redfoxhint

ContainerAlloyOven Class

Oct 23rd, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.04 KB | None | 0 0
  1. package com.arucraft.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.item.ItemStack;
  9. import net.minecraft.item.crafting.FurnaceRecipes;
  10. import net.minecraft.tileentity.TileEntityFurnace;
  11.  
  12. import com.arucraft.slot.SlotAlloyOven;
  13. import com.arucraft.tileentity.TileEntityAlloyOven;
  14.  
  15. public class ContainerAlloyOven extends Container {
  16.  
  17.     private TileEntityAlloyOven oven;
  18.     private int tripCookTime;
  19.     private int tripPower;
  20.     private int lastItemBurnTime;
  21.  
  22.     public ContainerAlloyOven(InventoryPlayer invPlayer, TileEntityAlloyOven teAlloyOven) {
  23.         tripCookTime = 0;
  24.         tripPower = 0;
  25.         lastItemBurnTime = 0;
  26.  
  27.         oven = teAlloyOven;
  28.  
  29.         this.addSlotToContainer(new Slot(teAlloyOven, 0, 44, 16));
  30.         this.addSlotToContainer(new Slot(teAlloyOven, 1, 44, 35));
  31.         this.addSlotToContainer(new Slot(teAlloyOven, 2, 44, 54));
  32.         this.addSlotToContainer(new Slot(teAlloyOven, 3, 8, 55));
  33.         this.addSlotToContainer(new SlotAlloyOven(invPlayer.player, teAlloyOven, 4, 124, 35));
  34.  
  35.         //Inventory
  36.         for(int i = 0; i < 3; i++) {
  37.             for(int j = 0; j < 9; j++) {
  38.                 this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  39.             }
  40.         }
  41.        
  42.        
  43.  
  44.         //ActionBar
  45.         for(int i = 0; i < 9; i++) {
  46.             this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
  47.         }
  48.  
  49.     }
  50.    
  51.     public void addCraftingToCrafters (ICrafting icraft) {
  52.         super.addCraftingToCrafters(icraft);
  53.         icraft.sendProgressBarUpdate(this, 0, this.oven.tripCooktime);
  54.         icraft.sendProgressBarUpdate(this, 1, this.oven.tripPower);
  55.     }
  56.    
  57.     public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
  58.     {
  59.         ItemStack itemstack = null;
  60.         Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);
  61.  
  62.         if (slot != null && slot.getHasStack())
  63.         {
  64.             ItemStack itemstack1 = slot.getStack();
  65.             itemstack = itemstack1.copy();
  66.  
  67.             if (p_82846_2_ == 2)
  68.             {
  69.                 if (!this.mergeItemStack(itemstack1, 3, 39, true))
  70.                 {
  71.                     return null;
  72.                 }
  73.  
  74.                 slot.onSlotChange(itemstack1, itemstack);
  75.             }
  76.             else if (p_82846_2_ != 1 && p_82846_2_ != 0)
  77.             {
  78.                 if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
  79.                 {
  80.                     if (!this.mergeItemStack(itemstack1, 0, 1, false))
  81.                     {
  82.                         return null;
  83.                     }
  84.                 }
  85.                 else if (TileEntityFurnace.isItemFuel(itemstack1))
  86.                 {
  87.                     if (!this.mergeItemStack(itemstack1, 1, 2, false))
  88.                     {
  89.                         return null;
  90.                     }
  91.                 }
  92.                 else if (p_82846_2_ >= 3 && p_82846_2_ < 30)
  93.                 {
  94.                     if (!this.mergeItemStack(itemstack1, 30, 39, false))
  95.                     {
  96.                         return null;
  97.                     }
  98.                 }
  99.                 else if (p_82846_2_ >= 30 && p_82846_2_ < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
  100.                 {
  101.                     return null;
  102.                 }
  103.             }
  104.             else if (!this.mergeItemStack(itemstack1, 3, 39, false))
  105.             {
  106.                 return null;
  107.             }
  108.  
  109.             if (itemstack1.stackSize == 0)
  110.             {
  111.                 slot.putStack((ItemStack)null);
  112.             }
  113.             else
  114.             {
  115.                 slot.onSlotChanged();
  116.             }
  117.  
  118.             if (itemstack1.stackSize == itemstack.stackSize)
  119.             {
  120.                 return null;
  121.             }
  122.  
  123.             slot.onPickupFromSlot(p_82846_1_, itemstack1);
  124.         }
  125.  
  126.         return itemstack;
  127.     }
  128.  
  129.     @Override
  130.     public boolean canInteractWith(EntityPlayer player) {
  131.         return oven.isUseableByPlayer(player);
  132.     }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment