ColorConverterUtils - MeAlam1/BlueLib GitHub Wiki
The ColorConverterUtils
class provides utility methods for parsing and converting color representations. This includes conversions between RGB, ARGB, hexadecimal strings, and Minecraft's DyeColor
enum. It simplifies working with color inputs in both string and numeric forms while providing robust error handling and logging.
To begin using ColorConverterUtils
, call any of its static methods to parse or convert color values in your mod.
Below is a breakdown of the available methods and their functionality.
-
parseColorToHexString(String) Parses a color string into a hexadecimal
int
value. Supports input formats like RGB tuples, ARGB tuples, hex strings (with#
or0x
), and raw hex strings.int color = ColorConverterUtils.parseColorToHexString("(255, 128, 64)");
-
getParsedColor(String) Attempts to parse a string into a
java.awt.Color
. Supports#hexcode
formats and MinecraftDyeColor
names.Optional<Color> color = ColorConverterUtils.getParsedColor("#FF0000");
-
getParsedColorName(String) Returns the lowercase string name of a Minecraft
DyeColor
if the provided input is valid.Optional<String> name = ColorConverterUtils.getParsedColorName("blue");
-
rgbToDecimal(int, int, int) Converts individual red, green, and blue components into a single decimal integer.
int hex = ColorConverterUtils.rgbToDecimal(255, 128, 64);
-
RGB Tuple:
(255, 255, 255)
-
ARGB Tuple:
(255, 255, 255, 255)
(Alpha is ignored) -
Hex String:
#FFFFFF
or0xFFFFFF
-
Raw Hex:
FFFFFF
-
Validation: RGB values are validated to ensure they lie within the range
0–255
. Invalid formats default to0xFFFFFF
. -
Logging: Invalid inputs are logged using BlueLib's internal
BaseLogger
. - Utility Design: This class cannot be instantiated and only provides static utility methods.