Advertisement
Guest User

TileEntityTiny.java

a guest
Sep 5th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. public class TileEntityTiny extends TileEntity implements IInventory {
  4.  
  5.     private ItemStack[] inv;
  6.    
  7.     public TileEntityTiny() {
  8.         inv = new ItemStack[1];
  9.     }
  10.    
  11.     @Override
  12.     public int getSizeInventory() {
  13.         return inv.length;
  14.     }
  15.  
  16.     @Override
  17.     public ItemStack getStackInSlot(int slot) {
  18.         return inv[slot];
  19.     }
  20.  
  21.     @Override
  22.     public ItemStack decrStackSize(int slot, int amt) {
  23.         ItemStack stack = getStackInSlot(slot);
  24.        
  25.         if (stack != null) {
  26.             if (stack.stackSize <= amt) {
  27.                 setInventorySlotContents(slot, null);
  28.             } else {
  29.                 stack = stack.splitStack(amt);
  30.                
  31.                 if (stack.stackSize == 0) {
  32.                     setInventorySlotContents(slot, null);
  33.                 }
  34.             }
  35.         }
  36.        
  37.         return stack;
  38.     }
  39.  
  40.     @Override
  41.     public ItemStack getStackInSlotOnClosing(int slot) {
  42.         ItemStack stack = getStackInSlot(slot);
  43.        
  44.         if (stack != null) {
  45.             setInventorySlotContents(slot, stack);
  46.         }
  47.        
  48.         return stack;
  49.     }
  50.  
  51.     @Override
  52.     public void setInventorySlotContents(int slot, ItemStack stack) {
  53.         inv[slot] = stack;
  54.        
  55.         if (stack != null && stack.stackSize > getInventoryStackLimit()) {
  56.             stack.stackSize = getInventoryStackLimit();
  57.         }
  58.     }
  59.  
  60.     @Override
  61.     public String getInvName() {
  62.         // TODO Auto-generated method stub
  63.         return null;
  64.     }
  65.  
  66.     @Override
  67.     public int getInventoryStackLimit() {
  68.         return 64;
  69.     }
  70.  
  71.     @Override
  72.     public boolean isUseableByPlayer(EntityPlayer player) {
  73.         return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
  74.     }
  75.  
  76.     @Override
  77.     public void openChest() {
  78.         // TODO Auto-generated method stub
  79.  
  80.     }
  81.  
  82.     @Override
  83.     public void closeChest() {
  84.         // TODO Auto-generated method stub
  85.  
  86.     }
  87.    
  88.     @Override
  89.     public void readFromNBT(NBTTagCompound tagCompound) {
  90.         super.readFromNBT(tagCompound);
  91.        
  92.         NBTTagList tagList = tagCompound.getTagList("Inventory");
  93.         for (int i = 0; i < tagList.tagCount(); i++) {
  94.             NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
  95.            
  96.             byte slot = tag.getByte("Slot");
  97.             if (slot >= 0 && slot < inv.length) {
  98.                 inv[slot] = ItemStack.loadItemStackFromNBT(tag);
  99.             }
  100.         }  
  101.     }
  102.    
  103.     @Override
  104.     public void writeToNBT(NBTTagCompound tagCompound) {
  105.         super.writeToNBT(tagCompound);
  106.        
  107.         NBTTagList itemList = new NBTTagList();
  108.         for (int i = 0; i < inv.length; i++) {
  109.             ItemStack stack = inv[i];
  110.             if (stack != null) {
  111.                 NBTTagCompound tag = new NBTTagCompound();
  112.                 tag.setByte("Slot", (byte) i);
  113.                 stack.writeToNBT(tag);
  114.                 itemList.appendTag(tag);
  115.             }
  116.         }
  117.        
  118.         tagCompound.setTag("Inventory", itemList);
  119.     }
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement