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.

Featured Replies

Posted

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

  • Author
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!

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.

  • Author
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

  • Author
2 hours ago, ChampionAsh5357 said:

RenderTooltipEvent

Okay, how do I change the tooltip rendered?

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

Edited by poopoodice

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

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

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

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

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.