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

Here's a few problems I've ran into.

1. I have a piece of code which checks if a stack has a specific key every tick. However, the NBTTagCompoud#hasKey method seems to be functioning incorrectly. I've debugged it and it looks like it always returns false.

 

public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
{
	if(!world.isRemote)
	{
		NBTTagCompound nbt = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();	
		System.out.println(nbt.getUniqueId("Identifier"));
		if(!nbt.hasKey("Identifier"))
		{
			nbt.setUniqueId("Identifier", UUID.randomUUID());
			stack.setTagCompound(nbt);
		}
	}
} 

 

2. From what I've heard NBT is handled on the server side only. How would I add a string from an item's NBT to its lore? Trying to retrieve tags on the client side in Item#addInformation always returns null.

3. In what case would I want to use capabilities instead of item NBT?

Edited by Melonslise

8 hours ago, Melonslise said:

1. I have a piece of code which checks if a stack has a specific key every tick. However, the NBTTagCompoud#hasKey method seems to be functioning incorrectly. I've debugged it and it looks like it always returns false.

 

If you look at the implementation of NBTTagCompound#setUniqueId, you'll see that it doesn't use the key you give it directly; it uses two different keys based on it. This means that NBTTagCompound#hasKey will never return true for the key you passed to NBTTagCompound#setUniqueId, you need to use NBTTagCompound#hasUniqueId instead.

 

 

8 hours ago, Melonslise said:

2. From what I've heard NBT is handled on the server side only. How would I add a string from an item's NBT to its lore? Trying to retrieve tags on the client side in Item#addInformation always returns null.

 

ItemStack NBT is automatically synced to the client. If you're setting on the server but can't access it from Item#addInformation, you're doing something wrong. Post your code.

 

 

8 hours ago, Melonslise said:

3. In what case would I want to use capabilities instead of item NBT?

 

To create your own API or implement an existing one like IItemHandler/IFluidHandler; or to store data without having to serialise it to/deserialise it from NBT every time you want to access/modify it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Thanks a lot! For some reason I automatically thought a UUID would be stored just like any other data type. Thanks for clearing things up, everything works now.

Edited by Melonslise

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.