NBT Tags in Lore Description but for 1.18.2

Started by Ghoulander on

Topic category: Help with modding (Java Edition)

Last seen on 22:00, 20. Sep 2022
Joined Feb 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
NBT Tags in Lore Description but for 1.18.2

Trying to add NBT Tags to an items Lore Description area.

Found code that works for 1.16 but not for 1.18.2
 

        @Override
        public void addInformation(ItemStack itemstack, World world, List<ITextComponent> list, ITooltipFlag flag) {
            super.addInformation(itemstack, world, list, flag);
            String line1 = (String) ((itemstack).getOrCreateTag().getString("line1"));
            String line2 = (String) ((itemstack).getOrCreateTag().getString("line2"));
            list.add(new StringTextComponent((("\u00A75") + "" + (line1))));
            list.add(new StringTextComponent((("\u00A75") + "" + (line2))));
        }

Did some of this code change with the 1.18.2 update?

 

Last seen on 15:21, 16. Oct 2023
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Im pretty sure …
Tue, 09/20/2022 - 15:18

Im pretty sure "addInformation" method was replaced by "appendHoverText" in any of the versions 1.16.x (in 1.16.5 its appendHoverText).

 

Also in 1.17 changed class names:

  • ITextComponent to Component
  • IToolTipFlag to TooltipFlag
  • World to Level
  • StringTextComponent to TextComponent (TextComponent from older versions was renamed to BaseComponent). 
Last seen on 22:00, 20. Sep 2022
Joined Feb 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks Azzier. That did the…
Tue, 09/20/2022 - 21:54

Thanks Azzier.

That did the trick!

For anyone who would like to use NBT Variables in Lore Descriptions..for 1.17+...Here ya go!

@Override
        public void appendHoverText(ItemStack itemstack, Level level, List<Component> list, TooltipFlag flag) {
            super.appendHoverText(itemstack, level, list, flag);
            String line1 = (String) ((itemstack).getOrCreateTag().getString("line1"));
            String line2 = (String) ((itemstack).getOrCreateTag().getString("line2"));
            list.add(new TextComponent((("\u00A75") + "" + (line1))));
            list.add(new TextComponent((("\u00A75") + "" + (line2))));
        }