Jump to content

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


Alanzote

Recommended Posts

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.

Link to comment
Share on other sites

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());
	}
}

Link to comment
Share on other sites

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

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.

Guest
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.

Announcements



×
×
  • Create New...

Important Information

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