Jump to content

NBT not saving after a ItemPickupEvent


quinn50

Recommended Posts


    @SubscribeEvent
    public void itemPickup(PlayerEvent.ItemPickupEvent event){
        
        ItemStack stack = event.getStack();
        if (stack.getItem().equals(ModItems.mobSoul)) {
            System.out.println("You picked up Mob Soul");

            NBTTagCompound nbt = stack.getTagCompound();
            if (nbt == null) {
                nbt = new NBTTagCompound();
                System.out.println("NBT Created for Mob Soul");
            }
            if (nbt.hasKey("potency")) {
                nbt.setInteger("potency", nbt.getInteger("potency"));
            } else {
                System.out.println("Random Value generated for Potency value");
                nbt.setInteger("potency", (int) (Math.random() * 100) + 1);
            }
            System.out.println("Value written to NBT tag");
            stack.setTagCompound(nbt);
        }

        
    }

This is my Event code, so what I want to do is when I pick up my custom item from a mob drop, it will generate a random number to be put inside of a tooltip showing how much "potency" the item has.

 

    @SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
        if (stack.hasTagCompound() && stack.getTagCompound().hasKey("potency")) {
            NBTTagCompound nbt = stack.getTagCompound();
            System.out.println(nbt);
            if (nbt != null && nbt.hasKey("potency")) {
                int pot = nbt.getInteger("potency");
                tooltip.add("Potency: " + pot);
            }

        } else {
            tooltip.add("Potency: N/A");

        }
    }

this is my tooltip code, I've tried all of the troubleshooting that I know of, such as just using a onRightClick method using the same general code in the ItemPickupEvent, which worked fine however my issue strides from the event.

 

I want to know if I am doing something generally wrong, as in 1.10 this same method worked for me previously.

Edited by quinn50
Link to comment
Share on other sites

have you tried looking at the values in the debugger? your tooltip code may not be picking up the values

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

49 minutes ago, Cadiboo said:

have you tried looking at the values in the debugger? your tooltip code may not be picking up the values

yes, I have but that is the issue for me it's not grabbing the NBT tag, but other options it does idk what is going on

Edited by quinn50
Link to comment
Share on other sites

11 hours ago, diesieben07 said:

That event cannot be used to modify the item being picked up. Why do you not create the item entity containing the necessary NBT data in the first place? Where is this dropped item coming from?

Sorry for late reply, I implemented this solution thanks for the help.

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.