Jump to content

Recommended Posts

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

 

Posted

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

Posted

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...

×   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.