From 8a5aefc09bc34735d83a43748f43ab5a254ff2b3 Mon Sep 17 00:00:00 2001 From: William Bradford Larcombe Date: Sat, 23 Jan 2021 19:33:31 +0000 Subject: [PATCH] Add special handling for Java (#190) - Added special handling to give Java additional metadata --- .../prospector/modmenu/gui/ModListEntry.java | 6 ++--- .../prospector/modmenu/util/BadgeType.java | 2 +- .../modmenu/util/HardcodedUtil.java | 24 ++++++++++++++++++ .../resources/assets/modmenu/duke_icon.png | Bin 0 -> 680 bytes 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/assets/modmenu/duke_icon.png 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 0000000000000000000000000000000000000000..db719880560cc933da1d4de556b7f6e89816b07b GIT binary patch literal 680 zcmV;Z0$2TsP)F{hSDXr$$ zq`r6fFoY1M5RsW}Eo3rjbd8@!s-}2|i(cL9I>ul@wHe^+C!S>%cZlbS(_4-uc#k;3 zN^*htggD0OfW)^#S3G_bT=e)$FwbQd0l(-e728;8V^-n@@g#B7&?~HY9&wYPYOX9( z9;Gz~8(E}~gaic@Y(j^FIAxP&*4dY6_?A#652L?@DmXccD3LctYK6M0lr_>-`gByq z-2czh)@G)??!hF``|7%%<3Qg&P_Mb}@2Tt7&w#)SaBa5yWt!96H|e#O7Ci>SJHX{l zOH&Sjt6gB^*^;^3kOH*)ng)Da0HHiEd=Ct)d$VfpD?%eBCNqv-0Xl=ZW`Jpjdm(bMU`f+q{!FWxOtyf}+xz?f zl1H-;jrKT`0yXeeHAEULoPo34Wqzll!wU4IMpZCbz`Vog=n+GbjdVth+W9a6G}YmE zLevH~0^th$3D5{w>brY8zH