From d1315fb585bc05fab11be3673db4f416a0ba58fb Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 12 Jan 2014 01:03:30 +0800 Subject: [PATCH] Finsihed engineering table --- .../engineering/BlockEngineeringTable.java | 52 ++++++++++++++----- .../engineering/RenderEngineeringTable.java | 2 + .../engineering/TileEngineeringTable.java | 20 ++++--- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java b/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java index a07cee40..3d8976d9 100644 --- a/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java +++ b/src/main/java/resonantinduction/archaic/engineering/BlockEngineeringTable.java @@ -1,5 +1,6 @@ package resonantinduction.archaic.engineering; +import codechicken.multipart.ControlKeyModifer; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.item.EntityItem; @@ -35,15 +36,16 @@ public class BlockEngineeringTable extends BlockRI @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitSide, float hitX, float hitY, float hitZ) { - if (hitSide == 1) - { - if (!world.isRemote) - { - TileEntity te = world.getBlockTileEntity(x, y, z); + TileEntity te = world.getBlockTileEntity(x, y, z); - if (te instanceof TileEngineeringTable) + if (te instanceof TileEngineeringTable) + { + TileEngineeringTable tile = (TileEngineeringTable) te; + + if (hitSide == 1) + { + if (!world.isRemote) { - TileEngineeringTable tile = (TileEngineeringTable) te; ItemStack current = player.inventory.getCurrentItem(); @@ -64,7 +66,7 @@ public class BlockEngineeringTable extends BlockRI { int slotID = j * 3 + k; ItemStack checkStack = tile.craftingMatrix[slotID]; - System.out.println(slotID); + if (checkStack != null) { EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, checkStack); @@ -74,8 +76,20 @@ public class BlockEngineeringTable extends BlockRI } else if (current != null) { - tile.craftingMatrix[slotID] = current; - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + if (ControlKeyModifer.isControlDown(player)) + { + tile.craftingMatrix[slotID] = current.splitStack(1); + } + else + { + tile.craftingMatrix[slotID] = current; + current = null; + } + + if (current == null || current.stackSize <= 0) + { + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + } } break matrix; @@ -84,10 +98,24 @@ public class BlockEngineeringTable extends BlockRI } tile.onInventoryChanged(); + + } + + return true; + } + else if (hitSide != 0) + { + ItemStack output = tile.getStackInSlot(9); + + if (output != null) + { + EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, output); + entityItem.delayBeforeCanPickup = 0; + world.spawnEntityInWorld(entityItem); + tile.onPickUpFromSlot(player, 9, output); + tile.setInventorySlotContents(9, null); } } - - return true; } return false; diff --git a/src/main/java/resonantinduction/archaic/engineering/RenderEngineeringTable.java b/src/main/java/resonantinduction/archaic/engineering/RenderEngineeringTable.java index 99bbcb4e..1cae2159 100644 --- a/src/main/java/resonantinduction/archaic/engineering/RenderEngineeringTable.java +++ b/src/main/java/resonantinduction/archaic/engineering/RenderEngineeringTable.java @@ -58,6 +58,8 @@ public class RenderEngineeringTable extends TileEntitySpecialRenderer GL11.glPushMatrix(); GL11.glTranslated(x + (double) (i / 3) / 3d + (0.5 / 3d), y + 1.1, z + (double) (i % 3) / 3d + (0.5 / 3d)); GL11.glScalef(0.7f, 0.7f, 0.7f); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); + this.renderItem(tileEntity.worldObj, ForgeDirection.UP, tile.craftingMatrix[i], new Vector3(), 0, 0); GL11.glPopMatrix(); } diff --git a/src/main/java/resonantinduction/archaic/engineering/TileEngineeringTable.java b/src/main/java/resonantinduction/archaic/engineering/TileEngineeringTable.java index 3ddd09e0..1e0aca04 100644 --- a/src/main/java/resonantinduction/archaic/engineering/TileEngineeringTable.java +++ b/src/main/java/resonantinduction/archaic/engineering/TileEngineeringTable.java @@ -13,6 +13,7 @@ import net.minecraft.network.packet.Packet; import resonantinduction.api.IArmbot; import resonantinduction.api.IArmbotUseable; import resonantinduction.core.ResonantInduction; +import resonantinduction.core.prefab.ContainerFake; import resonantinduction.electrical.encoder.coding.args.ArgumentData; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.PacketHandler; @@ -245,17 +246,19 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive boolean didCraft = false; /** Simulate an Inventory Crafting Instance */ - InventoryCrafting inventoryCrafting = this.getCraftingMatrix(); + InventoryCrafting inventoryCrafting = new InventoryCrafting(new ContainerFake(this), 3, 3); - if (inventoryCrafting != null) + for (int i = 0; i < this.craftingMatrix.length; i++) { - ItemStack matrixOutput = CraftingManager.getInstance().findMatchingRecipe(inventoryCrafting, this.worldObj); + inventoryCrafting.setInventorySlotContents(i, this.craftingMatrix[i]); + } - if (matrixOutput != null && this.getCraftingManager().getIdealRecipe(matrixOutput) != null) - { - this.output[craftingOutputSlot] = matrixOutput; - didCraft = true; - } + ItemStack matrixOutput = CraftingManager.getInstance().findMatchingRecipe(inventoryCrafting, this.worldObj); + + if (matrixOutput != null && this.getCraftingManager().getIdealRecipe(matrixOutput) != null) + { + this.output[craftingOutputSlot] = matrixOutput; + didCraft = true; } PacketDispatcher.sendPacketToAllPlayers(this.getDescriptionPacket()); @@ -404,4 +407,5 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive { return craftingSlots; } + }