You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.1 KiB
Java
101 lines
3.1 KiB
Java
package net.brokenmoon.afloydironchest.tileEntities;
|
|
|
|
import net.minecraft.src.*;
|
|
|
|
public class TileEntityGoldChest extends TileEntity implements IInventory {
|
|
private ItemStack[] contents = new ItemStack[81];
|
|
|
|
@Override
|
|
public int getSizeInventory() {
|
|
return 81;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStackInSlot(int i) {
|
|
return this.contents[i];
|
|
}
|
|
|
|
@Override
|
|
public ItemStack decrStackSize(int i, int j) {
|
|
if (this.contents[i] != null) {
|
|
ItemStack itemstack1;
|
|
if (this.contents[i].stackSize <= j) {
|
|
itemstack1 = this.contents[i];
|
|
this.contents[i] = null;
|
|
this.onInventoryChanged();
|
|
return itemstack1;
|
|
} else {
|
|
itemstack1 = this.contents[i].splitStack(j);
|
|
if (this.contents[i].stackSize == 0) {
|
|
this.contents[i] = null;
|
|
}
|
|
|
|
this.onInventoryChanged();
|
|
return itemstack1;
|
|
}
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setInventorySlotContents(int i, ItemStack itemStack) {
|
|
this.contents[i] = itemStack;
|
|
if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) {
|
|
itemStack.stackSize = this.getInventoryStackLimit();
|
|
}
|
|
|
|
this.onInventoryChanged();
|
|
}
|
|
|
|
@Override
|
|
public String getInvName() {
|
|
return "Gold Chest";
|
|
}
|
|
|
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
|
super.readFromNBT(nbttagcompound);
|
|
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
|
|
this.contents = new ItemStack[this.getSizeInventory()];
|
|
|
|
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
|
|
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
|
|
int j = nbttagcompound1.getByte("Slot") & 255;
|
|
if (j >= 0 && j < this.contents.length) {
|
|
this.contents[j] = new ItemStack(nbttagcompound1);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
|
super.writeToNBT(nbttagcompound);
|
|
NBTTagList nbttaglist = new NBTTagList();
|
|
|
|
for(int i = 0; i < this.contents.length; ++i) {
|
|
if (this.contents[i] != null) {
|
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
|
nbttagcompound1.setByte("Slot", (byte)i);
|
|
this.contents[i].writeToNBT(nbttagcompound1);
|
|
nbttaglist.setTag(nbttagcompound1);
|
|
}
|
|
}
|
|
|
|
nbttagcompound.setTag("Items", nbttaglist);
|
|
}
|
|
|
|
@Override
|
|
public int getInventoryStackLimit() {
|
|
return 64;
|
|
}
|
|
|
|
@Override
|
|
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
|
if (this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this) {
|
|
return false;
|
|
} else {
|
|
return entityPlayer.getDistanceSq((double)this.xCoord + 0.5, (double)this.yCoord + 0.5, (double)this.zCoord + 0.5) <= 64.0;
|
|
}
|
|
}
|
|
}
|