Guest User

ContainerIronWorkBench

a guest
Jul 4th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.71 KB | None | 0 0
  1. package simcraft.machines.workshop;
  2.  
  3. import simcraft.core.SimCraft;
  4. import simcraft.core.recipes.RecipesIronBench;
  5. import simcraft.machines.InventorySubCraft;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.entity.player.InventoryPlayer;
  8. import net.minecraft.inventory.Container;
  9. import net.minecraft.inventory.ICrafting;
  10. import net.minecraft.inventory.IInventory;
  11. import net.minecraft.inventory.InventoryCraftResult;
  12. import net.minecraft.inventory.Slot;
  13. import net.minecraft.inventory.SlotCrafting;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.world.World;
  16.  
  17.  
  18. public class ContainerIronWorkBench extends Container
  19. {
  20. public TileEntityIronWorkBench tile;
  21. /** The crafting matrix inventory (3x3). */
  22. public InventorySubCraft craftMatrix;
  23. public IInventory craftResult = new InventoryCraftResult();
  24. private int HammerSlot1Time = 0;
  25. private int ItemHammerSlot1Time = 0;
  26. /** Adv Bench **/
  27. public IInventory lowerChestInventory;
  28. static InventoryPlayer playerinv;
  29. private int numRows;
  30. private World worldObj;
  31.  
  32.  
  33. public ContainerIronWorkBench(IInventory par1IInventory, IInventory par2IInventory, TileEntityIronWorkBench var2)
  34. {
  35. this.craftMatrix = new InventorySubCraft(this, var2);
  36. this.playerinv = (InventoryPlayer) par1IInventory;
  37. this.tile = var2;
  38. this.addSlotToContainer(new SlotCrafting(playerinv.player, this.craftMatrix, this.craftResult, 0, 124, 35));
  39. this.lowerChestInventory = par2IInventory;
  40. this.numRows = par2IInventory.getSizeInventory() / 9;
  41. par2IInventory.openChest();
  42. int var3 = (this.numRows - 4) * 18;
  43. int var4;
  44. int var5;
  45.  
  46. /** Crafting Grid **/
  47. for (var4 = 0; var4 < 3; ++var4)
  48. {
  49. for (var5 = 0; var5 < 3; ++var5)
  50. {
  51. this.addSlotToContainer(new Slot(this.craftMatrix, var5 + var4 * 3, 30 + var5 * 18, 17 + var4 * 18));
  52. }
  53. }
  54.  
  55.  
  56. /** Players Inventory **/
  57. for (var4 = 0; var4 < 3; ++var4)
  58. {
  59. for (var5 = 0; var5 < 9; ++var5)
  60. {
  61. this.addSlotToContainer(new Slot(playerinv, var5 + var4 * 9 + 9, 8 + var5 * 18, 84 + var4 * 18));
  62. }
  63. }
  64. /** Players HotBar **/
  65. for (var4 = 0; var4 < 9; ++var4)
  66. {
  67. this.addSlotToContainer(new Slot(playerinv, var4, 8 + var4 * 18, 142));
  68. }
  69.  
  70. /** Adv Bench + Container **/
  71. if (this.numRows > 3)
  72. {
  73. this.addSlotToContainer(new Slot(par2IInventory, 10, 189, 35));
  74. this.addSlotToContainer(new Slot(par2IInventory, 11, 189, 84));
  75. this.addSlotToContainer(new Slot(par2IInventory, 12, 207, 84));
  76. this.addSlotToContainer(new Slot(par2IInventory, 13, 225, 84));
  77. this.addSlotToContainer(new Slot(par2IInventory, 14, 189, 102));
  78. this.addSlotToContainer(new Slot(par2IInventory, 15, 207, 102));
  79. this.addSlotToContainer(new Slot(par2IInventory, 16, 225, 102));
  80. this.addSlotToContainer(new Slot(par2IInventory, 17, 189, 120));
  81. this.addSlotToContainer(new Slot(par2IInventory, 18, 207, 120));
  82. this.addSlotToContainer(new Slot(par2IInventory, 19, 225, 120));
  83. this.addSlotToContainer(new Slot(par2IInventory, 20, 189, 138));
  84. this.addSlotToContainer(new Slot(par2IInventory, 21, 207, 138));
  85. this.addSlotToContainer(new Slot(par2IInventory, 22, 225, 138));
  86. }
  87.  
  88. this.onCraftMatrixChanged(this.craftMatrix);
  89. }
  90.  
  91. public void addCraftingToCrafters(ICrafting var1)
  92. {
  93. super.addCraftingToCrafters(var1);
  94. var1.sendProgressBarUpdate(this, 0, this.tile.HammerSlot1Time);
  95. var1.sendProgressBarUpdate(this, 1, this.tile.currentItemHammerSlot1Time);
  96. }
  97.  
  98. public void detectAndSendChanges()
  99. {
  100. super.detectAndSendChanges();
  101.  
  102. for (int var1 = 0; var1 < this.crafters.size(); ++var1)
  103. {
  104. ICrafting var2 = (ICrafting)this.crafters.get(var1);
  105.  
  106. if (this.HammerSlot1Time != this.tile.HammerSlot1Time)
  107. {
  108. var2.sendProgressBarUpdate(this, 0, this.tile.HammerSlot1Time);
  109. }
  110.  
  111. if (this.ItemHammerSlot1Time != this.tile.currentItemHammerSlot1Time)
  112. {
  113. var2.sendProgressBarUpdate(this, 1, this.tile.currentItemHammerSlot1Time);
  114. }
  115. }
  116.  
  117. this.HammerSlot1Time = this.tile.HammerSlot1Time;
  118. this.ItemHammerSlot1Time = this.tile.currentItemHammerSlot1Time;
  119. }
  120.  
  121. public void updateProgressBar(int var1, int var2)
  122. {
  123. if (var1 == 0)
  124. {
  125. this.tile.HammerSlot1Time = var2;
  126. }
  127.  
  128. if (var1 == 1)
  129. {
  130. this.tile.currentItemHammerSlot1Time = var2;
  131. }
  132.  
  133.  
  134.  
  135. }
  136.  
  137. /**
  138. * Callback for when the crafting matrix is changed.
  139. */
  140. public void onCraftMatrixChanged(IInventory par1IInventory)
  141. {
  142. this.craftResult.setInventorySlotContents(0, RecipesIronBench.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
  143. }
  144.  
  145.  
  146. public boolean canInteractWith(EntityPlayer par1EntityPlayer)
  147. {
  148. return this.lowerChestInventory.isUseableByPlayer(par1EntityPlayer);
  149. }
  150.  
  151. /**
  152. * Called to transfer a stack from one inventory to the other eg. when shift clicking.
  153. */
  154. public final ItemStack transferStackInSlot(EntityPlayer entityplayer, int var1)
  155. {
  156. ItemStack var2 = null;
  157. Slot var3 = (Slot)SimCraft.globalFunctions.getContainerSlots(this).get(var1);
  158.  
  159. if (var3 != null && var3.getHasStack())
  160. {
  161. ItemStack var4 = var3.getStack();
  162. var2 = var4.copy();
  163.  
  164. if (var1 < this.guiInventorySize())
  165. {
  166. this.transferToSlots(var4, this.guiInventorySize(), this.inventorySlots.size(), false);
  167. }
  168. else if (var1 >= this.guiInventorySize() && var1 < this.inventorySlots.size() - 9)
  169. {
  170. int var5 = this.getInput();
  171.  
  172. if (var5 != -1 && var5 < this.guiInventorySize())
  173. {
  174. this.transferToSlots(var4, var5, var5 + 1, false);
  175. }
  176. else
  177. {
  178. this.transferToSlots(var4, 0, this.guiInventorySize(), false);
  179. }
  180. }
  181. else if (var1 >= this.guiInventorySize() && var1 >= this.inventorySlots.size() - 9 && var1 < this.inventorySlots.size())
  182. {
  183. this.transferToSlots(var4, this.guiInventorySize(), this.inventorySlots.size() - 9, false);
  184. }
  185.  
  186. if (var4.stackSize == 0)
  187. {
  188. var3.putStack((ItemStack)null);
  189. }
  190. else
  191. {
  192. var3.onSlotChanged();
  193. }
  194.  
  195. if (var4.stackSize == var2.stackSize)
  196. {
  197. return null;
  198. }
  199.  
  200. var3.onPickupFromSlot(entityplayer, var4);
  201. }
  202.  
  203. return var2;
  204. }
  205.  
  206. public void transferToSlots(ItemStack var1, int var2, int var3, boolean var4)
  207. {
  208. this.mergeItemStack(var1, var2, var3, var4);
  209. }
  210.  
  211. public int guiInventorySize()
  212. {
  213. return 27;
  214. }
  215.  
  216. public int getInput()
  217. {
  218. return 0;
  219. }
  220.  
  221. /**
  222. * Callback for when the crafting gui is closed.
  223. */
  224. public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
  225. {
  226. super.onCraftGuiClosed(par1EntityPlayer);
  227. this.lowerChestInventory.closeChest();
  228. this.tile.HammerSlot1Time = 0;
  229. }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment