From b2c32527c60e7ffed1bcd16df22bb9ba9e3d1ccc Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Mon, 8 Jul 2013 20:43:28 +0100 Subject: [PATCH] Add canWrench() checks to Block classes' onBlockActivated() methods to fix the mmMPS powerFist always rotating Mekanism machines. --- common/mekanism/common/BlockEnergyCube.java | 132 +++++++++++--------- common/mekanism/common/BlockGasTank.java | 108 ++++++++-------- common/mekanism/common/BlockMachine.java | 108 ++++++++-------- 3 files changed, 186 insertions(+), 162 deletions(-) diff --git a/common/mekanism/common/BlockEnergyCube.java b/common/mekanism/common/BlockEnergyCube.java index e310ef0b1..eea14b464 100644 --- a/common/mekanism/common/BlockEnergyCube.java +++ b/common/mekanism/common/BlockEnergyCube.java @@ -12,6 +12,7 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; @@ -167,75 +168,82 @@ public class BlockEnergyCube extends BlockContainer if(entityplayer.getCurrentEquippedItem() != null) { - if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolConfigurator) + Item tool = entityplayer.getCurrentEquippedItem().getItem(); + if(tool instanceof IToolConfigurator) { - ((IToolConfigurator)entityplayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) + if(((IToolConfigurator)tool).canWrench(entityplayer, x, y, z)) { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 1; - break; - case 1: - change = 0; - break; - case 0: - change = 3; - break; + ((IToolConfigurator)tool).wrenchUsed(entityplayer, x, y, z); + + int change = 0; + + switch(tileEntity.facing) + { + case 3: + change = 5; + break; + case 5: + change = 2; + break; + case 2: + change = 4; + break; + case 4: + change = 1; + break; + case 1: + change = 0; + break; + case 0: + change = 3; + break; + } + + tileEntity.setFacing((short)change); + world.notifyBlocksOfNeighborChange(x, y, z, blockID); + return true; } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; } - else if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolWrench && !entityplayer.getCurrentEquippedItem().getItemName().contains("omniwrench")) + else if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) { - if(entityplayer.isSneaking()) + if(((IToolWrench)tool).canWrench(entityplayer, x, y, z)) { - dismantleBlock(world, x, y, z, false); - return true; + if(entityplayer.isSneaking()) + { + dismantleBlock(world, x, y, z, false); + return true; + } + + ((IToolWrench)tool).wrenchUsed(entityplayer, x, y, z); + + int change = 0; + + switch(tileEntity.facing) + { + case 3: + change = 5; + break; + case 5: + change = 2; + break; + case 2: + change = 4; + break; + case 4: + change = 1; + break; + case 1: + change = 0; + break; + case 0: + change = 3; + break; + } + + tileEntity.setFacing((short)change); + world.notifyBlocksOfNeighborChange(x, y, z, blockID); + return true; } - - ((IToolWrench)entityplayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) - { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 1; - break; - case 1: - change = 0; - break; - case 0: - change = 3; - break; - } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; } } diff --git a/common/mekanism/common/BlockGasTank.java b/common/mekanism/common/BlockGasTank.java index 738f12eac..ef18ae1f3 100644 --- a/common/mekanism/common/BlockGasTank.java +++ b/common/mekanism/common/BlockGasTank.java @@ -11,6 +11,7 @@ import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -161,63 +162,70 @@ public class BlockGasTank extends BlockContainer if(entityplayer.getCurrentEquippedItem() != null) { - if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolConfigurator) + Item tool = entityplayer.getCurrentEquippedItem().getItem(); + if(tool instanceof IToolConfigurator) { - ((IToolConfigurator)entityplayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) + if(((IToolConfigurator)tool).canWrench(entityplayer, x, y, z)) { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 3; - break; + ((IToolConfigurator)tool).wrenchUsed(entityplayer, x, y, z); + + int change = 0; + + switch(tileEntity.facing) + { + case 3: + change = 5; + break; + case 5: + change = 2; + break; + case 2: + change = 4; + break; + case 4: + change = 3; + break; + } + + tileEntity.setFacing((short)change); + world.notifyBlocksOfNeighborChange(x, y, z, blockID); + return true; } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; } - else if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolWrench && !entityplayer.getCurrentEquippedItem().getItemName().contains("omniwrench")) + else if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) { - if(entityplayer.isSneaking()) + if(((IToolWrench)tool).canWrench(entityplayer, x, y, z)) { - dismantleBlock(world, x, y, z, false); - return true; + if(entityplayer.isSneaking()) + { + dismantleBlock(world, x, y, z, false); + return true; + } + + ((IToolWrench)tool).wrenchUsed(entityplayer, x, y, z); + + int change = 0; + + switch(tileEntity.facing) + { + case 3: + change = 5; + break; + case 5: + change = 2; + break; + case 2: + change = 4; + break; + case 4: + change = 3; + break; + } + + tileEntity.setFacing((short)change); + world.notifyBlocksOfNeighborChange(x, y, z, blockID); + return true; } - - ((IToolWrench)entityplayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) - { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 3; - break; - } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; } } diff --git a/common/mekanism/common/BlockMachine.java b/common/mekanism/common/BlockMachine.java index 732998788..1e42aa1d3 100644 --- a/common/mekanism/common/BlockMachine.java +++ b/common/mekanism/common/BlockMachine.java @@ -20,6 +20,7 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; @@ -505,63 +506,70 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds if(entityplayer.getCurrentEquippedItem() != null) { - if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolConfigurator) + Item tool = entityplayer.getCurrentEquippedItem().getItem(); + if(tool instanceof IToolConfigurator) { - ((IToolConfigurator)entityplayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) + if(((IToolConfigurator)tool).canWrench(entityplayer, x, y, z)) { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 3; - break; + ((IToolConfigurator)tool).wrenchUsed(entityplayer, x, y, z); + + int change = 0; + + switch(tileEntity.facing) + { + case 3: + change = 5; + break; + case 5: + change = 2; + break; + case 2: + change = 4; + break; + case 4: + change = 3; + break; + } + + tileEntity.setFacing((short)change); + world.notifyBlocksOfNeighborChange(x, y, z, blockID); + return true; } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; } - else if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolWrench && !entityplayer.getCurrentEquippedItem().getItemName().contains("omniwrench")) + else if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) { - if(entityplayer.isSneaking() && metadata != 13) + if(((IToolWrench)tool).canWrench(entityplayer, x, y, z)) { - dismantleBlock(world, x, y, z, false); - return true; + if(entityplayer.isSneaking() && metadata != 13) + { + dismantleBlock(world, x, y, z, false); + return true; + } + + ((IToolWrench)tool).wrenchUsed(entityplayer, x, y, z); + + int change = 0; + + switch(tileEntity.facing) + { + case 3: + change = 5; + break; + case 5: + change = 2; + break; + case 2: + change = 4; + break; + case 4: + change = 3; + break; + } + + tileEntity.setFacing((short)change); + world.notifyBlocksOfNeighborChange(x, y, z, blockID); + return true; } - - ((IToolWrench)entityplayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) - { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 3; - break; - } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; } }