Write some entity NBT into an item lore

Started by Suzu on

Topic category: Help with Minecraft modding (Java Edition)

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?

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