Advertisement
Guest User

TileValaniumChest

a guest
Sep 23rd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.83 KB | None | 0 0
  1. import net.minecraft.entity.player.EntityPlayer;
  2. import net.minecraft.inventory.IInventory;
  3. import net.minecraft.inventory.ISidedInventory;
  4. import net.minecraft.item.ItemStack;
  5. import net.minecraft.nbt.NBTTagCompound;
  6. import net.minecraft.nbt.NBTTagList;
  7. import net.minecraft.tileentity.TileEntity;
  8. import net.minecraft.world.World;
  9.  
  10. public class TileValaniumChest extends TileEntity implements IInventory, ISidedInventory {
  11.     public ItemStack[] content;
  12.     public boolean openning;
  13.     public boolean closing;
  14.     public float prevLid;
  15.     public float lid;
  16.  
  17.     public TileValaniumChest() {
  18.         this.content = new ItemStack[112];
  19.  
  20.         this.openning = false;
  21.         this.closing = false;
  22.     }
  23.  
  24.     public int getSizeInventory() {
  25.         return this.content.length;
  26.     }
  27.  
  28.     public ItemStack getStackInSlot(int slot) {
  29.         return this.content[slot];
  30.     }
  31.  
  32.     public ItemStack decrStackSize(int slotIndex, int amount) {
  33.         if (this.content[slotIndex] != null) {
  34.             if (this.content[slotIndex].stackSize <= amount) {
  35.                 ItemStack itemstack = this.content[slotIndex];
  36.  
  37.                 this.content[slotIndex] = null;
  38.                 markDirty();
  39.  
  40.                 return itemstack;
  41.             }
  42.             ItemStack itemstack = this.content[slotIndex].splitStack(amount);
  43.             if (this.content[slotIndex].stackSize == 0) {
  44.                 this.content[slotIndex] = null;
  45.             }
  46.             markDirty();
  47.             return itemstack;
  48.         }
  49.         return null;
  50.     }
  51.  
  52.     public ItemStack getStackInSlotOnClosing(int slotIndex) {
  53.         if (this.content[slotIndex] != null) {
  54.             ItemStack itemstack = this.content[slotIndex];
  55.             this.content[slotIndex] = null;
  56.  
  57.             return itemstack;
  58.         }
  59.         return null;
  60.     }
  61.  
  62.     public void setInventorySlotContents(int slotIndex, ItemStack stack) {
  63.         this.content[slotIndex] = stack;
  64.         if ((stack != null) && (stack.stackSize > getInventoryStackLimit())) {
  65.             stack.stackSize = getInventoryStackLimit();
  66.         }
  67.         markDirty();
  68.     }
  69.  
  70.     public String getInventoryName() {
  71.         return "tile.ValaniumChest";
  72.     }
  73.  
  74.     public boolean hasCustomInventoryName() {
  75.         return false;
  76.     }
  77.  
  78.     public int getInventoryStackLimit() {
  79.         return 64;
  80.     }
  81.  
  82.     public boolean isUseableByPlayer(EntityPlayer player) {
  83.         return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this;
  84.     }
  85.  
  86.     public void openInventory() {
  87.         this.openning = true;
  88.     }
  89.  
  90.     public void closeInventory() {
  91.         this.closing = true;
  92.     }
  93.  
  94.     public void writeToNBT(NBTTagCompound compound) {
  95.         super.writeToNBT(compound);
  96.         NBTTagList nbttaglist = new NBTTagList();
  97.         for (int i = 0; i < this.content.length; i++) {
  98.             if (this.content[i] != null) {
  99.                 NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  100.                 nbttagcompound1.setByte("Slot", (byte) i);
  101.                 this.content[i].writeToNBT(nbttagcompound1);
  102.                 nbttaglist.appendTag(nbttagcompound1);
  103.             }
  104.         }
  105.         compound.setTag("Items", nbttaglist);
  106.     }
  107.  
  108.     public void readFromNBT(NBTTagCompound compound) {
  109.         super.readFromNBT(compound);
  110.  
  111.         NBTTagList nbttaglist = compound.getTagList("Items", 10);
  112.         this.content = new ItemStack[getSizeInventory()];
  113.         for (int i = 0; i < nbttaglist.tagCount(); i++) {
  114.             NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
  115.             int j = nbttagcompound1.getByte("Slot") & 0xFF;
  116.             if ((j >= 0) && (j < this.content.length)) {
  117.                 this.content[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
  118.             }
  119.         }
  120.     }
  121.  
  122.     public int[] getAccessibleSlotsFromSide(int side) {
  123.         int[] slots = new int[108];
  124.         for (int i = 0; i < 108; i++) {
  125.             slots[i] = i;
  126.         }
  127.         return slots;
  128.     }
  129.  
  130.     public boolean canInsertItem(int side, ItemStack stack, int slot) {
  131.         if (slot < 108) {
  132.             return true;
  133.         }
  134.         return false;
  135.     }
  136.  
  137.     public boolean canExtractItem(int side, ItemStack stack, int slot) {
  138.         if (slot < 108) {
  139.             return true;
  140.         }
  141.         return false;
  142.     }
  143.  
  144.     @Override
  145.     public boolean isItemValidForSlot(int slot, ItemStack item) {
  146.         if (slot < 108) {
  147.               return true;
  148.             }
  149.         return false;
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement