Jump to content

[1.7.10] NBT.setFloat and NBT.getFloat not working


Recommended Posts

I am trying to save a float named "power":

public float power;

On WriteToNBT I use:


On ReadFromNBT I use:

          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?



Link to comment
Share on other sites

Here is the NBT Saving and Writing COde:


public void readFromNBT(NBTTagCompound 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);

public void writeToNBT(NBTTagCompound 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);
	nbt.setTag("Slots", list);

		nbt.setString("CustomName", this.getInventoryName());

Link to comment
Share on other sites



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:




Just a wild guess - try using lower case i.e. power instead of POWER



Link to comment
Share on other sites

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.