Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.ISidedInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.world.World;
- public class TileValaniumChest extends TileEntity implements IInventory, ISidedInventory {
- public ItemStack[] content;
- public boolean openning;
- public boolean closing;
- public float prevLid;
- public float lid;
- public TileValaniumChest() {
- this.content = new ItemStack[112];
- this.openning = false;
- this.closing = false;
- }
- public int getSizeInventory() {
- return this.content.length;
- }
- public ItemStack getStackInSlot(int slot) {
- return this.content[slot];
- }
- public ItemStack decrStackSize(int slotIndex, int amount) {
- if (this.content[slotIndex] != null) {
- if (this.content[slotIndex].stackSize <= amount) {
- ItemStack itemstack = this.content[slotIndex];
- this.content[slotIndex] = null;
- markDirty();
- return itemstack;
- }
- ItemStack itemstack = this.content[slotIndex].splitStack(amount);
- if (this.content[slotIndex].stackSize == 0) {
- this.content[slotIndex] = null;
- }
- markDirty();
- return itemstack;
- }
- return null;
- }
- public ItemStack getStackInSlotOnClosing(int slotIndex) {
- if (this.content[slotIndex] != null) {
- ItemStack itemstack = this.content[slotIndex];
- this.content[slotIndex] = null;
- return itemstack;
- }
- return null;
- }
- public void setInventorySlotContents(int slotIndex, ItemStack stack) {
- this.content[slotIndex] = stack;
- if ((stack != null) && (stack.stackSize > getInventoryStackLimit())) {
- stack.stackSize = getInventoryStackLimit();
- }
- markDirty();
- }
- public String getInventoryName() {
- return "tile.ValaniumChest";
- }
- public boolean hasCustomInventoryName() {
- return false;
- }
- public int getInventoryStackLimit() {
- return 64;
- }
- public boolean isUseableByPlayer(EntityPlayer player) {
- return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this;
- }
- public void openInventory() {
- this.openning = true;
- }
- public void closeInventory() {
- this.closing = true;
- }
- public void writeToNBT(NBTTagCompound compound) {
- super.writeToNBT(compound);
- NBTTagList nbttaglist = new NBTTagList();
- for (int i = 0; i < this.content.length; i++) {
- if (this.content[i] != null) {
- NBTTagCompound nbttagcompound1 = new NBTTagCompound();
- nbttagcompound1.setByte("Slot", (byte) i);
- this.content[i].writeToNBT(nbttagcompound1);
- nbttaglist.appendTag(nbttagcompound1);
- }
- }
- compound.setTag("Items", nbttaglist);
- }
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- NBTTagList nbttaglist = compound.getTagList("Items", 10);
- this.content = new ItemStack[getSizeInventory()];
- for (int i = 0; i < nbttaglist.tagCount(); i++) {
- NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
- int j = nbttagcompound1.getByte("Slot") & 0xFF;
- if ((j >= 0) && (j < this.content.length)) {
- this.content[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
- }
- }
- }
- public int[] getAccessibleSlotsFromSide(int side) {
- int[] slots = new int[108];
- for (int i = 0; i < 108; i++) {
- slots[i] = i;
- }
- return slots;
- }
- public boolean canInsertItem(int side, ItemStack stack, int slot) {
- if (slot < 108) {
- return true;
- }
- return false;
- }
- public boolean canExtractItem(int side, ItemStack stack, int slot) {
- if (slot < 108) {
- return true;
- }
- return false;
- }
- @Override
- public boolean isItemValidForSlot(int slot, ItemStack item) {
- if (slot < 108) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement