How to display a variable or NBT tag in an item's lore?

Started by KinoFire on

Topic category: Help with MCreator software

Last seen on 20:35, 31. Aug 2020
Joined May 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to display a variable or NBT tag in an item's lore?

 

I'm trying to make a book that stores XP, and I have an NBT number tag that holds the amount. How would I display that NBT tag in the lore of an item, in the box shown above? The NBT number tag is called "xp"

Last seen on 14:00, 14. Nov 2023
Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It requires code. I can do…
Sun, 08/16/2020 - 09:31

It requires code. I can do it for you I just need to know if your NBT tag is a number or an interger.

Last seen on 20:35, 31. Aug 2020
Joined May 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's a number. I appreciate…
Sun, 08/16/2020 - 12:01

It's a number. I appreciate it man, let me know what you can do

Last seen on 14:00, 14. Nov 2023
Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Step 1: when you create your…
Mon, 08/17/2020 - 11:13

Step 1: when you create your item, make sure you add anything as item information (on the first page) like this :
[image]

Step 2: Lock your item's element.

Step 3: Replace this code:

@Override
public void addInformation(ItemStack itemstack, World world, List<ITextComponent> list, ITooltipFlag flag) {
	super.addInformation(itemstack, world, list, flag);
	list.add(new StringTextComponent("anything"))
}

by this one:

@Override
public void addInformation(ItemStack itemstack, World world, List<ITextComponent> list, ITooltipFlag flag) {
	double XP = 0;
	super.addInformation(itemstack, world, list, flag);
	XP = (double) ((itemstack).getOrCreateTag().getDouble("xp"));
	list.add(new StringTextComponent((("\u00A77") + "" + ((xp)) + "" + (" XP"))));
}

Step 4: Close and save the code.

Step 5: Build.

Step 6: If any error appears, send me your entire code and the error message.

Last seen on 14:00, 14. Nov 2023
Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ooops sorry I forgot to link…
Mon, 08/17/2020 - 11:15

Ooops sorry I forgot to link the image of the first step... Here it is:

img

Last seen on 20:35, 31. Aug 2020
Joined May 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It works! It gave me an…
Mon, 08/17/2020 - 22:52

It works! It gave me an error but I just had to change the capitalized "XP" to "xp". Thanks so much!

Last seen on 02:16, 22. Aug 2023
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hey max you seem like a real…
Thu, 03/04/2021 - 02:15

hey max you seem like a real smart guy, and you helped this guy out.  so sir im begging you I've spent the last 7 hours trying to make getEfficiency equal to an itemstack nbt number. and I just cant figure it out

 

Last seen on 14:00, 14. Nov 2023
Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey SpiDro, what is …
Thu, 03/04/2021 - 07:38

Hey SpiDro, what is "getEfficiency"? A variable? Could you show me how you use it and what you've tried to do?

Last seen on 02:16, 22. Aug 2023
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
getEfficiency is a variable…
Thu, 03/04/2021 - 14:44

getEfficiency is a variable for mining speed of a tool, but I need the variable to be equal to a itemnbt integer.  I have no idea how to properly call for itemstacks though

package net.mcreator.customtools.item;

import net.minecraftforge.registries.ObjectHolder;

import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Item;
import net.minecraft.item.IItemTier;

import net.mcreator.customtools.CustomtoolsModElements;

@CustomtoolsModElements.ModElement.Tag
public class CtPickaxeItem extends CustomtoolsModElements.ModElement {
	@ObjectHolder("customtools:ct_pickaxe")
	public static final Item block = null;
	public CtPickaxeItem(CustomtoolsModElements instance) {
		super(instance, 2);
	}
	

	int variabletest = 5;
	@Override

	public void initElements() {
		elements.items.add(() -> new PickaxeItem(new IItemTier() {
			public int getMaxUses() {
				return 100;
			}

			public float getEfficiency() {
				return variabletest;
			}

			public float getAttackDamage() {
				return 2f;
			}

			public int getHarvestLevel() {
				return 1;
			}

			public int getEnchantability() {
				return 2;
			}

			public Ingredient getRepairMaterial() {
				return Ingredient.EMPTY;
			}
		}, 1, -3f, new Item.Properties().group(ItemGroup.TOOLS)) {
		}.setRegistryName("ct_pickaxe"));
	}
}

 

 

Last seen on 14:00, 14. Nov 2023
Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
SpiDro, do you have Discord?…
Fri, 03/05/2021 - 13:42

SpiDro, do you have Discord? It would be easier to talk there...

Last seen on 02:16, 22. Aug 2023
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yeah SpiDrone#6590  
Fri, 03/05/2021 - 22:14

yeah SpiDrone#6590

 

Last seen on 10:46, 22. Jun 2022
Joined Jul 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hey max can u teach me more…
Sat, 05/07/2022 - 00:25

hey max can u teach me more art that tysm I wanna know what is the ('\u00A7" is and xp is

Last seen on 15:36, 24. Mar 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
and max was never seen again…
Wed, 08/16/2023 - 18:03

and max was never seen again

 

Last seen on 21:21, 13. Mar 2024
Joined Dec 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I want NBT Number to be…
Mon, 09/18/2023 - 19:28

I want NBT Number to be displayed the same way, But for Quiver With Arrows

I want NBT Number to be displayed the same way, But for Quiver With Arrows