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.

[Solved] [1.10.2] Item NBT issues

Featured Replies

Posted

Having a problem with item nbt. i setup the item with onCreated, then when i go to get something from the nbt with onItemRightClick it null points

 

any ideas?

 

Crash at item.getTagCompound().getInteger("power") <= 1900;

 

public void onCreated(ItemStack item, World worldIn, EntityPlayer playerIn)
    {
	    item.setTagCompound(new NBTTagCompound());
	    this.setDamage(item, 2000);
	    item.getTagCompound().setInteger("power", 2000);
	    item.getTagCompound().setBoolean("active", false);
    }

 

public ActionResult<ItemStack> onItemRightClick(ItemStack item, World world, EntityPlayer player, EnumHand hand)
{

	if (item.getTagCompound().getInteger("power") <= 1900 && !item.getTagCompound().getBoolean("active")) {


		item.getTagCompound().setBoolean("active", false);
		this.setDamage(item, (int) (this.getDamage(item) +(100)));
		item.getTagCompound().setShort("power", (short) this.getDamage(item));
		player.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, 100));
		return new ActionResult(EnumActionResult.SUCCESS, item);
	} else if (!item.getTagCompound().getBoolean("active")) {
		item.getTagCompound().setBoolean("active", false);
		player.removePotionEffect(MobEffects.NIGHT_VISION);
		return new ActionResult(EnumActionResult.SUCCESS, item);
	}
	return new ActionResult(EnumActionResult.FAIL, item);
}

 

https://github.com/Zerahi/RavenousVoid/blob/master/src/main/java/com/ravvoid/items/AwakenedVoidOrb.java

 

  • Author

just staring at the same code too long, that makes sense added a !item.hasTagCompound() check to the update tick and did the setup in their works great now

  • Author

yeah but it will only fire once cause any item of that type that doesn't have a tag will get one on the first tick public void onUpdate(ItemStack item, World

 

world, Entity player, int itemSlot, boolean isSelected) {
	if (!item.hasTagCompound()) {
		item.setTagCompound(new NBTTagCompound());
		    this.setDamage(item, 2000);
		    item.getTagCompound().setInteger("power", 2000);
		    item.getTagCompound().setBoolean("active", false);
	}

 

and i use on update for other things so not like its not ticking anway

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.