Guest User

Container

a guest
May 2nd, 2015
13
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package firstetestmod;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.entity.player.InventoryPlayer;
  5. import net.minecraft.inventory.Container;
  6. import net.minecraft.inventory.ICrafting;
  7. import net.minecraft.inventory.Slot;
  8. import net.minecraft.inventory.SlotFurnace;
  9. import net.minecraft.item.ItemStack;
  10. import cpw.mods.fml.relauncher.Side;
  11. import cpw.mods.fml.relauncher.SideOnly;
  12.  
  13. public class ContainerMatterMachine extends Container
  14. {
  15. private TileEntityMatterMachine MatterMachine;
  16. private int lastCookTime;
  17. private int lastBurnTime;
  18.  
  19. public ContainerMatterMachine(InventoryPlayer par1InventoryPlayer, TileEntityMatterMachine par2TileEntityFurnace)
  20. {
  21. this.MatterMachine = par2TileEntityFurnace;
  22. this.addSlotToContainer(new Slot(par2TileEntityFurnace, 0, 56, 35));
  23. this.addSlotToContainer(new SlotMatter(par1InventoryPlayer.player, par2TileEntityFurnace, 1, 116, 35));
  24. int i;
  25.  
  26. for (i = 0; i < 3; ++i)
  27. {
  28. for (int j = 0; j < 9; ++j)
  29. {
  30. this.addSlotToContainer(new Slot(par1InventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  31. }
  32. }
  33.  
  34. for (i = 0; i < 9; ++i)
  35. {
  36. this.addSlotToContainer(new Slot(par1InventoryPlayer, i, 8 + i * 18, 142));
  37. }
  38. }
  39.  
  40. public void addCraftingToCrafters(ICrafting par1ICrafting)
  41. {
  42. super.addCraftingToCrafters(par1ICrafting);
  43. par1ICrafting.sendProgressBarUpdate(this, 0, this.MatterMachine.cookTime);
  44. par1ICrafting.sendProgressBarUpdate(this, 1, this.MatterMachine.power);
  45. }
  46.  
  47. /**
  48. * Looks for changes made in the container, sends them to every listener.
  49. */
  50. public void detectAndSendChanges()
  51. {
  52. super.detectAndSendChanges();
  53.  
  54. for (int i = 0; i < this.crafters.size(); ++i)
  55. {
  56. ICrafting icrafting = (ICrafting)this.crafters.get(i);
  57.  
  58. if (this.lastCookTime != this.MatterMachine.cookTime)
  59. {
  60. icrafting.sendProgressBarUpdate(this, 0, this.MatterMachine.cookTime);
  61. }
  62.  
  63. if (this.lastBurnTime != this.MatterMachine.power)
  64. {
  65. icrafting.sendProgressBarUpdate(this, 1, this.MatterMachine.power);
  66. }
  67. }
  68.  
  69. this.lastCookTime = this.MatterMachine.cookTime;
  70. this.lastBurnTime = this.MatterMachine.power;
  71. }
  72.  
  73. @SideOnly(Side.CLIENT)
  74. public void updateProgressBar(int par1, int par2)
  75. {
  76. if (par1 == 0)
  77. {
  78. this.MatterMachine.cookTime = par2;
  79. }
  80.  
  81. if (par1 == 1)
  82. {
  83. this.MatterMachine.power = par2;
  84. }
  85. }
  86.  
  87. public boolean canInteractWith(EntityPlayer par1EntityPlayer)
  88. {
  89. return this.MatterMachine.isUseableByPlayer(par1EntityPlayer);
  90. }
  91.  
  92. /**
  93. * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
  94. */
  95. public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
  96. {
  97. ItemStack itemstack = null;
  98. Slot slot = (Slot)this.inventorySlots.get(par2);
  99.  
  100. if (slot != null && slot.getHasStack())
  101. {
  102. ItemStack itemstack1 = slot.getStack();
  103. itemstack = itemstack1.copy();
  104.  
  105. if (par2 == 2)
  106. {
  107. if (!this.mergeItemStack(itemstack1, 3, 39, true))
  108. {
  109. return null;
  110. }
  111.  
  112. slot.onSlotChange(itemstack1, itemstack);
  113. }
  114. else if (par2 != 1 && par2 != 0)
  115. {
  116. if (TileEntityMatterMachine.isItemFuel(itemstack1))
  117. {
  118. if (!this.mergeItemStack(itemstack1, 1, 2, false))
  119. {
  120. return null;
  121. }
  122. }
  123. else if (par2 >= 3 && par2 < 30)
  124. {
  125. if (!this.mergeItemStack(itemstack1, 30, 39, false))
  126. {
  127. return null;
  128. }
  129. }
  130. else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
  131. {
  132. return null;
  133. }
  134. }
  135. else if (!this.mergeItemStack(itemstack1, 3, 39, false))
  136. {
  137. return null;
  138. }
  139.  
  140. if (itemstack1.stackSize == 0)
  141. {
  142. slot.putStack((ItemStack)null);
  143. }
  144. else
  145. {
  146. slot.onSlotChanged();
  147. }
  148.  
  149. if (itemstack1.stackSize == itemstack.stackSize)
  150. {
  151. return null;
  152. }
  153.  
  154. slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
  155. }
  156.  
  157. return itemstack;
  158. }
  159. }
RAW Paste Data