Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package RUMatter.tileEntities;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.tileentity.TileEntity;
- public class TileEntityRUChest extends TileEntity implements IInventory {
- private ItemStack[] inv;
- public TileEntityRUChest() {
- inv = new ItemStack[9];
- }
- @Override
- public int getSizeInventory() {
- return inv.length;
- }
- @Override
- public ItemStack getStackInSlot(int slot) {
- return inv[slot];
- }
- @Override
- public void setInventorySlotContents(int slot, ItemStack stack) {
- inv[slot] = stack;
- if (stack != null && stack.stackSize > getInventoryStackLimit()) {
- stack.stackSize = getInventoryStackLimit();
- }
- }
- @Override
- public ItemStack decrStackSize(int slot, int amt) {
- ItemStack stack = getStackInSlot(slot);
- if (stack != null) {
- if (stack.stackSize <= amt)
- setInventorySlotContents(slot, null);
- else {
- stack = stack.splitStack(amt);
- if (stack.stackSize == 0) setInventorySlotContents(slot, null);
- }
- }
- return stack;
- }
- @Override
- public ItemStack getStackInSlotOnClosing(int slot) {
- ItemStack stack = getStackInSlot(slot);
- if (stack != null) setInventorySlotContents(slot, null);
- return stack;
- }
- @Override
- public int getInventoryStackLimit() {
- return 64;
- }
- @Override
- public boolean isUseableByPlayer(EntityPlayer player) {
- return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
- }
- @Override
- public void openChest() {
- // TODO Auto-generated method stub
- }
- @Override
- public void closeChest() {
- // TODO Auto-generated method stub
- }
- @Override
- public void readFromNBT(NBTTagCompound tagCompound) {
- super.readFromNBT(tagCompound);
- NBTTagList tagList = tagCompound.getTagList("Inventory");
- for (int i = 0; i < tagList.tagCount(); i++) {
- NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
- byte slot = tag.getByte("Slot");
- if (slot >= 0 && slot < inv.length) {
- inv[slot] = ItemStack.loadItemStackFromNBT(tag);
- }
- }
- }
- @Override
- public void writeToNBT(NBTTagCompound tagCompound) {
- super.writeToNBT(tagCompound);
- NBTTagList itemList = new NBTTagList();
- for (int i = 0; i < inv.length; i++) {
- ItemStack stack = inv[i];
- if (stack != null) {
- NBTTagCompound tag = new NBTTagCompound();
- tag.setByte("Slot", (byte) i);
- stack.writeToNBT(tag);
- itemList.appendTag(tag);
- }
- }
- tagCompound.setTag("Inventory", itemList);
- }
- @Override
- public String getInvName() {
- return "RUChest";
- }
- @Override
- public boolean isInvNameLocalized() {
- return this.getInvName().length() > 0;
- }
- @Override
- public boolean isItemValidForSlot(int slot, ItemStack stack) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement