From f18837cb9f0e5bde3ac8dcc61c77fc92a2f14174 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Fri, 17 Jan 2014 20:19:52 +0800 Subject: [PATCH] Unified inventory interaction actions --- .../resonantinduction/archaic/Archaic.java | 4 +- .../engineering/BlockEngineeringTable.java | 56 +++---------------- .../{blocks => firebox}/BlockFirebox.java | 38 +++++++------ .../{blocks => firebox}/TileFirebox.java | 17 ++++-- 4 files changed, 42 insertions(+), 73 deletions(-) rename src/main/java/resonantinduction/archaic/{blocks => firebox}/BlockFirebox.java (82%) rename src/main/java/resonantinduction/archaic/{blocks => firebox}/TileFirebox.java (90%) diff --git a/src/main/java/resonantinduction/archaic/Archaic.java b/src/main/java/resonantinduction/archaic/Archaic.java index aacc103b..338a3597 100644 --- a/src/main/java/resonantinduction/archaic/Archaic.java +++ b/src/main/java/resonantinduction/archaic/Archaic.java @@ -2,14 +2,14 @@ package resonantinduction.archaic; import net.minecraft.block.Block; import net.minecraft.item.Item; -import resonantinduction.archaic.blocks.BlockFirebox; import resonantinduction.archaic.blocks.BlockTurntable; -import resonantinduction.archaic.blocks.TileFirebox; import resonantinduction.archaic.crate.BlockCrate; import resonantinduction.archaic.crate.ItemBlockCrate; import resonantinduction.archaic.crate.TileCrate; import resonantinduction.archaic.engineering.BlockEngineeringTable; import resonantinduction.archaic.engineering.TileEngineeringTable; +import resonantinduction.archaic.firebox.BlockFirebox; +import resonantinduction.archaic.firebox.TileFirebox; import resonantinduction.archaic.imprint.BlockImprinter; import resonantinduction.archaic.imprint.ItemBlockImprint; import resonantinduction.archaic.imprint.TileImprinter; diff --git a/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java b/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java index 121bf779..f6751909 100644 --- a/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java +++ b/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java @@ -132,55 +132,7 @@ public class BlockEngineeringTable extends BlockRI if (check.distance(hitVector) < regionLength) { int slotID = j * 3 + k; - boolean didInsert = false; - ItemStack checkStack = tile.craftingMatrix[slotID]; - - if (current != null) - { - if (checkStack == null || checkStack.isItemEqual(current)) - { - if (ControlKeyModifer.isControlDown(player)) - { - if (checkStack == null) - { - tile.craftingMatrix[slotID] = current; - } - else - { - tile.craftingMatrix[slotID].stackSize += current.stackSize; - current.stackSize = 0; - } - - current = null; - } - else - { - if (checkStack == null) - { - tile.craftingMatrix[slotID] = current.splitStack(1); - } - else - { - tile.craftingMatrix[slotID].stackSize++; - current.stackSize--; - } - } - - if (current == null || current.stackSize <= 0) - { - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); - } - - didInsert = true; - } - } - - if (!didInsert && checkStack != null) - { - InventoryUtility.dropItemStack(world, new Vector3(player), checkStack, 0); - tile.craftingMatrix[slotID] = null; - } - + interactCurrentItem(tile, slotID, player); break matrix; } } @@ -252,6 +204,12 @@ public class BlockEngineeringTable extends BlockRI this.iconFront = par1IconRegister.registerIcon(this.getTextureName() + "_front"); } + @Override + public boolean isControlDown(EntityPlayer player) + { + return ControlKeyModifer.isControlDown(player); + } + @Override public TileEntity createNewTileEntity(World world) { diff --git a/src/main/java/resonantinduction/archaic/blocks/BlockFirebox.java b/src/main/java/resonantinduction/archaic/firebox/BlockFirebox.java similarity index 82% rename from src/main/java/resonantinduction/archaic/blocks/BlockFirebox.java rename to src/main/java/resonantinduction/archaic/firebox/BlockFirebox.java index d898bb5f..cd977cb1 100644 --- a/src/main/java/resonantinduction/archaic/blocks/BlockFirebox.java +++ b/src/main/java/resonantinduction/archaic/firebox/BlockFirebox.java @@ -1,7 +1,8 @@ -package resonantinduction.archaic.blocks; +package resonantinduction.archaic.firebox; import java.util.Random; +import codechicken.multipart.ControlKeyModifer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.player.EntityPlayer; @@ -37,29 +38,26 @@ public class BlockFirebox extends BlockRI } @Override - public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (tileEntity instanceof TileFirebox) { TileFirebox tile = (TileFirebox) tileEntity; + extractItem(tile, 0, player); + } + } - if (tile.getStackInSlot(0) == null) - { - if (tile.canBurn(entityPlayer.inventory.getCurrentItem())) - { - tile.setInventorySlotContents(0, entityPlayer.inventory.getCurrentItem()); - entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null); - return true; - } - } - else - { - InventoryUtility.dropItemStack(world, new Vector3(entityPlayer), tile.getStackInSlot(0)); - tile.setInventorySlotContents(0, null); - return true; - } + @Override + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileFirebox) + { + TileFirebox tile = (TileFirebox) tileEntity; + return interactCurrentItem(tile, 0, player); } return false; @@ -128,6 +126,12 @@ public class BlockFirebox extends BlockRI } } + @Override + public boolean isControlDown(EntityPlayer player) + { + return ControlKeyModifer.isControlDown(player); + } + @Override public TileEntity createNewTileEntity(World world) { diff --git a/src/main/java/resonantinduction/archaic/blocks/TileFirebox.java b/src/main/java/resonantinduction/archaic/firebox/TileFirebox.java similarity index 90% rename from src/main/java/resonantinduction/archaic/blocks/TileFirebox.java rename to src/main/java/resonantinduction/archaic/firebox/TileFirebox.java index 0a804f90..f9eedcd2 100644 --- a/src/main/java/resonantinduction/archaic/blocks/TileFirebox.java +++ b/src/main/java/resonantinduction/archaic/firebox/TileFirebox.java @@ -1,4 +1,4 @@ -package resonantinduction.archaic.blocks; +package resonantinduction.archaic.firebox; import java.util.ArrayList; @@ -51,13 +51,14 @@ public class TileFirebox extends TileExternalInventory implements IPacketSender, if (burnTime-- == 0) { + if (blockID == Block.fire.blockID) + { + worldObj.setBlock(xCoord, yCoord + 1, zCoord, 0); + } + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } - else if (blockID == Block.fire.blockID) - { - worldObj.setBlock(xCoord, yCoord + 1, zCoord, 0); - } if (canBurn(this.getStackInSlot(0))) { @@ -81,6 +82,12 @@ public class TileFirebox extends TileExternalInventory implements IPacketSender, return burnTime > 0; } + @Override + public boolean isItemValidForSlot(int i, ItemStack itemStack) + { + return i == 0 && canBurn(itemStack); + } + @Override public Packet getDescriptionPacket() {