forked from MinecraftUtilities/Backend
add italics to the server preview renderer
This commit is contained in:
parent
6693fc6793
commit
69833bf560
@ -104,8 +104,7 @@ public final class ColorUtils {
|
||||
public static Color getMinecraftColor(char colorCode) {
|
||||
String color = COLOR_MAP.getOrDefault(colorCode, null);
|
||||
if (color == null) {
|
||||
System.out.println("Unknown color code: " + colorCode);
|
||||
return Color.WHITE;
|
||||
throw new IllegalArgumentException("Invalid color code: " + colorCode);
|
||||
}
|
||||
return Color.decode(color);
|
||||
}
|
||||
|
@ -12,12 +12,14 @@ public class Fonts {
|
||||
|
||||
public static final Font MINECRAFT;
|
||||
public static final Font MINECRAFT_BOLD;
|
||||
public static final Font MINECRAFT_ITALIC;
|
||||
|
||||
static {
|
||||
InputStream stream = Main.class.getResourceAsStream("/fonts/minecraft-font.ttf");
|
||||
try {
|
||||
MINECRAFT = Font.createFont(Font.TRUETYPE_FONT, stream).deriveFont(18f);
|
||||
MINECRAFT_BOLD = MINECRAFT.deriveFont(Font.BOLD);
|
||||
MINECRAFT_ITALIC = MINECRAFT.deriveFont(Font.ITALIC);
|
||||
} catch (FontFormatException | IOException e) {
|
||||
log.error("Failed to load Minecraft font", e);
|
||||
throw new RuntimeException("Failed to load Minecraft font", e);
|
||||
|
@ -79,14 +79,21 @@ public class ServerPreviewRenderer extends Renderer<MinecraftServer> {
|
||||
// Move x position to after the drawn text
|
||||
x += textWidth;
|
||||
// Set color based on color code
|
||||
char colorCode = line.charAt(colorIndex + 1);
|
||||
char colorCode = Character.toLowerCase(line.charAt(colorIndex + 1));
|
||||
|
||||
if (colorCode == 'l') {
|
||||
graphics.setFont(Fonts.MINECRAFT_BOLD);
|
||||
} else {
|
||||
// Set the color and font style
|
||||
switch (colorCode) {
|
||||
case 'l': graphics.setFont(Fonts.MINECRAFT_BOLD);
|
||||
case 'o': graphics.setFont(Fonts.MINECRAFT_ITALIC);
|
||||
default: {
|
||||
try {
|
||||
Color color = ColorUtils.getMinecraftColor(colorCode);
|
||||
graphics.setColor(color);
|
||||
graphics.setFont(Fonts.MINECRAFT);
|
||||
} catch (Exception ignored) {
|
||||
// Unknown color, can ignore the error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move index to after the color code
|
||||
|
Loading…
Reference in New Issue
Block a user