Jump to content

Recommended Posts

Posted (edited)

How would I go about adding lore to an ItemStack?

Here is my current code:

CompoundNBT nbt = item.getTag();
CompoundNBT display;
ListNBT lore;
if (nbt.get("display") != null) {
    display = (CompoundNBT) nbt.get("display");
    if (display.get("Lore") != null) {
        lore = (ListNBT) display.get("Lore");
    } else {
        lore = new ListNBT();
    }
} else {
    lore = new ListNBT();
    display = new CompoundNBT();
}
CompoundNBT tagRawJson = new CompoundNBT();
tagRawJson.putString("tag", "{'text': '[tag]', 'italic': false, 'color': 'white'}".replace("[tag]", tag));
lore.add(tagRawJson.get("tag"));
display.put("Lore", lore);
nbt.put("display", display);
item.setTag(nbt);

I would like to add the contents of the String variable named tag to the lore.

Edited by DoctorC
Posted
19 minutes ago, ChampionAsh5357 said:

Item#addInformation if you own the item or RenderTooltipEvent if its not. I'm assuming that this is present on the ItemStack itself.

I want to add it on the Itemstack, not the item (I've tried Item.addInformation), but I'll look into RenderTooltipEvent.

Thanks!

Posted (edited)
25 minutes ago, DoctorC said:

I want to add it on the Itemstack, not the item (I've tried Item.addInformation), but I'll look into RenderTooltipEvent.

Thanks!

ItemStacks are Stacks of an Item.

addInformation in the ItemClass is passed the relevant ItemStack for you to make any determinations based on other data. But only works for your own items.

RenderTooltipEvent would be if you need to add information to an Item you don't control (and gets the same parameters addInformation does).

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
33 minutes ago, Draco18s said:

addInformation in the ItemClass is passed the relevant ItemStack for you to make any determinations based on other data. But only works for your own items.

I'm using GuiScreenEvent.KeyboardKeyPressedEvent to get a keybind being pressed, and then change the item under cursor, so I don't think Item#addInformation would work (well I can't get it to at least).

Edited by DoctorC
Posted
12 minutes ago, poopoodice said:

It gives you the coordinate.... you need to render the extra information yourself.

Yes, but how.

As in, I have a FontRenderer and I can render in a string, but it doesn't add lore, rather it adds text rendered underneath the item.

I don't have any experience rendering things in Forge, which is why I am asking.

Posted
2 minutes ago, poopoodice said:

If you just want to add some simple text to the item use ItemTooltipEvent.

There don't seem to be any functions to change the tooltip.

Posted
4 minutes ago, poopoodice said:

There's a list of tooltips provided, you can do whatever you want to it (remove them all, add your custom ones, or even flip them all around...).

Thanks!
I didn't realise that adding to the list would update it in-game without having to set it.

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.