From 287d85a2702cbc372f791a6e4438fd18decc37c1 Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Sun, 19 Apr 2015 19:52:48 -0400 Subject: [PATCH] #2331 Yeta Wrench not working with IDismantleable blocks --- .../enderio/item/ItemYetaWrench.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/crazypants/enderio/item/ItemYetaWrench.java b/src/main/java/crazypants/enderio/item/ItemYetaWrench.java index 2b539841..1756f843 100644 --- a/src/main/java/crazypants/enderio/item/ItemYetaWrench.java +++ b/src/main/java/crazypants/enderio/item/ItemYetaWrench.java @@ -11,10 +11,15 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import org.lwjgl.input.Keyboard; +import cofh.api.block.IDismantleable; +import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -62,22 +67,31 @@ public class ItemYetaWrench extends Item implements ITool, IConduitControl, IAdv @Override public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - if(world.isRemote) { - return false; - } Block block = world.getBlock(x, y, z); - if(block instanceof IRotatableFacade && !player.isSneaking() && - (block != EnderIO.blockConduitBundle || ConduitDisplayMode.getDisplayMode(stack) == ConduitDisplayMode.NONE)) { - if(((IRotatableFacade)block).tryRotateFacade(world, x, y, z, ForgeDirection.getOrientation(side))) { - player.swingItem(); - return true; + boolean ret = false; + if(block != null) { + PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, x, y, z, side, world); + if(MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY || e.useItem == Result.DENY) { + return false; + } + if(player.isSneaking() && block instanceof IDismantleable && ((IDismantleable) block).canDismantle(player, world, x, y, z)) { + if(!world.isRemote) { + ((IDismantleable) block).dismantleBlock(player, world, x, y, z, false); + } + ret = true; + } else if(block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) { + ret = true; + } else if(block instanceof IRotatableFacade && !player.isSneaking() + && (block != EnderIO.blockConduitBundle || ConduitDisplayMode.getDisplayMode(stack) == ConduitDisplayMode.NONE)) { + if(((IRotatableFacade) block).tryRotateFacade(world, x, y, z, ForgeDirection.getOrientation(side))) { + ret = true; + } } } - if(block != null && !player.isSneaking() && block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) { + if(ret) { player.swingItem(); - return true; } - return false; + return ret && !world.isRemote; } @Override