Advertisement
Mrolas

TilEntityShopStop.java

Dec 28th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. package mrolas.muchMoney.common.tileEntities;
  2.  
  3. import mrolas.muchMoney.common.item.Items;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.nbt.NBTTagCompound;
  8. import net.minecraft.nbt.NBTTagList;
  9. import net.minecraft.tileentity.TileEntity;
  10.  
  11. public class TileEntityShopStop
  12.     extends TileEntity
  13.     implements IInventory
  14. {
  15.     private long coins;
  16.    
  17.     private long price;
  18.    
  19.     private ItemStack[] stacks;
  20.    
  21.     public TileEntityShopStop ()
  22.     {
  23.         stacks = new ItemStack[6];
  24.     }
  25.  
  26.     @Override
  27.     public int getSizeInventory ()
  28.     {
  29.         return stacks.length;
  30.     }
  31.  
  32.     @Override
  33.     public ItemStack getStackInSlot (int i)
  34.     {
  35.         return stacks[i];
  36.     }
  37.  
  38.     @Override
  39.     public ItemStack decrStackSize (int i, int j)
  40.     {
  41.         ItemStack stack = getStackInSlot(i);
  42.        
  43.         if (stack != null)
  44.         {
  45.             if (stack.stackSize <= j)
  46.             {
  47.                 setInventorySlotContents(i, null);
  48.             }
  49.             else
  50.             {
  51.                 stack = stack.splitStack(j);
  52.                 onInventoryChanged();
  53.             }
  54.         }
  55.        
  56.         return stack;
  57.     }
  58.  
  59.     @Override
  60.     public ItemStack getStackInSlotOnClosing (int i)
  61.     {
  62.         ItemStack stack = getStackInSlot(i);
  63.         setInventorySlotContents(i, null);
  64.         return stack;
  65.     }
  66.  
  67.     @Override
  68.     public void setInventorySlotContents (int i, ItemStack itemstack)
  69.     {
  70.         stacks[i] = itemstack;
  71.        
  72.         if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
  73.         {
  74.             itemstack.stackSize = getInventoryStackLimit();
  75.         }
  76.        
  77.         onInventoryChanged();
  78.     }
  79.  
  80.     @Override
  81.     public String getInvName ()
  82.     {
  83.         return "InventoryShopStop";
  84.     }
  85.  
  86.     @Override
  87.     public boolean isInvNameLocalized ()
  88.     {
  89.         return false;
  90.     }
  91.  
  92.     @Override
  93.     public int getInventoryStackLimit ()
  94.     {
  95.         return 64;
  96.     }
  97.  
  98.     @Override
  99.     public boolean isUseableByPlayer (EntityPlayer entityplayer)
  100.     {
  101.         return entityplayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64;
  102.     }
  103.  
  104.     @Override
  105.     public void openChest () {}
  106.  
  107.     @Override
  108.     public void closeChest () {}
  109.  
  110.     @Override
  111.     public boolean isItemValidForSlot (int i, ItemStack itemstack)
  112.     {
  113.         if (i == 5)
  114.         {
  115.             return true;
  116.         }
  117.         else
  118.         {
  119.             return itemstack.itemID == Items.coin.itemID;
  120.         }
  121.     }
  122.    
  123.     @Override
  124.     public void writeToNBT (NBTTagCompound compound)
  125.     {
  126.         super.writeToNBT(compound);
  127.        
  128.         NBTTagList items = new NBTTagList();
  129.        
  130.         for (int i = 0; i < getSizeInventory(); i++)
  131.         {
  132.             ItemStack stack = getStackInSlot(i);
  133.            
  134.             if (stack != null)
  135.             {
  136.                 NBTTagCompound item = new NBTTagCompound();
  137.                 item.setByte("Slot", (byte)i);
  138.                 stack.writeToNBT(compound);
  139.                 items.appendTag(item);
  140.             }
  141.         }
  142.        
  143.         compound.setTag("Items", items);   
  144.     }
  145.    
  146.     @Override
  147.     public void readFromNBT (NBTTagCompound compound)
  148.     {
  149.         super.readFromNBT(compound);
  150.        
  151.         NBTTagList items = compound.getTagList("Items");
  152.        
  153.         for (int i = 0; i < items.tagCount(); i++)
  154.         {
  155.             NBTTagCompound item = (NBTTagCompound)items.tagAt(i);
  156.            
  157.             int slot = item.getByte("Slot");
  158.            
  159.             if (slot >= 0 && slot < getSizeInventory())
  160.             {
  161.                 setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
  162.             }
  163.         }
  164.     }
  165.  
  166.     public void receiveButtonEvent (byte buttonId)
  167.     {
  168.         switch (buttonId)
  169.         {
  170.        
  171.         }
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement