Jump to content

[1.6.1] Alternative to TileEntity for Items?


gigimoi

Recommended Posts

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.

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.