[Tutorial] How to make your text change colors

Started by mega1134227 on

Topic category: User side tutorials

Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Tutorial] How to make your text change colors
Sat, 09/07/2019 - 16:13 (edited)

This time around, I'll be teaching you guys a new trick of mine :P
The trick consists of making text change colors! This works with overlays, but I don't see why it shouldn't work with GUI's either :D

First off, you'll need to have your overlay/GUI ready. All done? Great. Next step is to lock its code.

After that, you'll need to get the colors you want. I can already offer a few, but if you want specific colors, I suggest to make a second overlay/GUI and to put in text colored with the colors you want and to then get them in the code. (Btw, I'm not exactly sure of the colors, some might be a bit off ;D)

Here are the colors I can offer :

        Red : -65536
        Orange : -39424
        Yellow : -256
        Lime green : -3342592
        Green : -13369600
        Turquoise : -16738048
        Light blue : -16737997
        Blue : -16711681
        Purple-ish blue : -16737844
        Purple : -16777063
        Pinkish purple : -6750004
        Pink : -65281
        Pinkish magenta : -65383

Then, you'll need to make a procedure. Make sure that procedure updates on "on player tick update" so that it actually updates and works. Then, you'll need to make an nbt tag "cycle."
That nbt tag will equal the value of your color. Don't forget to name your nbt and to keep it's name so that it can work and recognize it :)
Like so :

Ex :
        If yournbt1 = 1 {

                set yournbt1 to 2
        }
        else if yournbt1 = 2 {
                set yournbt1 to 3
        }
        else if yournbt1 = 3{

                set yournbt1 to 1

        }
        else {
                set yournbt1 to 1
        }

A mistake I see people do often is to use multiple "ifs." That isn't necessary, use a single one. Just go edit it (by clicking on the gear) so that it has multiple "else ifs" under it and then make it end with an else to catch the initial value of 0 of your nbt tag.
I recommend to then add a delay because otherwise, the color'll change too quick and it'll be hard to see them.
Like so :

Ex :
        If yournbt2 = 0 {
                set yournbt2 to 1
        }
        else if yournbt2 =1{
                do "yournbt1 procedure"
        }

You could add more of these as well if you want to make it slower as well :)

Last step is to edit your initial overlay. You'll have to add in a new variable to make this work. I named mine "color." This variable should be an int (simple value without any decimals) that is equal to yournbt1 as an int.
Use that "color" to replace the color value of your initial text.
Like so :

        @SubscribeEvent(priority = EventPriority.HIGH)
                @SideOnly(Side.CLIENT)
                public void eventHandler(RenderGameOverlayEvent event) {
                    if (!event.isCancelable() && event.getType() == RenderGameOverlayEvent.ElementType.HELMET) {
                        int posX = (event.getResolution().getScaledWidth()) / 2;
                        int posY = (event.getResolution().getScaledHeight()) / 2;
                        EntityPlayer entity = Minecraft.getMinecraft().player;
                        World world = entity.world;
                        int x = (int) entity.posX;
                        int y = (int) entity.posY;
                        int z = (int) entity.posZ;
                        int color = (int) (entity.getEntityData().getDouble("yournbt1"));
                        if (true) {
                            Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect(posX + 174, posY + 83, 0, 0, 256, 256);
                            Minecraft.getMinecraft().fontRenderer.drawString("something random", posX + 183, posY + 73, color);
                        }
                    }
                }

That's all! I know this might be a bit difficult to understand, but please do your best because I won't be coming back to explain this to anyone due to how busy I'll be with school, my mod and other stuff.
Other than that, if you did everything well, it should work :D
Btw, don't ask me or other people where the nbt tag procedures or any other are located because you should familiarize yourself first with where they are before doing any procedures. Otherwise, it's a waste of both your time and mine to ask that :/

Edited by mega1134227 on Sat, 09/07/2019 - 16:13
Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I've been trying ;P
Sun, 09/08/2019 - 14:11

I've been trying ;P

Joined Dec 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do you make it so that…
Sat, 02/15/2020 - 14:20

How do you make it so that when you Display a global variable with gui/overlay it only Shows a full number not decimal like 0.0

24.0 or something like that just the number 0  24

Joined Dec 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
before the feature is added…
Sat, 02/22/2020 - 20:26

before the feature is added you could try locking the code and changing the variable type from float (or double) to int, that way it will be an integer which means it will not have any decimals

Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Basically, you do the same…
Sun, 02/23/2020 - 14:18

Basically, you do the same thing I did for the color thing. Make a new int variable named "variable" or something like that and make it equal to your nbt converted into an int.
Like so:

int var = (int)(entity.getEntityData().getDouble("yournbt3"));

And then you follow my other tutorial or something like that and mix the steps that were shown here with the other ones to get what you want.
Here it is btw.
https://mcreator.net/forum/49725/variables-and-overlays-how-tutorial