Item color names

Started by CloudtailRox on

Topic category: Advanced modding

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Item color names
Fri, 09/02/2016 - 17:37 (edited)

I'd really like to have colored item names but whenever I try to put them in the game, I always get this

Executing gradle command: clean runClient
Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\~~~~l\Desktop\Mcreator 1.10.2\MCreator170>cd forge
C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\forge>SET "JAVA_HOME=C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\jdk64\"
C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\forge>SET JAVA_EXE=%JAVA_HOME%\bin\java.exe
C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\forge>SET PATH=%JAVA_HOME%\bin\;%PATH%
C:\Users\~~~~l\Desktop\Mcreator 1.10.2\MCreator170\forge>gradlew -Dorg.gradle.jvmargs="-Xms625m -Xmx2048m" clean runClient
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.7/userguide/gradle_daemon.html.
This mapping 'snapshot_20160518' was designed for MC 1.9.4! Use at your own peril.
#################################################
         ForgeGradle 2.2-SNAPSHOT-c438b06        
  https://github.com/MinecraftForge/ForgeGradle  
#################################################
               Powered by MCP unknown               
             http://modcoderpack.com             
         by: Searge, ProfMobius, Fesh0r,         
         R4wk, ZeuX, IngisKahn, bspkrs           
#################################################
:clean
:deobfCompileDummyTask
:deobfProvidedDummyTask
:sourceApiJava
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava
C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:23: error: '.' expected
import I18n;
           ^
C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:23: error: ';' expected
import I18n;
            ^
C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:25: error: class, interface, or enum expected
@SuppressWarnings("unchecked")
 ^
3 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 22.364 secs
C:\Users\~~~~\Desktop\Mcreator 1.10.2\MCreator170\forge>
Task completed with return code 0 in 23300 milliseconds

 

Here's the code:

package mod.mcreator;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
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.entity.player.EntityPlayer;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.Entity;
import net.minecraft.creativetab.CreativeTabs;
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 java.util.Random;
import java.util.List;
import I18n;

@SuppressWarnings("unchecked")
public class mcreator_lightningDust {

    public mcreator_lightningDust() {
    }

    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:LightningDust", "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 addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean par4)

    {

        itemstack.setStackDisplayName(EnumChatFormatting.BLUE + I18n.format(this.getUnlocalizedName() + "LightningDust"));

    }

    public void serverLoad(FMLServerStartingEvent event) {
    }

    public void preInit(FMLPreInitializationEvent event) {
    }

    public void registerRenderers() {
    }

    static {
        block = (new ItemlightningDust(477));

    }

    static class ItemlightningDust extends Item {

        public ItemlightningDust(int par1) {
            setMaxDamage(0);
            maxStackSize = 64;
            setUnlocalizedName("LightningDust");
            GameRegistry.registerItem(this, "LightningDust");
            setCreativeTab(CreativeTabs.MISC);
        }

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

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

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

        @Override
        public void onUpdate(ItemStack itemstack, World world, Entity entity, int par4, boolean par5) {
            int i = (int) entity.posX;
            int j = (int) entity.posY;
            int k = (int) entity.posZ;

            if ((Math.random() * 100) <= 1) {
                world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k, false));
            }

        }

        @Override
        public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
            list.add("Powerful");
            list.add("but very unstable");
        }

    }
}

Any help?

Edited by Nuparu00 on Fri, 09/02/2016 - 17:37
Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
crap i dont know how to do
Thu, 09/01/2016 - 23:40

crap i dont know how to do spoilers

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This "import I18n;" can work
Fri, 09/02/2016 - 17:55

This "import I18n;" can work only if your class is in same package as the imported class. Imports acts like a files in some file browser (Let's say the "Windows explorer"). If you are at highest possible location ( so for example disc C:\ ) , only way to get to some folder/file (without manually clicking through your computer) is write full path. So if your file is for example  "MCreator[1.7.0].exe" and it is in your downloads folder , its path would be "C:\Users\Buba\Downloads\MCreator[1.7.0].exe".
You can see that path at imports is something like "net.minecraft.entity.*; " or "java.util.Random;"

In this case for I18n it is "net.minecraft.client.resources.I18n".

Second... why do you have two times void addInformation()?
 

Third - why do you have the first one out of the Item's class?

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I still dont know where to
Sat, 09/10/2016 - 19:06

I still dont know where to put the code. 

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To the inner class that
Sat, 09/10/2016 - 19:33

To the inner class that extends Item

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Like this?
Sun, 09/11/2016 - 13:46

Like this?

/spoiler/

package mod.mcreator;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
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.entity.player.EntityPlayer;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.Entity;
import net.minecraft.creativetab.CreativeTabs;
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.client.resources.I18n;

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

@SuppressWarnings("unchecked")
public class mcreator_lightningDust {

    public mcreator_lightningDust() {
    }

    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:LightningDust", "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 ItemlightningDust(477));

    }

    static class ItemlightningDust extends Item {
          {
          itemstack.setStackDisplayName(EnumChatFormatting.BLUE + I18n.format(this.getUnlocalizedName() + "LightningDust"));
          }
        public ItemlightningDust(int par1) {
            setMaxDamage(0);
            maxStackSize = 64;
            setUnlocalizedName("LightningDust");
            GameRegistry.registerItem(this, "LightningDust");
            setCreativeTab(CreativeTabs.MISC);
               
        }

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

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

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

        @Override
        public void onUpdate(ItemStack itemstack, World world, Entity entity, int par4, boolean par5) {
            int i = (int) entity.posX;
            int j = (int) entity.posY;
            int k = (int) entity.posZ;

            if ((Math.random() * 100) <= 1) {
                world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k, false));
            }

        }

        @Override
        public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
            list.add("Powerful");
            list.add("but very unstable");
        }

    }
}

/spoiler/

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
HOW DO YOU DO SPOILERS????
Sun, 09/11/2016 - 13:46

HOW DO YOU DO SPOILERS????

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[*spoiler] [*/spoiler]
Sun, 09/11/2016 - 17:25

[*spoiler] [*/spoiler] (without the * symbol)

And why do you have this:

         {
          itemstack.setStackDisplayName(EnumChatFormatting.BLUE + I18n.format(this.getUnlocalizedName() + "LightningDust"));
          }

out of the void addInformation

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well now I'm getting this:
Sun, 09/11/2016 - 21:52

Well now I'm getting this:

[spoiler]

Executing gradle command: clean runClient
Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170>cd forge
C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge>SET "JAVA_HOME=C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\jdk64\"
C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge>SET JAVA_EXE=%JAVA_HOME%\bin\java.exe
C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge>SET PATH=%JAVA_HOME%\bin\;%PATH%
C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge>gradlew -Dorg.gradle.jvmargs="-Xms625m -Xmx2048m" clean runClient
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.7/userguide/gradle_daemon.html.
This mapping 'snapshot_20160518' was designed for MC 1.9.4! Use at your own peril.
#################################################
         ForgeGradle 2.2-SNAPSHOT-c438b06        
  https://github.com/MinecraftForge/ForgeGradle  
#################################################
               Powered by MCP unknown               
             http://modcoderpack.com             
         by: Searge, ProfMobius, Fesh0r,         
         R4wk, ZeuX, IngisKahn, bspkrs           
#################################################
:clean
:deobfCompileDummyTask
:deobfProvidedDummyTask
:sourceApiJava
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava
C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:105: error: cannot find symbol
                   itemstack.setStackDisplayName(EnumChatFormatting.BLUE + I18n.format(this.getUnlocalizedName() + "LightningDust"));
                                                 ^
  symbol:   variable EnumChatFormatting
  location: class ItemlightningDust
C:\Users\Samuel\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:105: error: cannot find symbol
                   itemstack.setStackDisplayName(EnumChatFormatting.BLUE + I18n.format(this.getUnlocalizedName() + "LightningDust"));
                   ^
  symbol:   variable itemstack
  location: class ItemlightningDust
2 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 52.88 secs
C:\Users\ppppl\Desktop\Mcreator 1.10.2\MCreator170\forge>
Task completed with return code 0 in 54456 milliseconds

[/spoiler]

 

And I put it here:

[spoiler]

@Override
        public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
               {
                   itemstack.setStackDisplayName(EnumChatFormatting.BLUE + I18n.format(this.getUnlocalizedName() + "LightningDust"));
               }    
            list.add("Powerful");
            list.add("but very unstable");
        }

[/spoiler]

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The brackets there must be
Mon, 09/12/2016 - 05:09

The brackets there must be only once and change itemstack to par1ItemStack

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
what do i do about this?
Mon, 09/12/2016 - 22:37

what do i do about this?

[spoiler]

C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:105: error: cannot find symbol
                          par1ItemStack.setStackDisplayName(EnumChatFormatting.BLUE + 
                                                            ^
  symbol:   variable EnumChatFormatting
  location: class ItemlightningDust
1 error

[/spoiler]

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try add this import: import
Mon, 09/12/2016 - 23:09

Try add this import: import net.minecraft.util.EnumChatFormatting;

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Spoiler: Highlight to view
Mon, 09/12/2016 - 23:56

[spoiler]

C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:21: error: cannot find symbol
import net.minecraft.util.EnumChatFormatting;
                         ^
  symbol:   class EnumChatFormatting
  location: package net.minecraft.util
C:\Users\pppp\Desktop\Mcreator 1.10.2\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_lightningDust.java:105: error: cannot find symbol
               par1ItemStack.setStackDisplayName(EnumChatFormatting.BLUE + I18n.format(this.getUnlocalizedName() + "LightningDust"));
                                                 ^
  symbol:   variable EnumChatFormatting
  location: class ItemlightningDust

[/spoiler]

Last seen on 23:50, 22. Apr 2019
Joined Nov 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
halp
Tue, 09/13/2016 - 21:24

halp

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok , remove the import + in
Tue, 09/13/2016 - 21:40

Ok , remove the import + in your code change EnumChatFormatting to TextFormatting.

+ you need this import if you have not it already: import net.minecraft.client.resources.I18n;