diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java b/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java index 5ae27ae85..6f623647d 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java @@ -1,14 +1,12 @@ package ellpeck.actuallyadditions.items; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ellpeck.actuallyadditions.ActuallyAdditions; import ellpeck.actuallyadditions.config.values.ConfigFloatValues; import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.inventory.GuiHandler; -import ellpeck.actuallyadditions.items.tools.ItemAllToolAA; import ellpeck.actuallyadditions.util.INameableItem; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.WorldUtil; @@ -22,6 +20,7 @@ import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -38,12 +37,6 @@ import java.util.Set; @SuppressWarnings("unchecked") public class ItemDrill extends ItemEnergy implements INameableItem{ - private static final Set allSet = Sets.newHashSet(); - static{ - allSet.addAll(ItemAllToolAA.pickSet); - allSet.addAll(ItemAllToolAA.shovelSet); - } - public ItemDrill(){ super(500000, 5000, 3); } @@ -211,6 +204,8 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ zRange = radius; } + float mainHardness = world.getBlock(x, y, z).getBlockHardness(world, x, y, z); + //Break Middle Block first int use = this.getEnergyUsePerBlock(stack); if(this.getEnergyStored(stack) >= use){ @@ -225,7 +220,10 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ for(int zPos = z-zRange; zPos <= z+zRange; zPos++){ if(!(x == xPos && y == yPos && z == zPos)){ if(this.getEnergyStored(stack) >= use){ - this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use); + //Only break Blocks that are (about) as hard or softer + if(world.getBlock(xPos, yPos, zPos).getBlockHardness(world, xPos, yPos, zPos) <= mainHardness+5.0F){ + this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use); + } } else return; } @@ -246,10 +244,12 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ block.onBlockHarvested(world, xPos, yPos, zPos, meta, player); if(block.removedByPlayer(world, player, xPos, yPos, zPos, true)){ block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta); - block.harvestBlock(world, player, xPos, yPos, zPos, meta); - if(!EnchantmentHelper.getSilkTouchModifier(player)){ - block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player))); + if(!player.capabilities.isCreativeMode){ + block.harvestBlock(world, player, xPos, yPos, zPos, meta); + if(!EnchantmentHelper.getSilkTouchModifier(player)){ + block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player))); + } } } @@ -300,13 +300,6 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ else return true; } - @Override - public float func_150893_a(ItemStack stack, Block block){ - if(this.getEnergyStored(stack) < this.getEnergyUsePerBlock(stack)) return 0.0F; - if(block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil || block.getMaterial() == Material.rock || allSet.contains(block)) return this.getEfficiencyFromUpgrade(stack); - else return super.func_150893_a(stack, block); - } - @Override public boolean hitEntity(ItemStack stack, EntityLivingBase entity1, EntityLivingBase entity2){ int use = this.getEnergyUsePerBlock(stack); @@ -316,9 +309,14 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ return true; } + @Override + public float getDigSpeed(ItemStack stack, Block block, int meta){ + return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) ? (this.getToolClasses(stack).contains(block.getHarvestTool(meta)) ? this.getEfficiencyFromUpgrade(stack) : 1.0F) : 0.0F; + } + @Override public boolean canHarvestBlock(Block block, ItemStack stack){ - return this.func_150893_a(stack, block) > super.func_150893_a(stack, block); + return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) && (block.getMaterial().isToolNotRequired() || (block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? ToolMaterial.EMERALD.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : ToolMaterial.EMERALD.getHarvestLevel() >= 2) : ToolMaterial.EMERALD.getHarvestLevel() >= 1) : ToolMaterial.EMERALD.getHarvestLevel() >= 1) : ToolMaterial.EMERALD.getHarvestLevel() >= 2) : ToolMaterial.EMERALD.getHarvestLevel() >= 2) : ToolMaterial.EMERALD.getHarvestLevel() >= 2)))); } @Override @@ -336,17 +334,12 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ @Override public Set getToolClasses(ItemStack stack){ - HashSet hashSet = new HashSet(); + HashSet hashSet = new HashSet<>(); hashSet.add("pickaxe"); hashSet.add("shovel"); return hashSet; } - @Override - public float getDigSpeed(ItemStack stack, Block block, int meta){ - return this.func_150893_a(stack, block); - } - @Override public Multimap getAttributeModifiers(ItemStack stack){ Multimap map = super.getAttributeModifiers(stack); diff --git a/src/main/java/ellpeck/actuallyadditions/items/tools/ItemAllToolAA.java b/src/main/java/ellpeck/actuallyadditions/items/tools/ItemAllToolAA.java index aa9a46ca0..293911f78 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/tools/ItemAllToolAA.java +++ b/src/main/java/ellpeck/actuallyadditions/items/tools/ItemAllToolAA.java @@ -30,23 +30,12 @@ import java.util.Set; @SuppressWarnings("unchecked") public class ItemAllToolAA extends ItemTool implements INameableItem{ - public static final Set axeSet = Sets.newHashSet(Blocks.planks, Blocks.bookshelf, Blocks.log, Blocks.log2, Blocks.chest, Blocks.pumpkin, Blocks.lit_pumpkin); - public static final Set pickSet = Sets.newHashSet(Blocks.cobblestone, Blocks.double_stone_slab, Blocks.stone_slab, Blocks.stone, Blocks.sandstone, Blocks.mossy_cobblestone, Blocks.iron_ore, Blocks.iron_block, Blocks.coal_ore, Blocks.gold_block, Blocks.gold_ore, Blocks.diamond_ore, Blocks.diamond_block, Blocks.ice, Blocks.netherrack, Blocks.lapis_ore, Blocks.lapis_block, Blocks.redstone_ore, Blocks.lit_redstone_ore, Blocks.rail, Blocks.detector_rail, Blocks.golden_rail, Blocks.activator_rail); - public static final Set shovelSet = Sets.newHashSet(Blocks.grass, Blocks.dirt, Blocks.sand, Blocks.gravel, Blocks.snow_layer, Blocks.snow, Blocks.clay, Blocks.farmland, Blocks.soul_sand, Blocks.mycelium); - - private static final Set allSet = Sets.newHashSet(); - static{ - allSet.addAll(axeSet); - allSet.addAll(pickSet); - allSet.addAll(shovelSet); - } - private String name; private EnumRarity rarity; private String repairItem; public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity){ - super(4.0F, toolMat, allSet); + super(4.0F, toolMat, Sets.newHashSet()); this.repairItem = repairItem; this.name = unlocalizedName; @@ -56,13 +45,13 @@ public class ItemAllToolAA extends ItemTool implements INameableItem{ } @Override - public float func_150893_a(ItemStack stack, Block block){ - return block.getMaterial() != Material.iron && block.getMaterial() != Material.anvil && block.getMaterial() != Material.rock && block.getMaterial() != Material.wood && block.getMaterial() != Material.plants && block.getMaterial() != Material.vine ? super.func_150893_a(stack, block) : this.efficiencyOnProperMaterial; + public float getDigSpeed(ItemStack stack, Block block, int meta){ + return this.getToolClasses(stack).contains(block.getHarvestTool(meta)) ? this.efficiencyOnProperMaterial : 1.0F; } @Override - public boolean func_150897_b(Block block){ - return block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2)); + public boolean canHarvestBlock(Block block, ItemStack stack){ + return block.getMaterial().isToolNotRequired() || (block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2))); } @Override @@ -134,7 +123,7 @@ public class ItemAllToolAA extends ItemTool implements INameableItem{ @Override public Set getToolClasses(ItemStack stack){ - HashSet hashSet = new HashSet(); + HashSet hashSet = new HashSet<>(); hashSet.add("pickaxe"); hashSet.add("axe"); hashSet.add("shovel");