Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

nbt.setFloat("POWER",power);
nbt.getInteger("POWER");

 

Float != Integer

 

Uhm?

1.7.10 is no longer supported by forge, you are on your own.

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.

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

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.