Guest User

ContainerCookingFurnace

a guest
Feb 21st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.65 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.IInventory;
  8. import net.minecraft.inventory.Slot;
  9. import net.minecraft.inventory.SlotFurnaceFuel;
  10. import net.minecraft.inventory.SlotFurnaceOutput;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.item.crafting.FurnaceRecipes;
  13. import net.minecraft.tileentity.TileEntityFurnace;
  14. import net.minecraftforge.fml.relauncher.Side;
  15. import net.minecraftforge.fml.relauncher.SideOnly;
  16.  
  17. public class ContainerCookingFurnace extends Container
  18. {
  19.     private final IInventory tileFurnace;
  20.     private int field_178152_f;
  21.     private int field_178153_g;
  22.     private int field_178154_h;
  23.     private int field_178155_i;
  24.     private static final String __OBFID = "CL_00001748";
  25.  
  26.     public ContainerCookingFurnace(InventoryPlayer invPlayer, IInventory cookingFurnaceInventory)
  27.     {
  28.         this.tileFurnace = cookingFurnaceInventory;
  29.         this.addSlotToContainer(new Slot(cookingFurnaceInventory, 0, 56, 17));
  30.         this.addSlotToContainer(new SlotFurnaceFuel(cookingFurnaceInventory, 1, 56, 53));
  31.         this.addSlotToContainer(new SlotFurnaceOutput(invPlayer.player, cookingFurnaceInventory, 2, 116, 35));
  32.         this.addSlotToContainer(new Slot(cookingFurnaceInventory, 3, 60, 27));
  33.         int i;
  34.  
  35.         for (i = 0; i < 3; ++i)
  36.         {
  37.             for (int j = 0; j < 9; ++j)
  38.             {
  39.                 this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  40.             }
  41.         }
  42.  
  43.         for (i = 0; i < 9; ++i)
  44.         {
  45.             this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
  46.         }
  47.     }
  48.  
  49.     public void addCraftingToCrafters(ICrafting listener)
  50.     {
  51.         super.addCraftingToCrafters(listener);
  52.         listener.func_175173_a(this, this.tileFurnace);
  53.     }
  54.  
  55.     public void detectAndSendChanges()
  56.     {
  57.         super.detectAndSendChanges();
  58.  
  59.         for (int i = 0; i < this.crafters.size(); ++i)
  60.         {
  61.             ICrafting icrafting = (ICrafting)this.crafters.get(i);
  62.  
  63.             if (this.field_178152_f != this.tileFurnace.getField(2))
  64.             {
  65.                 icrafting.sendProgressBarUpdate(this, 2, this.tileFurnace.getField(2));
  66.             }
  67.  
  68.             if (this.field_178154_h != this.tileFurnace.getField(0))
  69.             {
  70.                 icrafting.sendProgressBarUpdate(this, 0, this.tileFurnace.getField(0));
  71.             }
  72.  
  73.             if (this.field_178155_i != this.tileFurnace.getField(1))
  74.             {
  75.                 icrafting.sendProgressBarUpdate(this, 1, this.tileFurnace.getField(1));
  76.             }
  77.  
  78.             if (this.field_178153_g != this.tileFurnace.getField(3))
  79.             {
  80.                 icrafting.sendProgressBarUpdate(this, 3, this.tileFurnace.getField(3));
  81.             }
  82.         }
  83.  
  84.         this.field_178152_f = this.tileFurnace.getField(2);
  85.         this.field_178154_h = this.tileFurnace.getField(0);
  86.         this.field_178155_i = this.tileFurnace.getField(1);
  87.         this.field_178153_g = this.tileFurnace.getField(3);
  88.     }
  89.  
  90.     @SideOnly(Side.CLIENT)
  91.     public void updateProgressBar(int id, int data)
  92.     {
  93.         this.tileFurnace.setField(id, data);
  94.     }
  95.  
  96.     public boolean canInteractWith(EntityPlayer playerIn)
  97.     {
  98.         return this.tileFurnace.isUseableByPlayer(playerIn);
  99.     }
  100.  
  101.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
  102.     {
  103.         ItemStack itemstack = null;
  104.         Slot slot = (Slot)this.inventorySlots.get(index);
  105.  
  106.         if (slot != null && slot.getHasStack())
  107.         {
  108.             ItemStack itemstack1 = slot.getStack();
  109.             itemstack = itemstack1.copy();
  110.  
  111.             if (index == 2)
  112.             {
  113.                 if (!this.mergeItemStack(itemstack1, 3, 39, true))
  114.                 {
  115.                     return null;
  116.                 }
  117.  
  118.                 slot.onSlotChange(itemstack1, itemstack);
  119.             }
  120.             else if (index != 1 && index != 0)
  121.             {
  122.                 if (FurnaceRecipes.instance().getSmeltingResult(itemstack1) != null)
  123.                 {
  124.                     if (!this.mergeItemStack(itemstack1, 0, 1, false))
  125.                     {
  126.                         return null;
  127.                     }
  128.                 }
  129.                 else if (TileEntityFurnace.isItemFuel(itemstack1))
  130.                 {
  131.                     if (!this.mergeItemStack(itemstack1, 1, 2, false))
  132.                     {
  133.                         return null;
  134.                     }
  135.                 }
  136.                 else if (index >= 3 && index < 30)
  137.                 {
  138.                     if (!this.mergeItemStack(itemstack1, 30, 39, false))
  139.                     {
  140.                         return null;
  141.                     }
  142.                 }
  143.                 else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
  144.                 {
  145.                     return null;
  146.                 }
  147.             }
  148.             else if (!this.mergeItemStack(itemstack1, 3, 39, false))
  149.             {
  150.                 return null;
  151.             }
  152.  
  153.             if (itemstack1.stackSize == 0)
  154.             {
  155.                 slot.putStack((ItemStack)null);
  156.             }
  157.             else
  158.             {
  159.                 slot.onSlotChanged();
  160.             }
  161.  
  162.             if (itemstack1.stackSize == itemstack.stackSize)
  163.             {
  164.                 return null;
  165.             }
  166.  
  167.             slot.onPickupFromSlot(playerIn, itemstack1);
  168.         }
  169.  
  170.         return itemstack;
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment