Posted May 18, 201411 yr I cant seem to get my TileEntity to save its NBT, ive looked at updated 1.7.2 tutorials on saving NBT and it just wont work. Here is my code: public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < slots.length) { slots[slot] = ItemStack.loadItemStackFromNBT(tag); } } } public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < slots.length; i++) { ItemStack stack = slots[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } par1NBTTagCompound.setTag("Inventory", itemList); } Slots is indeed the itemstack array used by the container/gui. I'll give any more code if needed.
May 18, 201411 yr Author After trial and error, I came to the conclusion that writeNBT/getDescriptionPacket is called but onDataPacket/readFromNBT is not. Any ideas?
May 18, 201411 yr I don't see any constructors, but... When the game reloads it will call a constructor with no arguments and then call "readFromNBT(...)". If there is no empty constructor available it will give up. When this is the problem Eclipse throws a bunch of red text at me upon attempts to load the world. Pay attention to the red text.
May 18, 201411 yr Author When this is the problem Eclipse throws a bunch of red text at me upon attempts to load the world. Pay attention to the red text. Thanks, Ive been doing this for a long time so I am looking over exceptions since vanilla minecraft makes so many. Thanks again!
May 19, 201411 yr Are you just trying to get it to save the nbt data? world.markBlockForUpdate(x,y,z); Long time Bukkit & Forge Programmer Happy to try and help
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.