Posted August 2, 20169 yr 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
August 2, 20169 yr Are you crafting it or spawning it in? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr 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
August 2, 20169 yr You mean you moved the stuff in your onCreated to onUpdate? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr 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
August 2, 20169 yr Yup that is the way to do it :3 have fun modding. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
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.