Advertisement
Guest User

Untitled

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