Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TileEntityEmpty extends TileEntityMageTech implements ISidedInventory
- {
- public static final int INVENTORY_SIZE = 2;
- private static final int[] slotsTop = new int[] {0};
- private static final int[] slotsBottom = new int[] {1};
- private static final int[] slotsSides = new int[] {0, 1};
- private ItemStack[] inventory;
- public TileEntityEmpty ()
- {
- inventory = new ItemStack[INVENTORY_SIZE];
- }
- @Override
- public int getSizeInventory()
- {
- return inventory.length;
- }
- @Override
- public ItemStack getStackInSlot(int slotIndex)
- {
- return inventory[slotIndex];
- }
- @Override
- public ItemStack decrStackSize(int slotIndex, int decrementAmount)
- {
- ItemStack itemStack = getStackInSlot(slotIndex);
- if (itemStack != null)
- {
- if (itemStack.stackSize <= decrementAmount)
- setInventorySlotContents(slotIndex, null);
- else
- {
- itemStack = itemStack.splitStack(decrementAmount);
- if (itemStack.stackSize == 0)
- setInventorySlotContents(slotIndex, null);
- }
- }
- return itemStack;
- }
- @Override
- public ItemStack getStackInSlotOnClosing(int slotIndex)
- {
- ItemStack itemStack = getStackInSlot(slotIndex);
- if (itemStack != null)
- setInventorySlotContents(slotIndex, null);
- return itemStack;
- }
- @Override
- public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
- {
- inventory[slotIndex] = itemStack;
- if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
- itemStack.stackSize = getInventoryStackLimit();
- }
- @Override
- public String getInventoryName()
- {
- return this.hasCustomName() ? this.getCustomName() : Names.Containers.CONTAINERNAME;
- }
- @Override
- public boolean hasCustomInventoryName()
- {
- return this.hasCustomName();
- }
- @Override
- public int getInventoryStackLimit()
- {
- return 64;
- }
- @Override
- public boolean isUseableByPlayer(EntityPlayer entityplayer)
- {
- return true;
- }
- @Override
- public void openInventory() { }
- @Override
- public void closeInventory() { }
- @Override
- public void writeToNBT(NBTTagCompound nbtTagCompound)
- {
- super.writeToNBT(nbtTagCompound);
- // Write the ItemStacks in the inventory to NBT
- NBTTagList tagList = new NBTTagList();
- for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex)
- {
- if (inventory[currentIndex] != null)
- {
- NBTTagCompound tagCompound = new NBTTagCompound();
- tagCompound.setByte("Slot", (byte) currentIndex);
- inventory[currentIndex].writeToNBT(tagCompound);
- tagList.appendTag(tagCompound);
- }
- }
- nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
- }
- @Override
- public void readFromNBT(NBTTagCompound nbtTagCompound)
- {
- super.readFromNBT(nbtTagCompound);
- // Read in the ItemStacks in the inventory from NBT
- NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
- inventory = new ItemStack[this.getSizeInventory()];
- for (int i = 0; i < tagList.tagCount(); ++i)
- {
- NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
- byte slotIndex = tagCompound.getByte("Slot");
- if (slotIndex >= 0 && slotIndex < inventory.length)
- {
- inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
- }
- }
- }
- @Override
- public void updateEntity() { }
- public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
- {
- return slotIndex != 1;
- }
- public int[] getAccessibleSlotsFromSide(int side)
- {
- return side == 0 ? slotsBottom : (side == 1 ? slotsTop : slotsSides);
- }
- public boolean canInsertItem(int slot, ItemStack itemStack, int side)
- {
- return this.isItemValidForSlot(side, itemStack);
- }
- public boolean canExtractItem(int slot, ItemStack itemStack, int side)
- {
- return !(side != 0 && side != 1) || (slot != 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement