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) {
|
public static Color getMinecraftColor(char colorCode) {
|
||||||
String color = COLOR_MAP.getOrDefault(colorCode, null);
|
String color = COLOR_MAP.getOrDefault(colorCode, null);
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
System.out.println("Unknown color code: " + colorCode);
|
throw new IllegalArgumentException("Invalid color code: " + colorCode);
|
||||||
return Color.WHITE;
|
|
||||||
}
|
}
|
||||||
return Color.decode(color);
|
return Color.decode(color);
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,14 @@ public class Fonts {
|
|||||||
|
|
||||||
public static final Font MINECRAFT;
|
public static final Font MINECRAFT;
|
||||||
public static final Font MINECRAFT_BOLD;
|
public static final Font MINECRAFT_BOLD;
|
||||||
|
public static final Font MINECRAFT_ITALIC;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
InputStream stream = Main.class.getResourceAsStream("/fonts/minecraft-font.ttf");
|
InputStream stream = Main.class.getResourceAsStream("/fonts/minecraft-font.ttf");
|
||||||
try {
|
try {
|
||||||
MINECRAFT = Font.createFont(Font.TRUETYPE_FONT, stream).deriveFont(18f);
|
MINECRAFT = Font.createFont(Font.TRUETYPE_FONT, stream).deriveFont(18f);
|
||||||
MINECRAFT_BOLD = MINECRAFT.deriveFont(Font.BOLD);
|
MINECRAFT_BOLD = MINECRAFT.deriveFont(Font.BOLD);
|
||||||
|
MINECRAFT_ITALIC = MINECRAFT.deriveFont(Font.ITALIC);
|
||||||
} catch (FontFormatException | IOException e) {
|
} catch (FontFormatException | IOException e) {
|
||||||
log.error("Failed to load Minecraft font", e);
|
log.error("Failed to load Minecraft font", e);
|
||||||
throw new RuntimeException("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
|
// Move x position to after the drawn text
|
||||||
x += textWidth;
|
x += textWidth;
|
||||||
// Set color based on color code
|
// Set color based on color code
|
||||||
char colorCode = line.charAt(colorIndex + 1);
|
char colorCode = Character.toLowerCase(line.charAt(colorIndex + 1));
|
||||||
|
|
||||||
if (colorCode == 'l') {
|
// Set the color and font style
|
||||||
graphics.setFont(Fonts.MINECRAFT_BOLD);
|
switch (colorCode) {
|
||||||
} else {
|
case 'l': graphics.setFont(Fonts.MINECRAFT_BOLD);
|
||||||
Color color = ColorUtils.getMinecraftColor(colorCode);
|
case 'o': graphics.setFont(Fonts.MINECRAFT_ITALIC);
|
||||||
graphics.setColor(color);
|
default: {
|
||||||
graphics.setFont(Fonts.MINECRAFT);
|
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
|
// Move index to after the color code
|
||||||
|
Loading…
Reference in New Issue
Block a user