Posted February 14, 201510 yr I am trying to save a float named "power": public float power; On WriteToNBT I use: super.writeToNBT(nbt) nbt.setFloat("POWER",power); On ReadFromNBT I use: super.readFromNBT(nbt) power = nbt.getInteger("POWER"); Using the Code: if(ItemStack.areItemStacksEqual(slots[0], new ItemStack(//Some Item here))) I check for an Item in Slot 0, and then I add the power. After world reloads the nbt looses the "POWER" float and every power that has been stored is deleted. Any Ideas? Thanks.
February 14, 201510 yr nbt.setFloat("POWER",power); nbt.getInteger("POWER"); Float != Integer Uhm? 1.7.10 is no longer supported by forge, you are on your own.
February 14, 201510 yr Well, your problem is most likely elsewhere, we're gonna need your code. 1.7.10 is no longer supported by forge, you are on your own.
February 14, 201510 yr Author Here is the NBT Saving and Writing COde: @Override public void readFromNBT(NBTTagCompound nbt){ super.readFromNBT(nbt); facingDirection = nbt.getInteger("facingDirection"); NBTTagList list = nbt.getTagList("Slots", 10); power = nbt.getFloat("POWER"); this.slots = new ItemStack[getSizeInventory()]; for(int i = 0; i < list.tagCount(); i++){ NBTTagCompound item = list.getCompoundTagAt(i); byte b = item.getByte("Item"); if(b >= 0 && b < this.slots.length){ this.slots[b] = ItemStack.loadItemStackFromNBT(item); } } if(nbt.hasKey("CustomName")){ this.setInventoryName(nbt.getString("CustomName")); } } @Override public void writeToNBT(NBTTagCompound nbt){ super.writeToNBT(nbt); nbt.setFloat("POWER", power); nbt.setInteger("facingDirection", facingDirection); NBTTagList list = new NBTTagList(); for(int i = 0; i < this.slots.length; i++) { if(this.slots[i] != null){ NBTTagCompound item = new NBTTagCompound(); item.setByte("item", (byte)i); this.slots[i].writeToNBT(item); list.appendTag(item); } } nbt.setTag("Slots", list); if(this.hasCustomInventoryName()){ nbt.setString("CustomName", this.getInventoryName()); } }
February 14, 201510 yr Hi I'm not seeing an obvious problem. You could use this tool to help troubleshoot: NBTexplorer is a very useful tool to examine the structure of your NBT saved data and make sure it's correct: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1262665-nbtexplorer-nbt-editor-for-windows-and-mac Just a wild guess - try using lower case i.e. power instead of POWER -TGG
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.