Advertisement
Guest User

Container Furnace

a guest
May 2nd, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. package com.mazetar.mazLearnedThis;
  2.  
  3.  
  4. import com.mazetar.mazLearnedThis.tileentity.TileEntityFurnaceChest;
  5.  
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.entity.player.InventoryPlayer;
  8. import net.minecraft.inventory.Container;
  9. import net.minecraft.inventory.Slot;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.tileentity.TileEntity;
  12.  
  13. public class CotainerFurnaceChest extends Container {
  14.  
  15.         public TileEntityFurnaceChest tileEntity;
  16.         public InventoryPlayer playerInventory;
  17.        
  18.    
  19.     public CotainerFurnaceChest(TileEntity te,
  20.             EntityPlayer player) {
  21.         tileEntity = (TileEntityFurnaceChest)te;
  22.         playerInventory = player.inventory;
  23.         int rowCount = 6;
  24.         int colCount = 9;
  25.         final int SLOT_SIZE = 18;
  26.        
  27.        
  28.       //the Slot constructor takes the IInventory and the slot number in that it binds to
  29.         //and the x-y coordinates it resides on-screen
  30.         /* Sets up the chest inventory */
  31.         int slotNum = 0;
  32.         for (int row = 0; row < rowCount; row++) {
  33.                 for (int col = 0; col < colCount; col++) {
  34.                         addSlotToContainer(new Slot(tileEntity, slotNum, 12 + col * SLOT_SIZE, 8 + row * SLOT_SIZE));
  35.                         slotNum++;
  36.                      // New Slot (Inventory, SlotNumber, xPosition, yPosition);
  37.                        
  38.                 }
  39.         }
  40.        
  41.         /* Player Inventory */
  42.         for (int playerRow = 0; playerRow < 3; playerRow++)
  43.             for (int playerCol = 0; playerCol < 9; playerCol++)
  44.                addSlotToContainer(new Slot(playerInventory, playerCol + playerRow * 9 + 9, 12 + playerCol * SLOT_SIZE, 8 + playerRow * SLOT_SIZE));
  45.        
  46.         /* Player hotbar */
  47.         for (int hotSlotNum = 0; hotSlotNum < 9; hotSlotNum++){
  48.                addSlotToContainer(new Slot(playerInventory, hotSlotNum, 12 + hotSlotNum * SLOT_SIZE, 8 -24));
  49.         }
  50.        
  51.     }
  52.    
  53.     @Override
  54.     public ItemStack transferStackInSlot(EntityPlayer p, int i)
  55.     {
  56.         ItemStack itemstack = null;
  57.         Slot slot = (Slot) inventorySlots.get(i);
  58.         if (slot != null && slot.getHasStack())
  59.         {
  60.             ItemStack itemstack1 = slot.getStack();
  61.             itemstack = itemstack1.copy();
  62.             int invSize = tileEntity.getSizeInventory();
  63.             if (i < invSize)
  64.             {
  65.                 if (!mergeItemStack(itemstack1, invSize, inventorySlots.size(), true))
  66.                 {
  67.                     return null;
  68.                 }
  69.             }
  70.             else if (!mergeItemStack(itemstack1, 0, invSize, false))
  71.             {
  72.                 return null;
  73.             }
  74.             if (itemstack1.stackSize == 0)
  75.             {
  76.                 slot.putStack(null);
  77.             }
  78.             else
  79.             {
  80.                 slot.onSlotChanged();
  81.             }
  82.         }
  83.         return itemstack;
  84.     }
  85.    
  86.  
  87.     @Override
  88.     public boolean canInteractWith(EntityPlayer entityplayer) {
  89.         // TODO Auto-generated method stub
  90.         return true;
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement