diff --git a/src/main/java/slimeknights/harvesttweaks/ExtraHarvestLevelHandler.java b/src/main/java/slimeknights/harvesttweaks/ExtraHarvestLevelHandler.java index 965ce12..a46cd3a 100644 --- a/src/main/java/slimeknights/harvesttweaks/ExtraHarvestLevelHandler.java +++ b/src/main/java/slimeknights/harvesttweaks/ExtraHarvestLevelHandler.java @@ -1,47 +1,56 @@ -package iguanaman.iguanatweakstconstruct.override; +package slimeknights.harvesttweaks; import net.minecraft.block.Block; -import net.minecraft.init.Blocks; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; // This class handles harvest levels on the same block but where some metadata requires a tool, // and some metadatas don't public class ExtraHarvestLevelHandler { + @SubscribeEvent - public void breakSpeed(PlayerEvent.BreakSpeed event) - { - if(event.entityPlayer == null) + public void breakSpeed(PlayerEvent.BreakSpeed event) { + EntityPlayer player = event.getEntityPlayer(); + if(player == null) { return; + } - if(event.block == null || event.block == Blocks.air) + if(event.getState() == null || event.getState().getBlock().isAir(event.getState(), null, null)) { return; + } - Block block = event.block; - int hlvl = event.block.getHarvestLevel(event.metadata); + IBlockState state = event.getState(); + Block block = state.getBlock(); + int hlvl = block.getHarvestLevel(state); // does the block require a tool? - if(hlvl <= 0) + if(hlvl < 0) { // no, nothing to do return; + } - // tool requires a harvest level, but does the material require a tool? - if(!block.getMaterial().isToolNotRequired()) + // block requires a harvest level, but does the material require a tool? + if(!state.getMaterial().isToolNotRequired()) { // a tool is required, we don't have to do anything return; + } // The tool does NOT require a tool, but has a harvest level for a tool set // we now manually check if this requiremnet is fulfilled - String tool = event.block.getHarvestTool(event.metadata); - ItemStack itemStack = event.entityPlayer.getCurrentEquippedItem(); + String tool = block.getHarvestTool(state); + ItemStack itemStack = player.getHeldItemMainhand(); if(itemStack != null && itemStack.getItem() != null) { - if(itemStack.getItem().getHarvestLevel(itemStack, tool) >= hlvl) - // everything ok, correct tool + if(itemStack.getItem().getHarvestLevel(itemStack, tool, player, state) >= hlvl) + // everything ok, correct tool + { return; + } } // we require a tool, but no fitting tool is present. we prevent any breaking diff --git a/src/main/java/slimeknights/harvesttweaks/HarvestTweaks.java b/src/main/java/slimeknights/harvesttweaks/HarvestTweaks.java index ed4dc4e..47db493 100644 --- a/src/main/java/slimeknights/harvesttweaks/HarvestTweaks.java +++ b/src/main/java/slimeknights/harvesttweaks/HarvestTweaks.java @@ -76,6 +76,7 @@ public void postInit(FMLPostInitializationEvent event) { CONFIG.save(); MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(new ExtraHarvestLevelHandler()); if(event.getSide().isServer()) { MinecraftForge.EVENT_BUS.register(ConfigSyncHandler.INSTANCE); }