Advertisement
Guest User

NaturalisContainerPowerFurnace

a guest
Jul 29th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.20 KB | None | 0 0
  1. package nekpek.mod.Naturalis.PowerFurnace;
  2.  
  3. import nekpek.mod.Naturalis.blocks.TileEntityNaturalisFurnace;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.entity.player.InventoryPlayer;
  6. import net.minecraft.inventory.Container;
  7. import net.minecraft.inventory.ICrafting;
  8. import net.minecraft.inventory.Slot;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.item.crafting.FurnaceRecipes;
  11. import cpw.mods.fml.relauncher.Side;
  12. import cpw.mods.fml.relauncher.SideOnly;
  13.  
  14. public class NaturalisContainerPowerFurnace extends Container
  15.     {
  16.         private final TileEntityNaturalisFurnace furnace;
  17.         private int lastCookTime;
  18.         private int lastBurnTime;
  19.         private int lastItemBurnTime;
  20.  
  21.         public NaturalisContainerPowerFurnace(InventoryPlayer par1InventoryPlayer, TileEntityNaturalisFurnace par2TileEntityFurnace)
  22.             {
  23.                 this.furnace = par2TileEntityFurnace;
  24.                 this.addSlotToContainer(new Slot(par2TileEntityFurnace, 0, 56, 17));
  25.                 this.addSlotToContainer(new Slot(par2TileEntityFurnace, 1, 20, 17));
  26.                 this.addSlotToContainer(new SlotNaturalisFurnace(par1InventoryPlayer.player, par2TileEntityFurnace, 2, 116, 35));
  27.                 int i;
  28.  
  29.                 for (i = 0; i < 3; ++i)
  30.                     {
  31.                         for (int j = 0; j < 9; ++j)
  32.                             {
  33.                                 this.addSlotToContainer(new Slot(par1InventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  34.                             }
  35.                     }
  36.  
  37.                 for (i = 0; i < 9; ++i)
  38.                     {
  39.                         this.addSlotToContainer(new Slot(par1InventoryPlayer, i, 8 + i * 18, 142));
  40.                     }
  41.             }
  42.  
  43.         @Override
  44.         public void addCraftingToCrafters(ICrafting par1ICrafting)
  45.             {
  46.                 super.addCraftingToCrafters(par1ICrafting);
  47.                 par1ICrafting.sendProgressBarUpdate(this, 0, this.furnace.furnaceCookTime);
  48.                 par1ICrafting.sendProgressBarUpdate(this, 1, this.furnace.furnaceCookTime);
  49.                 par1ICrafting.sendProgressBarUpdate(this, 2, this.furnace.currentItemBurnTime);
  50.             }
  51.  
  52.         /**
  53.          * Looks for changes made in the container, sends them to every
  54.          * listener.
  55.          */
  56.         @Override
  57.         public void detectAndSendChanges()
  58.             {
  59.                 super.detectAndSendChanges();
  60.  
  61.                 for (int i = 0; i < this.crafters.size(); ++i)
  62.                     {
  63.                         ICrafting icrafting = (ICrafting) this.crafters.get(i);
  64.  
  65.                         if (this.lastCookTime != this.furnace.furnaceCookTime)
  66.                             {
  67.                                 icrafting.sendProgressBarUpdate(this, 0, this.furnace.furnaceCookTime);
  68.                             }
  69.  
  70.                         if (this.lastCookTime != this.furnace.furnaceCookTime)
  71.                             {
  72.                                 icrafting.sendProgressBarUpdate(this, 1, this.furnace.furnaceCookTime);
  73.                             }
  74.  
  75.                         if (this.lastItemBurnTime != this.furnace.currentItemBurnTime)
  76.                             {
  77.                                 icrafting.sendProgressBarUpdate(this, 2, this.furnace.currentItemBurnTime);
  78.                             }
  79.                     }
  80.  
  81.                 this.lastCookTime = this.furnace.furnaceCookTime;
  82.                 this.lastBurnTime = this.furnace.furnaceBurnTime;
  83.                 this.lastItemBurnTime = this.furnace.currentItemBurnTime;
  84.             }
  85.  
  86.         @Override
  87.         @SideOnly(Side.CLIENT)
  88.         public void updateProgressBar(int par1, int par2)
  89.             {
  90.                 if (par1 == 0)
  91.                     {
  92.                         this.furnace.furnaceCookTime = par2;
  93.                     }
  94.  
  95.                 if (par1 == 1)
  96.                     {
  97.                         this.furnace.furnaceCookTime = par2;
  98.                     }
  99.  
  100.                 if (par1 == 2)
  101.                     {
  102.                         this.furnace.currentItemBurnTime = par2;
  103.                     }
  104.             }
  105.  
  106.         @Override
  107.         public boolean canInteractWith(EntityPlayer par1EntityPlayer)
  108.             {
  109.                 return this.furnace.isUseableByPlayer(par1EntityPlayer);
  110.             }
  111.  
  112.         /**
  113.          * Called when a player shift-clicks on a slot. You must override this
  114.          * or you will crash when someone does that.
  115.          */
  116.         @Override
  117.         public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
  118.             {
  119.                 ItemStack itemstack = null;
  120.                 Slot slot = (Slot) this.inventorySlots.get(par2);
  121.  
  122.                 if (slot != null && slot.getHasStack())
  123.                     {
  124.                         ItemStack itemstack1 = slot.getStack();
  125.                         itemstack = itemstack1.copy();
  126.  
  127.                         if (par2 == 2)
  128.                             {
  129.                                 if (!this.mergeItemStack(itemstack1, 3, 39, true))
  130.                                     {
  131.                                         return null;
  132.                                     }
  133.  
  134.                                 slot.onSlotChange(itemstack1, itemstack);
  135.                             }
  136.                         else
  137.                             if (par2 != 1 && par2 != 0)
  138.                                 {
  139.                                     if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
  140.                                         {
  141.                                             if (!this.mergeItemStack(itemstack1, 0, 1, false))
  142.                                                 {
  143.                                                     return null;
  144.                                                 }
  145.                                         }
  146.                                     else
  147.                                         if (TileEntityNaturalisFurnace.isItemFuel(itemstack1))
  148.                                             {
  149.                                                 if (!this.mergeItemStack(itemstack1, 1, 2, false))
  150.                                                     {
  151.                                                         return null;
  152.                                                     }
  153.                                             }
  154.                                         else
  155.                                             if (par2 >= 3 && par2 < 30)
  156.                                                 {
  157.                                                     if (!this.mergeItemStack(itemstack1, 30, 39, false))
  158.                                                         {
  159.                                                             return null;
  160.                                                         }
  161.                                                 }
  162.                                             else
  163.                                                 if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
  164.                                                     {
  165.                                                         return null;
  166.                                                     }
  167.                                 }
  168.                             else
  169.                                 if (!this.mergeItemStack(itemstack1, 3, 39, false))
  170.                                     {
  171.                                         return null;
  172.                                     }
  173.  
  174.                         if (itemstack1.stackSize == 0)
  175.                             {
  176.                                 slot.putStack((ItemStack) null);
  177.                             }
  178.                         else
  179.                             {
  180.                                 slot.onSlotChanged();
  181.                             }
  182.  
  183.                         if (itemstack1.stackSize == itemstack.stackSize)
  184.                             {
  185.                                 return null;
  186.                             }
  187.  
  188.                         slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
  189.                     }
  190.  
  191.                 return itemstack;
  192.             }
  193.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement