Separated crate activation methods into correct method calls

This commit is contained in:
Robert S 2014-04-14 05:30:14 -04:00
parent 1212e27f54
commit a23962aef7

View file

@ -81,22 +81,53 @@ public class BlockCrate extends BlockTile
} }
} }
/** Placed the item the player is holding into the crate. */
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{ {
if (!world.isRemote) if (!world.isRemote && world.getBlockTileEntity(x, y, z) instanceof TileCrate)
{ {
if (world.getBlockTileEntity(x, y, z) instanceof TileCrate) TileCrate tile = (TileCrate) world.getBlockTileEntity(x, y, z);
tile.buildSampleStack();
ItemStack sampleStack = tile.getSampleStack();
int oreID = OreDictionary.getOreID(sampleStack);
if (ControlKeyModifer.isControlDown(player))
{
}
else if (oreID != -1)
{
ArrayList<ItemStack> ores = OreDictionary.getOres(oreID);
for (int oreIndex = 0; oreIndex < ores.size(); oreIndex++)
{
if (ores.get(oreIndex).isItemEqual(sampleStack))
{
int nextIndex = (oreIndex + 1) % ores.size();
ItemStack desiredStack = ores.get(nextIndex).copy();
desiredStack.stackSize = sampleStack.stackSize;
for (int index = 0; index < tile.getSizeInventory(); index++)
tile.setInventorySlotContents(index, null);
tile.addStackToStorage(desiredStack);
break;
}
}
}
}
return true;
}
@Override
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote && world.getBlockTileEntity(x, y, z) instanceof TileCrate)
{ {
TileCrate tile = (TileCrate) world.getBlockTileEntity(x, y, z); TileCrate tile = (TileCrate) world.getBlockTileEntity(x, y, z);
tile.buildSampleStack(); tile.buildSampleStack();
ItemStack sampleStack = tile.getSampleStack(); ItemStack sampleStack = tile.getSampleStack();
if (WrenchUtility.isWrench(player.getCurrentEquippedItem()))
{
if (player.isSneaking())
{
if (sampleStack != null && sampleStack.stackSize > 0) if (sampleStack != null && sampleStack.stackSize > 0)
{ {
ItemStack dropStack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z)); ItemStack dropStack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
@ -109,34 +140,17 @@ public class BlockCrate extends BlockTile
} }
world.setBlock(x, y, z, 0, 0, 3); world.setBlock(x, y, z, 0, 0, 3);
} }
return true;
}
int oreID = OreDictionary.getOreID(sampleStack);
if (oreID != -1)
{
ArrayList<ItemStack> ores = OreDictionary.getOres(oreID);
for (int i = 0; i < ores.size(); i++)
{
if (ores.get(i).isItemEqual(sampleStack))
{
int nextIndex = (i + 1) % ores.size();
ItemStack desiredStack = ores.get(nextIndex).copy();
desiredStack.stackSize = sampleStack.stackSize;
for (int index = 0; index < tile.getSizeInventory(); index++)
tile.setInventorySlotContents(index, null);
tile.addStackToStorage(desiredStack);
break;
}
}
} }
return true; return true;
} }
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote && world.getBlockTileEntity(x, y, z) instanceof TileCrate)
{
TileCrate tile = (TileCrate) world.getBlockTileEntity(x, y, z);
/** Make double clicking input all stacks. */ /** Make double clicking input all stacks. */
boolean allMode = (world.getWorldTime() - tile.prevClickTime < 10); boolean allMode = (world.getWorldTime() - tile.prevClickTime < 10);
@ -148,6 +162,7 @@ public class BlockCrate extends BlockTile
} }
else else
{ {
/* Creative mode way to fill crates to max in one click */
ItemStack current = player.inventory.getCurrentItem(); ItemStack current = player.inventory.getCurrentItem();
if (side == 1 && player.capabilities.isCreativeMode) if (side == 1 && player.capabilities.isCreativeMode)
{ {
@ -162,8 +177,6 @@ public class BlockCrate extends BlockTile
tryInsert(tile, player, allMode); tryInsert(tile, player, allMode);
} }
} }
}
return true; return true;
} }