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

Hi,

 

I'm wondering how to create NBT tags for Items in MC 1.8.9, so that every item got a different timer and all timers will be saved, so that after reloading the world, they are not resetted.

 

Thanks in advance.

Bektor

Developer of Primeval Forest.

  • Author

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.

  • Author

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.

  • Author

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.

  • Author

So, what else makes Minecraft so slow?

But Minecraft with OpenGL 3.3 would still be cool and would make it more cool, because I'm currently learning OpenGL 3.3 with GLSL 330.

Developer of Primeval Forest.

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.