camerpon900 Posted December 10, 2015 Share Posted December 10, 2015 Hi when i cant insert a item into my top slot however i can in my bottom slot but when i do that it appears in my top slot and bottom and if i extract the item from the top it duplicates the item TileEntity package com.camerpon900.realauto2.blocks.TileEntities; import com.camerpon900.realauto2.blocks.Blocks; import com.camerpon900.realauto2.utils.WorldHelper; import net.minecraft.entity.player.EntityPlayer; 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; import net.minecraft.world.biome.BiomeGenDesert; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityEnergyCube extends TileEntity implements ISidedInventory { private ItemStack[] slots = new ItemStack[2]; public int power = 0; private int maxPower = 5000000; public void updateEntity() { System.out.println("Slots: " + this.slots.length); } public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); System.out.println("slots " + this.slots); System.out.println("reading nbt"); NBTTagList list = nbt.getTagList("Slots", 10); NBTTagList powerList = nbt.getTagList("Power",power); this.slots = new ItemStack[getSizeInventory()]; for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound item = list.getCompoundTagAt(i); NBTTagCompound power = list.getCompoundTagAt(i); byte b = item.getByte("Item"); int p = item.getInteger("Power"); if (b >= 0 && b < this.slots.length) { this.slots = ItemStack.loadItemStackFromNBT(item); } if(p >= 0 && p < this.maxPower) { this.power = power.getInteger("Power"); } } } public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); System.out.println("Writing To NBT at x: " + xCoord + " y: " + yCoord + " z: " + zCoord); NBTTagList list = new NBTTagList(); for(int i = 0; i < slots.length; i++) { if(this.slots != null) { NBTTagCompound item = new NBTTagCompound(); item.setByte("Item", (byte)i); this.slots.writeToNBT(item); list.appendTag(item); } } if(power >= 1) { NBTTagCompound power = new NBTTagCompound(); power.setInteger("Power", this.power); list.appendTag(power); } nbt.setTag("Power", list); nbt.setTag("Slots", list); } public int getSizeInventory() { return this.slots.length; } public int[] getAccessibleSlotsFromSide(int p_94128_1_) { return new int[0]; } public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) { return this.isItemValidForSlot(p_102007_1_,p_102007_2_); } public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) { return true; } public ItemStack getStackInSlot(int i) { if(i <= 2) { return this.slots[1]; } return this.slots; } public ItemStack decrStackSize(int i, int j) { if(this.slots != null) { System.out.println(this.slots); ItemStack itemStack; if(this.slots.stackSize <= j) { itemStack = this.slots; this.slots = null; return itemStack; } else { itemStack = this.slots.splitStack(j); if(this.slots.stackSize == 0) { this.slots = null; } } return itemStack; } return null; } public ItemStack getStackInSlotOnClosing(int p_70304_1_) { return null; } public void setInventorySlotContents(int i, ItemStack itemStack) { this.slots = itemStack; if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { itemStack.stackSize = this.getInventoryStackLimit(); } } public String getInventoryName() { return null; } public boolean hasCustomInventoryName() { return false; } public int getInventoryStackLimit() { return 64; } public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { return true; } public void openInventory() { } public void closeInventory() { } public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { return true; } } Container package com.camerpon900.realauto2.container; import com.camerpon900.realauto2.blocks.TileEntities.TileEntityCompressor; import com.camerpon900.realauto2.blocks.TileEntities.TileEntityEnergyCube; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; public class ContainerEnergyCube extends Container { private TileEntityEnergyCube energyCube; public static final int INPUT = 0, OUTPUT = 1; public ContainerEnergyCube(InventoryPlayer invPlayer, TileEntityEnergyCube tileEntity) { this.energyCube = tileEntity; //0 = Input, 2 = Output this.addSlotToContainer(new Slot(energyCube, INPUT, 56, 23)); this.addSlotToContainer(new Slot(energyCube, OUTPUT, 56, 53)); for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(invPlayer,9+j+i*9,8+18*j,84+i*18)); } } for(int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(invPlayer,i,8 + i*18,142)); } } public boolean canInteractWith(EntityPlayer p_75145_1_) { return true; } } Quote Link to comment Share on other sites More sharing options...
camerpon900 Posted December 10, 2015 Author Share Posted December 10, 2015 Ok thanks i posted it on pastebin here are the links: Container - http://pastebin.com/vgtHMEuM TileEntity - http://pastebin.com/pdkGYfqp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.