Topic category: User side tutorials
I will explain how to give items hexadecimal colored names instead of Minecraft color codes, but first, some indications.
- This method only works with items and tools, not blocks.
- I tested it in NeoForge 1.21.1 with MCreator 2024.4.
- You will need to lock your item, so do this at the end of development. Otherwise, you won’t be able to make new procedures such as “When item in main hand tick” directly from the item editor without unlocking it.
It’s actually pretty simple. Lock the code and open the java of the item.
Let’s say I have an item named Test Item with this code:
package net.mcreator.blazeandglaze.item;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.Item;
public class TestItemItem extends Item {
public TestItemItem() {
super(new Item.Properties().stacksTo(64).rarity(Rarity.COMMON));
}
}
You’ll have to add 2 imports at the top:import net.minecraft.world.item.ItemStack;
import net.minecraft.network.chat.Component;
Then, before the last closing parenthesis, add this code:
@Override
public Component getName(ItemStack stack) {
return Component.empty()
.append(Component.literal("T").withColor(0xA16AE8)) // Deep Violet
.append(Component.literal("e").withColor(0xB478EB)) // Soft Purple
.append(Component.literal("s").withColor(0xC78EF0)) // Light Orchid
.append(Component.literal("t").withColor(0xDAA4F3)) // Pale Lilac
.append(Component.literal(" ").withColor(0xECD1FA)) // Blush Pink
.append(Component.literal("I").withColor(0xC3E3FB)) // Ice Blue
.append(Component.literal("t").withColor(0xA5D6F8)) // Soft Sky
.append(Component.literal("e").withColor(0x88C8F4)) // Cool Blue
.append(Component.literal("m").withColor(0x6ABAF1)); // Clear Blue
}
Important: don’t forget the semicolon at the end.
(You can remove the part after the //
, but it won’t be read anyway.)
In the end, your code should look something like this — the structure might vary slightly, but just remember to add the @Override
before the final }
.
You can change the colors and the name however you want. It’s not important what internal name the item has — I could’ve used “Jason” instead of “Test Item” and it would have worked anyway.
result: