Add canWrench() checks to Block classes' onBlockActivated() methods

to fix the mmMPS powerFist always rotating Mekanism machines.
This commit is contained in:
Ben Spiers 2013-07-08 20:43:28 +01:00
parent c27f4d06bc
commit b2c32527c6
3 changed files with 186 additions and 162 deletions

View file

@ -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);
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, blockID);
return true;
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;
}
}
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;
}
}

View file

@ -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);
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, blockID);
return true;
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;
}
}
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;
}
}

View file

@ -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);
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, blockID);
return true;
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;
}
}
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;
}
}