Guest User

ContainerSauceMaker

a guest
Jan 26th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. package com.chef.mod.container;
  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.Item;
  10. import net.minecraft.item.ItemStack;
  11.  
  12. import com.chef.mod.crafting.CookFurnaceRecipes;
  13. import com.chef.mod.crafting.SauceMakerRecipes;
  14. import com.chef.mod.slot.SlotSauceMakerBowl;
  15. import com.chef.mod.tileentity.TileEntityCookFurnace;
  16. import com.chef.mod.tileentity.TileEntitySauceMaker;
  17.  
  18. import cpw.mods.fml.relauncher.Side;
  19. import cpw.mods.fml.relauncher.SideOnly;
  20.  
  21. public class ContainerSauceMaker extends Container {
  22.  
  23. private TileEntitySauceMaker sauceMaker;
  24.  
  25. public int lastBurnTime;
  26. public int lastCurrentItemBurnTime;
  27. public int lastCookTime;
  28.  
  29. public ContainerSauceMaker(InventoryPlayer inventory, TileEntitySauceMaker tileentity) {
  30. this.sauceMaker = tileentity;
  31.  
  32. //Input slot 1
  33. this.addSlotToContainer(new Slot(tileentity, 0, 21, 9));
  34.  
  35. //Input slot 2
  36. this.addSlotToContainer(new SlotSauceMakerBowl(tileentity, 1, 49, 51));
  37.  
  38. //Input slot fuel
  39. this.addSlotToContainer(new Slot(tileentity, 2, 21, 51));
  40.  
  41. //Output slot
  42. this.addSlotToContainer(new SlotFurnace(inventory.player, tileentity, 3, 120, 29));
  43.  
  44.  
  45. //Inventory
  46. for(int i = 0; i < 3; i++) {
  47. for(int j = 0; j < 9; j++) {
  48. this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  49. }
  50. }
  51.  
  52. //Action bar
  53. for(int i = 0; i < 9; i++) {
  54. this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
  55. }
  56.  
  57. }
  58.  
  59. public void addCraftingToCrafters (ICrafting icrafting) {
  60. super.addCraftingToCrafters(icrafting);
  61. icrafting.sendProgressBarUpdate(this, 0, this.sauceMaker.cookTime);
  62. icrafting.sendProgressBarUpdate(this, 1, this.sauceMaker.burnTime);
  63. icrafting.sendProgressBarUpdate(this, 2, this.sauceMaker.currentItemBurnTime);
  64. }
  65.  
  66. public void detectAndSendChanges() {
  67. super.detectAndSendChanges();
  68. for(int i = 0; i < this.crafters.size(); i++) {
  69. ICrafting icrafting = (ICrafting) this.crafters.get(i);
  70.  
  71. if(this.lastCookTime != this.sauceMaker.cookTime) {
  72. icrafting.sendProgressBarUpdate(this, 0, this.sauceMaker.cookTime);
  73. }
  74.  
  75. if(this.lastBurnTime != this.sauceMaker.burnTime) {
  76. icrafting.sendProgressBarUpdate(this, 1, this.sauceMaker.burnTime);
  77. }
  78.  
  79. if(this.lastCurrentItemBurnTime != this.sauceMaker.currentItemBurnTime) {
  80. icrafting.sendProgressBarUpdate(this, 2, this.sauceMaker.currentItemBurnTime);
  81. }
  82. }
  83.  
  84. this.lastCookTime = this.sauceMaker.cookTime;
  85. this.lastBurnTime = this.sauceMaker.burnTime;
  86. this.lastCurrentItemBurnTime = this.sauceMaker.currentItemBurnTime;
  87. }
  88.  
  89. @SideOnly(Side.CLIENT)
  90. public void updateProgressBar(int par1, int par2)
  91. {
  92. if (par1 == 0) {
  93. this.sauceMaker.cookTime = par2;
  94. }
  95.  
  96. if (par1 == 1) {
  97. this.sauceMaker.burnTime = par2;
  98. }
  99.  
  100. if(par1 == 2) {
  101. this.sauceMaker.currentItemBurnTime = par2;
  102. }
  103. }
  104.  
  105. public ItemStack transferStackInSlot(EntityPlayer player, int slot)
  106. {
  107. ItemStack itemstack = null;
  108. Slot containerslot = (Slot)this.inventorySlots.get(slot);
  109. Item item = null;
  110. Item item2 = null;
  111.  
  112. if (containerslot != null && containerslot.getHasStack()) {
  113. ItemStack itemstack1 = containerslot.getStack();
  114. itemstack = itemstack1.copy();
  115.  
  116. if (slot == 2)
  117. {
  118. if (!this.mergeItemStack(itemstack1, 3, 39, true))
  119. {
  120. return null;
  121. }
  122.  
  123. containerslot.onSlotChange(itemstack1, itemstack);
  124. }
  125.  
  126. else if (slot == 1)
  127. {
  128. if (!this.mergeItemStack(itemstack1, 3, 39, true))
  129. {
  130. return null;
  131. }
  132.  
  133. containerslot.onSlotChange(itemstack1, itemstack);
  134. }
  135.  
  136. else if (slot == 0)
  137. {
  138. if (!this.mergeItemStack(itemstack1, 3, 39, true))
  139. {
  140. return null;
  141. }
  142.  
  143. containerslot.onSlotChange(itemstack1, itemstack);
  144. }
  145.  
  146. else if (slot != 1 && slot != 0)
  147. {
  148. if (SauceMakerRecipes.getJuicingResult(item, item2) != null)
  149. {
  150. {
  151. return null;
  152. }
  153. }
  154. else if (TileEntitySauceMaker.isItemIngredient(itemstack1))
  155. {
  156. if (!this.mergeItemStack(itemstack1, 0, 1, false))
  157. {
  158. return null;
  159. }
  160. }
  161.  
  162. else if (TileEntitySauceMaker.isItemBowl(itemstack1))
  163. {
  164. if (!this.mergeItemStack(itemstack1, 1, 2, false))
  165. {
  166. return null;
  167. }
  168. }
  169.  
  170. else if (TileEntitySauceMaker.isItemFuel(itemstack1))
  171. {
  172. if (!this.mergeItemStack(itemstack1, 2, 3, false))
  173. {
  174. return null;
  175. }
  176. }
  177. else if (slot >= 3 && slot < 30)
  178. {
  179. if (!this.mergeItemStack(itemstack1, 30, 39, false))
  180. {
  181. return null;
  182. }
  183. }
  184. //For placing it in the output
  185. else if (slot >= 30 && slot < 39 && !this.mergeItemStack(itemstack1, 4, 30, false))
  186. {
  187. return null;
  188. }
  189. }
  190. else if (!this.mergeItemStack(itemstack1, 3, 39, false))
  191. {
  192. return null;
  193. }
  194.  
  195. if (itemstack1.stackSize == 0)
  196. {
  197. containerslot.putStack((ItemStack)null);
  198. }
  199. else
  200. {
  201. containerslot.onSlotChanged();
  202. }
  203.  
  204. if (itemstack1.stackSize == itemstack.stackSize)
  205. {
  206. return null;
  207. }
  208.  
  209. containerslot.onPickupFromSlot(player, itemstack1);
  210. }
  211.  
  212. return itemstack;
  213. }
  214.  
  215.  
  216. @Override
  217. public boolean canInteractWith(EntityPlayer player) {
  218. return true;
  219. }
  220.  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment