diff --git a/src/main/java/io/github/prospector/modmenu/gui/ModListEntry.java b/src/main/java/io/github/prospector/modmenu/gui/ModListEntry.java index 4b6ced6bb..7c6a53b23 100644 --- a/src/main/java/io/github/prospector/modmenu/gui/ModListEntry.java +++ b/src/main/java/io/github/prospector/modmenu/gui/ModListEntry.java @@ -80,10 +80,8 @@ private NativeImageBackedTexture createIcon() { } if (!Files.exists(path)) { ModContainer modMenu = FabricLoader.getInstance().getModContainer(ModMenu.MOD_ID).orElseThrow(IllegalAccessError::new); - if (HardcodedUtil.getFabricMods().contains(metadata.getId())) { - path = modMenu.getPath("assets/" + ModMenu.MOD_ID + "/fabric_icon.png"); - } else if (metadata.getId().equals("minecraft")) { - path = modMenu.getPath("assets/" + ModMenu.MOD_ID + "/mc_icon.png"); + if (HardcodedUtil.modHasHardcodedIcon(metadata)) { + path = HardcodedUtil.getHardcodedIcon(metadata); } else { path = modMenu.getPath("assets/" + ModMenu.MOD_ID + "/grey_fabric_icon.png"); } diff --git a/src/main/java/io/github/prospector/modmenu/util/BadgeType.java b/src/main/java/io/github/prospector/modmenu/util/BadgeType.java index d634ce2d4..9f1d6b191 100644 --- a/src/main/java/io/github/prospector/modmenu/util/BadgeType.java +++ b/src/main/java/io/github/prospector/modmenu/util/BadgeType.java @@ -9,7 +9,7 @@ public enum BadgeType { DEPRECATED(new TranslatableText("modmenu.deprecated"), 0xffff3333, 0xffb30000), PATCHWORK_FORGE(new TranslatableText("modmenu.forge"), 0xff1f2d42, 0xff101721), MINECRAFT(new TranslatableText("modmenu.minecraft"), 0xff6f6c6a, 0xff31302f); - + private Text text; private int outlineColor; private int fillColor; diff --git a/src/main/java/io/github/prospector/modmenu/util/HardcodedUtil.java b/src/main/java/io/github/prospector/modmenu/util/HardcodedUtil.java index 0ebfe9836..121fb2e18 100644 --- a/src/main/java/io/github/prospector/modmenu/util/HardcodedUtil.java +++ b/src/main/java/io/github/prospector/modmenu/util/HardcodedUtil.java @@ -8,10 +8,13 @@ import net.minecraft.text.Text; import org.apache.commons.lang3.text.WordUtils; +import java.nio.file.Path; import java.util.HashMap; import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -19,11 +22,17 @@ public class HardcodedUtil { private static final Pattern FABRIC_PATTERN = Pattern.compile("^fabric-.*(-v\\d+)$"); private static final Set FABRIC_MODS = new HashSet<>(); private static final HashMap HARDCODED_DESCRIPTIONS = new HashMap<>(); + private static final HashMap, Path> HARDCODED_ICONS = new HashMap<>(); public static void initializeHardcodings() { FABRIC_MODS.add("fabric"); FABRIC_MODS.add("fabricloader"); HARDCODED_DESCRIPTIONS.put("minecraft", "The base game."); + HARDCODED_DESCRIPTIONS.put("java", "The Java Runtime Environment"); + ModContainer modMenu = FabricLoader.getInstance().getModContainer(ModMenu.MOD_ID).orElseThrow(IllegalAccessError::new); + HARDCODED_ICONS.put(mod -> getFabricMods().contains(mod.getId()), modMenu.getPath("assets/" + ModMenu.MOD_ID + "/fabric_icon.png")); + HARDCODED_ICONS.put(mod -> mod.getId().equals("minecraft"), modMenu.getPath("assets/" + ModMenu.MOD_ID + "/mc_icon.png")); + HARDCODED_ICONS.put(mod -> mod.getId().equals("java"), modMenu.getPath("assets/" + ModMenu.MOD_ID + "/duke_icon.png")); } public static void hardcodeModuleMetadata(ModContainer mod, ModMetadata metadata, String id) { @@ -42,6 +51,9 @@ public static void hardcodeModuleMetadata(ModContainer mod, ModMetadata metadata if (id.equals("fabricloader") || id.equals("fabric") || metadata.getName().endsWith(" API")) { ModMenu.addLibraryMod(id); } + if (id.equals("java")) { + ModMenu.addLibraryMod(id); + } } public static Text formatFabricModuleName(String name) { @@ -60,6 +72,18 @@ public static Text formatFabricModuleName(String name) { return new LiteralText(name); } + public static boolean modHasHardcodedIcon(ModMetadata mod) { + return HARDCODED_ICONS.keySet().stream().anyMatch(predicate -> predicate.test(mod)); + } + + public static Path getHardcodedIcon(ModMetadata mod) { + AtomicReference result = new AtomicReference<>(); + HARDCODED_ICONS.forEach((predicate, path) -> { + if (predicate.test(mod)) result.set(path); + }); + return result.get(); + } + public static String getHardcodedDescription(String id) { return HARDCODED_DESCRIPTIONS.getOrDefault(id, ""); } diff --git a/src/main/resources/assets/modmenu/duke_icon.png b/src/main/resources/assets/modmenu/duke_icon.png new file mode 100644 index 000000000..db7198805 Binary files /dev/null and b/src/main/resources/assets/modmenu/duke_icon.png differ