Write some entity NBT into an item lore

Started by Suzu on

Topic category: Help with modding (Java Edition)

Last seen on 14:22, 4. Oct 2023
Joined Aug 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Write some entity NBT into an item lore

Hello, I'm making a mod that you can storage your XP levels and you can watch your XP levels in the book.

This is the first item, the basic book:

	@Override
	public void appendHoverText(ItemStack itemstack, Level world, List<Component> list, TooltipFlag flag) {
		int xp = 0;
		super.appendHoverText(itemstack, world, list, flag);
		xp = (int) ((itemstack).getOrCreateTag().getDouble("xp"));
		list.add(new TextComponent((("\u00A77") + "" + ((xp)) + "" + ("/10 XP"))));
	}

This is the problem, I want to make the same lore but similar to an enderchest, so instead of using an item NBT I need an entity NBT (I guess), this is all I could found by myself:

	@Override
	public void appendHoverText(ItemStack itemstack, Level world, List<Component> list, TooltipFlag flag) {
		int xp_ender = 0;
		super.appendHoverText(itemstack, world, list, flag);
		xp_ender = (int) ((entity).getPersistentData().getDouble("xp_ender"));
		list.add(new TextComponent((("\u00A77") + "" + ((xp_ender)) + "" + ("/30 XP"))));
	}

I'm very noob with Java so I don't really understand coding, any idea about what is wrong?

Last seen on 09:15, 1. Aug 2024
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I have the same problem get…
Mon, 05/09/2022 - 09:57

I have the same problem get me up on discord perhaps we can figure out stuff together.
Here is my ID: Nosferatu#3742