Jump to content

[SOLVED][1.8.9] Item NBT tags


Bektor

Recommended Posts

Ok, I did it now this way:

 

	public int tickExist = -1;

@Override
public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) {
	stack.getSubCompound(Constants.MOD_ID, true);

	if(stack.getTagCompound() != null && stack.getTagCompound().getInteger("timer") == -1)
	       stack.getTagCompound().setInteger("timer", tickExist);
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
	if(stack.getTagCompound() != null) {
		this.tickExist = stack.getTagCompound().getInteger("timer");
	}
	tooltip.add(EnumChatFormatting.DARK_AQUA + "" + (15 - TimeUtil.ticksToSeconds(tickExist) < 0 ? "0" : 15 - TimeUtil.ticksToSeconds(tickExist) + " seconds left"));
}

In the update method, the

tickExist

are going to be updated.

So, is it correct that I'm using

stack.getTagCompound().getInteger("timer");

 

Oh and now all items got the same value. So, what is wrong?

Developer of Primeval Forest.

Link to comment
Share on other sites

So I should do it that way:

stack.getSubCompound(Constants.MOD_ID, true).getInteger("timer")

And set it the same way? Correct?

 

And does I need to have a check in the addInformation to see if the NBTTagCompound is null or not?

And when will the onCreated method called? Only when the item gets created or when the object gets re-created (like after the Game was restarted)?

(just want to know, because I want to know if I have to check if the NBT Tag I want to set already exists or if I just can create it because it will never override an existing one, because it will never be called when the Game was loaded and the item already exists in the world which was loaded)

 

EDIT:

oh and how much performance does

stack.getSubCompound(Constants.MOD_ID, true).getInteger("timer")

cost? Because I'm wondering if its a good idea to use it in the update method, too, to set and get the "timer" variable. (use it here multiply times per update)

Developer of Primeval Forest.

Link to comment
Share on other sites

Ok, thx. Now its working perfectly. And yeah, MC has such a performance, there are such things really negligible. xD

(I'm wondering how the performance would be when MC would use OpenGL 3.3, Java 8 and would be optimised on performance and speed (same graphics), I think it would run faster)

Developer of Primeval Forest.

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.