mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 02:45:13 +00:00
Minor cleanups in tools
This commit is contained in:
6 files changed
+40
-40
No files matched your search
@@ -102,15 +102,15 @@ public final class BotaniaAPI {
|
||||
|
||||
|
||||
public static final ArmorMaterial manasteelArmorMaterial = EnumHelper.addArmorMaterial("MANASTEEL", "manasteel", 16,
|
||||
new int[] { 2, 6, 5, 2 }, 18, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0);
|
||||
new int[] { 2, 5, 6, 2 }, 18, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0);
|
||||
public static final ToolMaterial manasteelToolMaterial = EnumHelper.addToolMaterial("MANASTEEL", 3, 300, 6.2F, 2F, 20);
|
||||
|
||||
public static final ArmorMaterial elementiumArmorMaterial = EnumHelper.addArmorMaterial("B_ELEMENTIUM", "b_elementium", 18,
|
||||
new int[] { 2, 6, 5, 2 }, 18, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0);
|
||||
new int[] { 2, 5, 6, 2 }, 18, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0);
|
||||
public static final ToolMaterial elementiumToolMaterial = EnumHelper.addToolMaterial("B_ELEMENTIUM", 3, 720, 6.2F, 2F, 20);
|
||||
|
||||
public static final ArmorMaterial terrasteelArmorMaterial = EnumHelper.addArmorMaterial("TERRASTEEL", "terrasteel", 34,
|
||||
new int[] { 3, 8, 6, 3 }, 26, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 3F);
|
||||
new int[] { 3, 6, 8, 3 }, 26, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 3F);
|
||||
public static final ToolMaterial terrasteelToolMaterial = EnumHelper.addToolMaterial("TERRASTEEL", 4, 2300, 9F, 3F, 26);
|
||||
|
||||
public static final ArmorMaterial manaweaveArmorMaterial = EnumHelper.addArmorMaterial("MANAWEAVE", "manaweave", 5,
|
||||
|
||||
@@ -48,11 +48,11 @@ public class ItemSwapRing extends ItemBauble {
|
||||
IBlockState state = entity.world.getBlockState(pos.getBlockPos());
|
||||
|
||||
Material mat = state.getMaterial();
|
||||
if(ToolCommons.isRightMaterial(mat, ToolCommons.materialsPick))
|
||||
if(ToolCommons.materialsPick.contains(mat))
|
||||
typeToFind = ToolType.PICK;
|
||||
else if(ToolCommons.isRightMaterial(mat, ToolCommons.materialsShovel))
|
||||
else if(ToolCommons.materialsShovel.contains(mat))
|
||||
typeToFind = ToolType.SHOVEL;
|
||||
else if(ToolCommons.isRightMaterial(mat, ToolCommons.materialsAxe))
|
||||
else if(ToolCommons.materialsAxe.contains(mat))
|
||||
typeToFind = ToolType.AXE;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
@@ -35,11 +36,14 @@ import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.item.equipment.tool.elementium.ItemElementiumPick;
|
||||
import vazkii.botania.common.item.equipment.tool.terrasteel.ItemTerraPick;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class ToolCommons {
|
||||
|
||||
public static final Material[] materialsPick = new Material[]{ Material.ROCK, Material.IRON, Material.ICE, Material.GLASS, Material.PISTON, Material.ANVIL };
|
||||
public static final Material[] materialsShovel = new Material[]{ Material.GRASS, Material.GROUND, Material.SAND, Material.SNOW, Material.CRAFTED_SNOW, Material.CLAY };
|
||||
public static final Material[] materialsAxe = new Material[]{ Material.CORAL, Material.LEAVES, Material.PLANTS, Material.WOOD, Material.GOURD };
|
||||
public static final List<Material> materialsPick = Arrays.asList(Material.ROCK, Material.IRON, Material.ICE, Material.GLASS, Material.PISTON, Material.ANVIL);
|
||||
public static final List<Material> materialsShovel = Arrays.asList(Material.GRASS, Material.GROUND, Material.SAND, Material.SNOW, Material.CRAFTED_SNOW, Material.CLAY);
|
||||
public static final List<Material> materialsAxe = Arrays.asList(Material.CORAL, Material.LEAVES, Material.PLANTS, Material.WOOD, Material.GOURD);
|
||||
|
||||
public static void damageItem(ItemStack stack, int dmg, EntityLivingBase entity, int manaPerDamage) {
|
||||
int manaToRequest = dmg * manaPerDamage;
|
||||
@@ -49,32 +53,21 @@ public final class ToolCommons {
|
||||
stack.damageItem(dmg, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pos is the actual block coordinate, posStart and posEnd are deltas from pos
|
||||
*/
|
||||
public static void removeBlocksInIteration(EntityPlayer player, ItemStack stack, World world, BlockPos pos, BlockPos posStart, BlockPos posEnd, Block block, Material[] materialsListing, boolean silk, int fortune, boolean dispose) {
|
||||
float blockHardness = block == null ? 1F : block.getBlockHardness(world.getBlockState(pos), world, pos);
|
||||
public static void removeBlocksInIteration(EntityPlayer player, ItemStack stack, World world, BlockPos centerPos, Vec3i startDelta, Vec3i endDelta, Block block, List<Material> materialsListing, boolean silk, int fortune, boolean dispose) {
|
||||
float blockHardness = block == null ? 1F : block.getBlockHardness(world.getBlockState(centerPos), world, centerPos);
|
||||
|
||||
for (BlockPos iterPos : BlockPos.getAllInBox(pos.add(posStart), pos.add(posEnd))) {
|
||||
if (iterPos.equals(pos)) // skip original block space to avoid crash, vanilla code in the tool class will handle it
|
||||
for (BlockPos iterPos : BlockPos.getAllInBox(centerPos.add(startDelta), centerPos.add(endDelta))) {
|
||||
if (iterPos.equals(centerPos)) // skip original block space to avoid crash, vanilla code in the tool class will handle it
|
||||
continue;
|
||||
removeBlockWithDrops(player, stack, world, iterPos, pos, block, materialsListing, silk, fortune, blockHardness, dispose);
|
||||
removeBlockWithDrops(player, stack, world, iterPos, centerPos, block, materialsListing, silk, fortune, blockHardness, dispose);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRightMaterial(Material material, Material[] materialsListing) {
|
||||
for(Material mat : materialsListing)
|
||||
if(material == mat)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos, BlockPos bPos, Block block, Material[] materialsListing, boolean silk, int fortune, float blockHardness, boolean dispose) {
|
||||
public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos, BlockPos bPos, Block block, List<Material> materialsListing, boolean silk, int fortune, float blockHardness, boolean dispose) {
|
||||
removeBlockWithDrops(player, stack, world, pos, bPos, block, materialsListing, silk, fortune, blockHardness, dispose, true);
|
||||
}
|
||||
|
||||
public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos, BlockPos bPos, Block block, Material[] materialsListing, boolean silk, int fortune, float blockHardness, boolean dispose, boolean particles) {
|
||||
public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos, BlockPos bPos, Block block, List<Material> materialsListing, boolean silk, int fortune, float blockHardness, boolean dispose, boolean particles) {
|
||||
if(!world.isBlockLoaded(pos))
|
||||
return;
|
||||
|
||||
@@ -86,7 +79,7 @@ public final class ToolCommons {
|
||||
|
||||
Material mat = world.getBlockState(pos).getMaterial();
|
||||
if(!world.isRemote && blk != null && !blk.isAir(state, world, pos) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
|
||||
if(!blk.canHarvestBlock(player.world, pos, player) || !isRightMaterial(mat, materialsListing)) {
|
||||
if(!blk.canHarvestBlock(player.world, pos, player) || !materialsListing.contains(mat)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+9
-5
@@ -9,15 +9,19 @@ import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.common.item.equipment.tool.ToolCommons;
|
||||
import vazkii.botania.common.item.equipment.tool.manasteel.ItemManasteelShovel;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemElementiumShovel extends ItemManasteelShovel {
|
||||
|
||||
public static final Material[] materialsShovel = new Material[]{ Material.GRASS, Material.GROUND, Material.SAND, Material.SNOW, Material.CRAFTED_SNOW, Material.CLAY };
|
||||
public static final List<Material> materialsShovel = Arrays.asList(Material.GRASS, Material.GROUND, Material.SAND, Material.SNOW, Material.CRAFTED_SNOW, Material.CLAY);
|
||||
|
||||
public ItemElementiumShovel() {
|
||||
super(BotaniaAPI.elementiumToolMaterial, LibItemNames.ELEMENTIUM_SHOVEL);
|
||||
@@ -27,19 +31,19 @@ public class ItemElementiumShovel extends ItemManasteelShovel {
|
||||
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) {
|
||||
World world = player.world;
|
||||
Material mat = world.getBlockState(pos).getMaterial();
|
||||
if (!ToolCommons.isRightMaterial(mat, materialsShovel))
|
||||
if (!ToolCommons.materialsShovel.contains(mat))
|
||||
return false;
|
||||
|
||||
RayTraceResult block = ToolCommons.raytraceFromEntity(world, player, true, 10);
|
||||
if (block == null)
|
||||
return false;
|
||||
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
|
||||
boolean silk = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0;
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
|
||||
boolean silk = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
|
||||
|
||||
Block blk = world.getBlockState(pos).getBlock();
|
||||
if(blk instanceof BlockFalling)
|
||||
ToolCommons.removeBlocksInIteration(player, stack, world, pos, new BlockPos(0, -12, 0), new BlockPos(1, 12, 1), blk, materialsShovel, silk, fortune, false);
|
||||
ToolCommons.removeBlocksInIteration(player, stack, world, pos, new Vec3i(0, -12, 0), new Vec3i(1, 12, 1), blk, materialsShovel, silk, fortune, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
+8
-6
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.equipment.tool.terrasteel;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -33,6 +34,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
@@ -65,7 +67,7 @@ public class ItemTerraPick extends ItemManasteelPick implements IManaItem, ISequ
|
||||
private static final int MAX_MANA = Integer.MAX_VALUE;
|
||||
private static final int MANA_PER_DAMAGE = 100;
|
||||
|
||||
private static final Material[] MATERIALS = new Material[] { Material.ROCK, Material.IRON, Material.ICE, Material.GLASS, Material.PISTON, Material.ANVIL, Material.GRASS, Material.GROUND, Material.SAND, Material.SNOW, Material.CRAFTED_SNOW, Material.CLAY };
|
||||
private static final List<Material> MATERIALS = Arrays.asList(Material.ROCK, Material.IRON, Material.ICE, Material.GLASS, Material.PISTON, Material.ANVIL, Material.GRASS, Material.GROUND, Material.SAND, Material.SNOW, Material.CRAFTED_SNOW, Material.CLAY);
|
||||
|
||||
public static final int[] LEVELS = new int[] {
|
||||
0, 10000, 1000000, 10000000, 100000000, 1000000000
|
||||
@@ -164,14 +166,14 @@ public class ItemTerraPick extends ItemManasteelPick implements IManaItem, ISequ
|
||||
|
||||
World world = player.world;
|
||||
Material mat = world.getBlockState(pos).getMaterial();
|
||||
if(!ToolCommons.isRightMaterial(mat, MATERIALS))
|
||||
if(!MATERIALS.contains(mat))
|
||||
return;
|
||||
|
||||
if(world.isAirBlock(pos))
|
||||
return;
|
||||
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
|
||||
boolean silk = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0;
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
|
||||
boolean silk = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
|
||||
boolean thor = ItemThorRing.getThorRing(player) != null;
|
||||
boolean doX = thor || side.getFrontOffsetX() == 0;
|
||||
boolean doY = thor || side.getFrontOffsetY() == 0;
|
||||
@@ -188,8 +190,8 @@ public class ItemTerraPick extends ItemManasteelPick implements IManaItem, ISequ
|
||||
if(range == 0 && level != 1)
|
||||
return;
|
||||
|
||||
BlockPos beginDiff = new BlockPos(doX ? -range : 0, doY ? -1 : 0, doZ ? -range : 0);
|
||||
BlockPos endDiff = new BlockPos(doX ? range : 0, doY ? rangeY * 2 - 1 : 0, doZ ? range : 0);
|
||||
Vec3i beginDiff = new Vec3i(doX ? -range : 0, doY ? -1 : 0, doZ ? -range : 0);
|
||||
Vec3i endDiff = new Vec3i(doX ? range : 0, doY ? rangeY * 2 - 1 : 0, doZ ? range : 0);
|
||||
|
||||
ToolCommons.removeBlocksInIteration(player, stack, world, pos, beginDiff, endDiff, null, MATERIALS, silk, fortune, isTipped(stack));
|
||||
if(origLevel == 5)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package vazkii.botania.common.item.relic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -150,7 +151,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IWireframeCoordinat
|
||||
for (BlockPos coords : cursors) {
|
||||
IBlockState state = world.getBlockState(coords);
|
||||
breaker.breakOtherBlock(player, stack, coords, coords, side);
|
||||
ToolCommons.removeBlockWithDrops(player, stack, player.world, coords, pos, state.getBlock(), new Material[]{state.getMaterial()}, silk, fortune, state.getBlockHardness(world, coords), dispose);
|
||||
ToolCommons.removeBlockWithDrops(player, stack, player.world, coords, pos, state.getBlock(), Collections.singletonList(state.getMaterial()), silk, fortune, state.getBlockHardness(world, coords), dispose);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user