package simcraft.machines.workshop; import simcraft.core.SimCraft; import simcraft.core.recipes.RecipesIronBench; import simcraft.machines.InventorySubCraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ContainerIronWorkBench extends Container { public TileEntityIronWorkBench tile; /** The crafting matrix inventory (3x3). */ public InventorySubCraft craftMatrix; public IInventory craftResult = new InventoryCraftResult(); private int HammerSlot1Time = 0; private int ItemHammerSlot1Time = 0; /** Adv Bench **/ public IInventory lowerChestInventory; static InventoryPlayer playerinv; private int numRows; private World worldObj; public ContainerIronWorkBench(IInventory par1IInventory, IInventory par2IInventory, TileEntityIronWorkBench var2) { this.craftMatrix = new InventorySubCraft(this, var2); this.playerinv = (InventoryPlayer) par1IInventory; this.tile = var2; this.addSlotToContainer(new SlotCrafting(playerinv.player, this.craftMatrix, this.craftResult, 0, 124, 35)); this.lowerChestInventory = par2IInventory; this.numRows = par2IInventory.getSizeInventory() / 9; par2IInventory.openChest(); int var3 = (this.numRows - 4) * 18; int var4; int var5; /** Crafting Grid **/ for (var4 = 0; var4 < 3; ++var4) { for (var5 = 0; var5 < 3; ++var5) { this.addSlotToContainer(new Slot(this.craftMatrix, var5 + var4 * 3, 30 + var5 * 18, 17 + var4 * 18)); } } /** Players Inventory **/ for (var4 = 0; var4 < 3; ++var4) { for (var5 = 0; var5 < 9; ++var5) { this.addSlotToContainer(new Slot(playerinv, var5 + var4 * 9 + 9, 8 + var5 * 18, 84 + var4 * 18)); } } /** Players HotBar **/ for (var4 = 0; var4 < 9; ++var4) { this.addSlotToContainer(new Slot(playerinv, var4, 8 + var4 * 18, 142)); } /** Adv Bench + Container **/ if (this.numRows > 3) { this.addSlotToContainer(new Slot(par2IInventory, 10, 189, 35)); this.addSlotToContainer(new Slot(par2IInventory, 11, 189, 84)); this.addSlotToContainer(new Slot(par2IInventory, 12, 207, 84)); this.addSlotToContainer(new Slot(par2IInventory, 13, 225, 84)); this.addSlotToContainer(new Slot(par2IInventory, 14, 189, 102)); this.addSlotToContainer(new Slot(par2IInventory, 15, 207, 102)); this.addSlotToContainer(new Slot(par2IInventory, 16, 225, 102)); this.addSlotToContainer(new Slot(par2IInventory, 17, 189, 120)); this.addSlotToContainer(new Slot(par2IInventory, 18, 207, 120)); this.addSlotToContainer(new Slot(par2IInventory, 19, 225, 120)); this.addSlotToContainer(new Slot(par2IInventory, 20, 189, 138)); this.addSlotToContainer(new Slot(par2IInventory, 21, 207, 138)); this.addSlotToContainer(new Slot(par2IInventory, 22, 225, 138)); } this.onCraftMatrixChanged(this.craftMatrix); } public void addCraftingToCrafters(ICrafting var1) { super.addCraftingToCrafters(var1); var1.sendProgressBarUpdate(this, 0, this.tile.HammerSlot1Time); var1.sendProgressBarUpdate(this, 1, this.tile.currentItemHammerSlot1Time); } public void detectAndSendChanges() { super.detectAndSendChanges(); for (int var1 = 0; var1 < this.crafters.size(); ++var1) { ICrafting var2 = (ICrafting)this.crafters.get(var1); if (this.HammerSlot1Time != this.tile.HammerSlot1Time) { var2.sendProgressBarUpdate(this, 0, this.tile.HammerSlot1Time); } if (this.ItemHammerSlot1Time != this.tile.currentItemHammerSlot1Time) { var2.sendProgressBarUpdate(this, 1, this.tile.currentItemHammerSlot1Time); } } this.HammerSlot1Time = this.tile.HammerSlot1Time; this.ItemHammerSlot1Time = this.tile.currentItemHammerSlot1Time; } public void updateProgressBar(int var1, int var2) { if (var1 == 0) { this.tile.HammerSlot1Time = var2; } if (var1 == 1) { this.tile.currentItemHammerSlot1Time = var2; } } /** * Callback for when the crafting matrix is changed. */ public void onCraftMatrixChanged(IInventory par1IInventory) { this.craftResult.setInventorySlotContents(0, RecipesIronBench.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } public boolean canInteractWith(EntityPlayer par1EntityPlayer) { return this.lowerChestInventory.isUseableByPlayer(par1EntityPlayer); } /** * Called to transfer a stack from one inventory to the other eg. when shift clicking. */ public final ItemStack transferStackInSlot(EntityPlayer entityplayer, int var1) { ItemStack var2 = null; Slot var3 = (Slot)SimCraft.globalFunctions.getContainerSlots(this).get(var1); if (var3 != null && var3.getHasStack()) { ItemStack var4 = var3.getStack(); var2 = var4.copy(); if (var1 < this.guiInventorySize()) { this.transferToSlots(var4, this.guiInventorySize(), this.inventorySlots.size(), false); } else if (var1 >= this.guiInventorySize() && var1 < this.inventorySlots.size() - 9) { int var5 = this.getInput(); if (var5 != -1 && var5 < this.guiInventorySize()) { this.transferToSlots(var4, var5, var5 + 1, false); } else { this.transferToSlots(var4, 0, this.guiInventorySize(), false); } } else if (var1 >= this.guiInventorySize() && var1 >= this.inventorySlots.size() - 9 && var1 < this.inventorySlots.size()) { this.transferToSlots(var4, this.guiInventorySize(), this.inventorySlots.size() - 9, false); } if (var4.stackSize == 0) { var3.putStack((ItemStack)null); } else { var3.onSlotChanged(); } if (var4.stackSize == var2.stackSize) { return null; } var3.onPickupFromSlot(entityplayer, var4); } return var2; } public void transferToSlots(ItemStack var1, int var2, int var3, boolean var4) { this.mergeItemStack(var1, var2, var3, var4); } public int guiInventorySize() { return 27; } public int getInput() { return 0; } /** * Callback for when the crafting gui is closed. */ public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) { super.onCraftGuiClosed(par1EntityPlayer); this.lowerChestInventory.closeChest(); this.tile.HammerSlot1Time = 0; } }