grossik

Untitled

Jul 26th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. package cz.grossik.farmcraft2.crushing;
  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.IContainerListener;
  7. import net.minecraft.inventory.IInventory;
  8. import net.minecraft.inventory.Slot;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraftforge.fml.relauncher.Side;
  11. import net.minecraftforge.fml.relauncher.SideOnly;
  12.  
  13. public class ContainerCrushing extends Container
  14. {
  15. private final IInventory tileFurnace;
  16. private int cookTime;
  17. private int totalCookTime;
  18. private int furnaceBurnTime;
  19. private int currentItemBurnTime;
  20.  
  21. public ContainerCrushing(InventoryPlayer playerInventory, TileEntityCrushing te)
  22. {
  23. this.tileFurnace = te;
  24. this.addSlotToContainer(new SlotCrushing(te, 0, 57, 35));
  25. this.addSlotToContainer(new SlotCrushingOutput(playerInventory.player, te, 2, 116, 35));
  26.  
  27. for (int i = 0; i < 3; ++i)
  28. {
  29. for (int j = 0; j < 9; ++j)
  30. {
  31. this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  32. }
  33. }
  34.  
  35. for (int k = 0; k < 9; ++k)
  36. {
  37. this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
  38. }
  39. }
  40.  
  41. public void addListener(IContainerListener listener)
  42. {
  43. super.addListener(listener);
  44. listener.sendAllWindowProperties(this, this.tileFurnace);
  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.listeners.size(); ++i)
  55. {
  56. IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i);
  57.  
  58. if (this.cookTime != this.tileFurnace.getField(2))
  59. {
  60. icontainerlistener.sendProgressBarUpdate(this, 2, this.tileFurnace.getField(2));
  61. }
  62.  
  63. if (this.furnaceBurnTime != this.tileFurnace.getField(0))
  64. {
  65. icontainerlistener.sendProgressBarUpdate(this, 0, this.tileFurnace.getField(0));
  66. }
  67.  
  68. if (this.currentItemBurnTime != this.tileFurnace.getField(1))
  69. {
  70. icontainerlistener.sendProgressBarUpdate(this, 1, this.tileFurnace.getField(1));
  71. }
  72.  
  73. if (this.totalCookTime != this.tileFurnace.getField(3))
  74. {
  75. icontainerlistener.sendProgressBarUpdate(this, 3, this.tileFurnace.getField(3));
  76. }
  77. }
  78.  
  79. this.cookTime = this.tileFurnace.getField(2);
  80. this.furnaceBurnTime = this.tileFurnace.getField(0);
  81. this.currentItemBurnTime = this.tileFurnace.getField(1);
  82. this.totalCookTime = this.tileFurnace.getField(3);
  83. }
  84.  
  85. @SideOnly(Side.CLIENT)
  86. public void updateProgressBar(int id, int data)
  87. {
  88. this.tileFurnace.setField(id, data);
  89. }
  90.  
  91. public boolean canInteractWith(EntityPlayer playerIn)
  92. {
  93. return this.tileFurnace.isUseableByPlayer(playerIn);
  94. }
  95.  
  96. /**
  97. * Take a stack from the specified inventory slot.
  98. */
  99. public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
  100. {
  101. ItemStack itemstack = null;
  102. Slot slot = (Slot)this.inventorySlots.get(index);
  103.  
  104. if (slot != null && slot.getHasStack())
  105. {
  106. ItemStack itemstack1 = slot.getStack();
  107. itemstack = itemstack1.copy();
  108.  
  109. if (index == 2)
  110. {
  111. if (!this.mergeItemStack(itemstack1, 3, 39, true))
  112. {
  113. return null;
  114. }
  115.  
  116. slot.onSlotChange(itemstack1, itemstack);
  117. }
  118. else if (index != 1 && index != 0)
  119. {
  120. if (CrushingRecipes.instance().getSmeltingResult(itemstack1) != null)
  121. {
  122. if (!this.mergeItemStack(itemstack1, 0, 1, false))
  123. {
  124. return null;
  125. }
  126. }
  127. else if (TileEntityCrushing.isItemFuel(itemstack1))
  128. {
  129. if (!this.mergeItemStack(itemstack1, 1, 2, false))
  130. {
  131. return null;
  132. }
  133. }
  134. else if (index >= 3 && index < 30)
  135. {
  136. if (!this.mergeItemStack(itemstack1, 30, 39, false))
  137. {
  138. return null;
  139. }
  140. }
  141. else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
  142. {
  143. return null;
  144. }
  145. }
  146.  
  147. if (itemstack1.stackSize == 0)
  148. {
  149. slot.putStack((ItemStack)null);
  150. }
  151. else
  152. {
  153. slot.onSlotChanged();
  154. }
  155.  
  156. if (itemstack1.stackSize == itemstack.stackSize)
  157. {
  158. return null;
  159. }
  160.  
  161. slot.onPickupFromSlot(playerIn, itemstack1);
  162. }
  163.  
  164. return itemstack;
  165. }
  166. }
Add Comment
Please, Sign In to add comment