Colored item names

Started by xanadian on

Topic category: Advanced modding

Last seen on 13:41, 13. Mar 2021
Joined Jun 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Colored item names

I'm trying to get the item names to show up in color.  Ideally, I'd like to get *tools* (swords/shovels/etc) and maybe other things to have custom colored names, but I'm starting "simple."  I've read the advice in these threads (https://mcreator.net/comment/41846#comment-41846, https://mcreator.net/comment/31137), and poked around with MCreator in general, and I'm striking out.  I'm not getting a gradle error, but the item name won't show up in color.

 

This is for MCreator 1.7.7, by the way.  Here's my code:

 



import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraft.world.World;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.Block;
import net.minecraft.util.text.*;
import net.minecraft.client.resources.I18n;

import java.util.Random;
import java.util.List;

@SuppressWarnings("unchecked")
public class mcreator_dummyItem {

	public mcreator_dummyItem() {
	}

	public static Item block;
	public static Object instance;

	public void load(FMLInitializationEvent event) {
		if (event.getSide() == Side.CLIENT)
			Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
					.register(block, 0, new ModelResourceLocation("testenvironmentmod:DummyItem", "inventory"));
	}

	public void generateNether(World world, Random random, int chunkX, int chunkZ) {
	}

	public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
	}

	public int addFuel(ItemStack fuel) {
		return 0;
	}

	public void serverLoad(FMLServerStartingEvent event) {
	}

	public void preInit(FMLPreInitializationEvent event) {
	}

	public void registerRenderers() {
	}

	static {
		block = (new ItemdummyItem());

	}

	static class ItemdummyItem extends Item {

		public ItemdummyItem() {
			setMaxDamage(0);
			maxStackSize = 1;
			setUnlocalizedName("dummyitem");
			setRegistryName("dummyitem");
			ForgeRegistries.ITEMS.register(this);
			setCreativeTab(CreativeTabs.MISC);
		}

		@Override
		public int getItemEnchantability() {
			return 0;
		}

		@Override
		public int getMaxItemUseDuration(ItemStack par1ItemStack) {
			return 500;
		}

		@Override
		public float getDestroySpeed(ItemStack par1ItemStack, IBlockState par2Block) {
			return 1.5F;
		}

          public void addInformation(ItemStack par1ItemStack, World world, List list, boolean par4) {
               par1ItemStack.setStackDisplayName(TextFormatting.BLUE + I18n.format(this.getUnlocalizedName() + ".name"));
          }

	}
}

 

Much thanks for any guidance!

Last seen on 03:03, 6. Feb 2024
Joined Apr 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try thissetUnlocalizedName("…
Thu, 05/24/2018 - 16:19

Try this
setUnlocalizedName("\u00A7fdummyitem");

or when you making item add this to your name: \u00A7Dummy Item
This should work

Last seen on 13:41, 13. Mar 2021
Joined Jun 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It worked!  If you put the…
Mon, 06/04/2018 - 22:04

It worked!  If you put the code in the name field when making the item.  I didn't use the \u00A7 sequence, but Alt-Numpad2-Numpad1 to give me the 'section' symbol.  Worked great that way.

 

Doing "setUnlocalizedName("\u00A7fdummyitem");" gave me an item with the color in its name, but the item name was "item.dummyitem.item" (the middle part was in color).

 

Thanks!