Guest User

Untitled

a guest
Jan 22nd, 2018
24
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package forgingaura.forgeyourworld.ffactory.Container;
  2.  
  3. import forgingaura.forgeyourworld.ffactory.tileentity.TileEntitySteampunkFurnace;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.entity.player.InventoryPlayer;
  6. import net.minecraft.inventory.*;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.item.crafting.FurnaceRecipes;
  9. import net.minecraftforge.fml.relauncher.Side;
  10. import net.minecraftforge.fml.relauncher.SideOnly;
  11.  
  12. public class ContainerSteampunkFurnace extends Container {
  13. private final IInventory tileFurnace;
  14. private int cookTime;
  15. private int totalCookTime;
  16. private int furnaceBurnTime;
  17. private int currentItemBurnTime;
  18.  
  19. public ContainerSteampunkFurnace(InventoryPlayer playerInventory, IInventory furnaceInventory)
  20. {
  21. this.tileFurnace = furnaceInventory;
  22. this.addSlotToContainer(new Slot(furnaceInventory, 0, 56, 17));
  23. this.addSlotToContainer(new SlotFurnaceFuel(furnaceInventory, 1, 56, 53));
  24. this.addSlotToContainer(new SlotFurnaceOutput(playerInventory.player, furnaceInventory, 2, 116, 35));
  25.  
  26. for (int i = 0; i < 3; ++i)
  27. {
  28. for (int j = 0; j < 9; ++j)
  29. {
  30. this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  31. }
  32. }
  33.  
  34. for (int k = 0; k < 9; ++k)
  35. {
  36. this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
  37. }
  38. }
  39.  
  40. public void addListener(IContainerListener listener)
  41. {
  42. super.addListener(listener);
  43. listener.sendAllWindowProperties(this, this.tileFurnace);
  44. }
  45.  
  46. /**
  47. * Looks for changes made in the container, sends them to every listener.
  48. */
  49. public void detectAndSendChanges()
  50. {
  51. super.detectAndSendChanges();
  52.  
  53. for (int i = 0; i < this.listeners.size(); ++i)
  54. {
  55. IContainerListener icontainerlistener = this.listeners.get(i);
  56.  
  57. if (this.cookTime != this.tileFurnace.getField(2))
  58. {
  59. icontainerlistener.sendWindowProperty(this, 2, this.tileFurnace.getField(2));
  60. }
  61.  
  62. if (this.furnaceBurnTime != this.tileFurnace.getField(0))
  63. {
  64. icontainerlistener.sendWindowProperty(this, 0, this.tileFurnace.getField(0));
  65. }
  66.  
  67. if (this.currentItemBurnTime != this.tileFurnace.getField(1))
  68. {
  69. icontainerlistener.sendWindowProperty(this, 1, this.tileFurnace.getField(1));
  70. }
  71.  
  72. if (this.totalCookTime != this.tileFurnace.getField(3))
  73. {
  74. icontainerlistener.sendWindowProperty(this, 3, this.tileFurnace.getField(3));
  75. }
  76. }
  77.  
  78. this.cookTime = this.tileFurnace.getField(2);
  79. this.furnaceBurnTime = this.tileFurnace.getField(0);
  80. this.currentItemBurnTime = this.tileFurnace.getField(1);
  81. this.totalCookTime = this.tileFurnace.getField(3);
  82. }
  83.  
  84. @SideOnly(Side.CLIENT)
  85. public void updateProgressBar(int id, int data)
  86. {
  87. this.tileFurnace.setField(id, data);
  88. }
  89.  
  90. /**
  91. * Determines whether supplied player can use this container
  92. */
  93. public boolean canInteractWith(EntityPlayer playerIn)
  94. {
  95. return this.tileFurnace.isUsableByPlayer(playerIn);
  96. }
  97.  
  98. /**
  99. * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
  100. * inventory and the other inventory(s).
  101. */
  102. public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
  103. {
  104. ItemStack itemstack = ItemStack.EMPTY;
  105. Slot slot = this.inventorySlots.get(index);
  106.  
  107. if (slot != null && slot.getHasStack())
  108. {
  109. ItemStack itemstack1 = slot.getStack();
  110. itemstack = itemstack1.copy();
  111.  
  112. if (index == 2)
  113. {
  114. if (!this.mergeItemStack(itemstack1, 3, 39, true))
  115. {
  116. return ItemStack.EMPTY;
  117. }
  118.  
  119. slot.onSlotChange(itemstack1, itemstack);
  120. }
  121. else if (index != 1 && index != 0)
  122. {
  123. if (!FurnaceRecipes.instance().getSmeltingResult(itemstack1).isEmpty())
  124. {
  125. if (!this.mergeItemStack(itemstack1, 0, 1, false))
  126. {
  127. return ItemStack.EMPTY;
  128. }
  129. }
  130. else if (TileEntitySteampunkFurnace.isItemFuel(itemstack1))
  131. {
  132. if (!this.mergeItemStack(itemstack1, 1, 2, false))
  133. {
  134. return ItemStack.EMPTY;
  135. }
  136. }
  137. else if (index >= 3 && index < 30)
  138. {
  139. if (!this.mergeItemStack(itemstack1, 30, 39, false))
  140. {
  141. return ItemStack.EMPTY;
  142. }
  143. }
  144. else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
  145. {
  146. return ItemStack.EMPTY;
  147. }
  148. }
  149. else if (!this.mergeItemStack(itemstack1, 3, 39, false))
  150. {
  151. return ItemStack.EMPTY;
  152. }
  153.  
  154. if (itemstack1.isEmpty())
  155. {
  156. slot.putStack(ItemStack.EMPTY);
  157. }
  158. else
  159. {
  160. slot.onSlotChanged();
  161. }
  162.  
  163. if (itemstack1.getCount() == itemstack.getCount())
  164. {
  165. return ItemStack.EMPTY;
  166. }
  167.  
  168. slot.onTake(playerIn, itemstack1);
  169. }
  170.  
  171. return itemstack;
  172. }
  173. }
RAW Paste Data