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

Any method where you have an ItemStack parameter, you can assign data to it/get data from it using stack.getTagCompound().

  • Author

That's rather convenient,

 

int length = stack.getTagCompound().getInteger("Length");

 

However, yields a null pointer exception.

 

I assume I would need to set the integer first, but where would I do that?

  • Author

Right, but where would I throw that?

 

Would I need to extend ItemStack and put it in the constructor?

ItemStack can't be extended, it is final. However, getting an integer shouldn't throw NPE as it will always either return a value if it has one or 0 if it does not. Look at the getInteger(String) method in NBTTagCompound and you'll see that it always returns something. The NPE is coming from one of two things (most likely the second) - The stack is null or it's tag compound is null. ItemStack tag compounds are protected against NPE, so first do this:

 

NBTTagCompound nbt = stack.getTagCompound();
	if(nbt == null)
	{
		nbt = new NBTTagCompound();
		stack.setTagCompound(nbt);
	}

 

A specific example of what you're trying to do with the NBT would be helpful, that way I can tell you where to set the int value for retrieval later.

  • Author
A specific example of what you're trying to do with the NBT would be helpful, that way I can tell you where to set the int value for retrieval later.

 

Not needed, your example works perfectly, thank you.

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.