add italics to the server preview renderer
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m52s
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m52s
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 {
|
||||
Color color = ColorUtils.getMinecraftColor(colorCode);
|
||||
graphics.setColor(color);
|
||||
graphics.setFont(Fonts.MINECRAFT);
|
||||
// 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…
x
Reference in New Issue
Block a user