Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So i was wondering how to use other colors than the on listed in the "TextFormatting" file. 
Example

mc.fontRenderer.drawStringWithShadow(Mod.MODNAME + " " + TextFormating.GREEN + Mod.MODVER,1,1,Mod.MYHEXCOLOR);

How would i go on using brown as example?

I use the following class to get colors outside the predefined ones, it should be able to fit your case I belive.


To understand how it works, it is simply that RGBA colors are encoded in a single integer, where each set of 2 bytes store a single color.

2 bytes can encode the values 0-255.Which is the reason that RGB is defined in that range.
 

public class GuiHelper {
    private GuiHelper() {

    }

    public static int RGBAToInt(int R, int G, int B, int A) {
        // Make sure the values are between 0 and 255
        R &= 255;
        G &= 255;
        B &= 255;
        A &= 255;

        // Convert
        return A << 24 | R << 16 | G << 8 | B;
    }

    public static int RGBAToInt(int RGB, int A) {
        return RGBAToInt(RGB, RGB, RGB, A);
    }

    public static int RGBAToInt(int RGB) {
        return RGBAToInt(RGB, RGB, RGB, 255);
    }

    public static int RGBAToInt(int R, int G, int B) {
        return RGBAToInt(R, G, B, 255);
    }

}

 

  • Author
3 minutes ago, [DK] Headcrab [DK] said:

I use the following class to get colors outside the predefined ones, it should be able to fit your case I belive.


To understand how it works, it is simply that RGBA colors are encoded in a single integer, where each set of 2 bytes store a single color.

2 bytes can encode the values 0-255.Which is the reason that RGB is defined in that range.
 


public class GuiHelper {
    private GuiHelper() {

    }

    public static int RGBAToInt(int R, int G, int B, int A) {
        // Make sure the values are between 0 and 255
        R &= 255;
        G &= 255;
        B &= 255;
        A &= 255;

        // Convert
        return A << 24 | R << 16 | G << 8 | B;
    }

    public static int RGBAToInt(int RGB, int A) {
        return RGBAToInt(RGB, RGB, RGB, A);
    }

    public static int RGBAToInt(int RGB) {
        return RGBAToInt(RGB, RGB, RGB, 255);
    }

    public static int RGBAToInt(int R, int G, int B) {
        return RGBAToInt(R, G, B, 255);
    }

}

 

How would i use it? I got the class in my util folder and now idk how to use it :P

 

4 minutes ago, epik666 said:

How would i use it? I got the class in my util folder and now idk how to use it :P

The last argument for FontRenderer#drawString is the color as an integer.

 

So for example:

fontRenderer.drawString("My string to draw in RED", stringPosX, stringPosY, GuiHelper.RGBAToInt(255, 0, 0));

 

Same applies for FontRenderer#drawStringWithShadow

Edited by [DK] Headcrab [DK]

  • Author
24 minutes ago, [DK] Headcrab [DK] said:

 

The last argument for FontRenderer#drawString is the color as an integer.

 

So for example:


fontRenderer.drawString("My string to draw in RED", stringPosX, stringPosY, GuiHelper.RGBAToInt(255, 0, 0));

 

Same applies for FontRenderer#drawStringWithShadow

Thanks, it seems like it does not work outside fontrenders. Im trying to use it in something else and i can't seem to figure out how to do it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.