Posted May 16, 20205 yr 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?
May 16, 20205 yr 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); } }
May 16, 20205 yr 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
May 16, 20205 yr 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 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 May 16, 20205 yr by [DK] Headcrab [DK]
May 16, 20205 yr 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.