From 73829e6245628967d7c07085fe34edd0ff3ef3e9 Mon Sep 17 00:00:00 2001 From: Prospector Date: Sun, 16 Jun 2024 16:47:53 -0400 Subject: [PATCH] reformat --- .editorconfig | 15 +- .../com/terraformersmc/modmenu/ModMenu.java | 23 +- .../modmenu/ModMenuModMenuCompat.java | 1 - .../modmenu/api/ModMenuApi.java | 1 - .../modmenu/api/UpdateChannel.java | 4 +- .../modmenu/config/FileOnlyConfig.java | 3 +- .../modmenu/config/ModMenuConfig.java | 56 ++-- .../modmenu/config/ModMenuConfigManager.java | 28 +- .../config/option/BooleanConfigOption.java | 19 +- .../config/option/EnumConfigOption.java | 20 +- .../config/option/StringSetConfigOption.java | 3 +- .../modmenu/event/ModMenuEventHandler.java | 59 +++- .../modmenu/gui/ModsScreen.java | 304 ++++++++++++------ .../gui/widget/DescriptionListWidget.java | 104 +++--- .../widget/LegacyTexturedButtonWidget.java | 40 ++- .../modmenu/gui/widget/ModListWidget.java | 54 +++- .../gui/widget/ModMenuButtonWidget.java | 15 +- .../UpdateCheckerTexturedButtonWidget.java | 16 +- .../gui/widget/entries/ChildEntry.java | 17 +- .../gui/widget/entries/ModListEntry.java | 97 +++++- .../gui/widget/entries/ParentEntry.java | 75 ++++- .../modmenu/mixin/AccessorGridWidget.java | 1 - .../modmenu/mixin/MixinGameMenu.java | 30 +- .../modmenu/mixin/MixinTitleScreen.java | 3 +- .../modmenu/util/DrawingUtil.java | 58 +++- .../util/EnumToLowerCaseJsonConverter.java | 8 +- .../terraformersmc/modmenu/util/HttpUtil.java | 19 +- .../terraformersmc/modmenu/util/JsonUtil.java | 11 +- .../modmenu/util/ModMenuScreenTexts.java | 1 - .../modmenu/util/UpdateCheckerUtil.java | 31 +- .../modmenu/util/VersionUtil.java | 2 +- .../terraformersmc/modmenu/util/mod/Mod.java | 47 +-- .../modmenu/util/mod/ModBadgeRenderer.java | 22 +- .../modmenu/util/mod/ModSearch.java | 44 +-- .../modmenu/util/mod/ModrinthUpdateInfo.java | 4 +- .../util/mod/fabric/FabricDummyParentMod.java | 9 +- .../util/mod/fabric/FabricIconHandler.java | 6 +- .../mod/fabric/FabricLoaderUpdateChecker.java | 18 +- .../modmenu/util/mod/fabric/FabricMod.java | 53 +-- .../mod/quilt/QuiltLoaderUpdateChecker.java | 27 +- .../modmenu/util/mod/quilt/QuiltMod.java | 33 +- .../resources/assets/modmenu/lang/be_by.json | 2 +- .../resources/assets/modmenu/lang/en_us.json | 24 +- .../resources/assets/modmenu/lang/no_no.json | 24 +- .../resources/assets/modmenu/lang/pl_pl.json | 20 +- .../resources/assets/modmenu/lang/tt_ru.json | 2 +- 46 files changed, 981 insertions(+), 472 deletions(-) diff --git a/.editorconfig b/.editorconfig index 292b72d0d..d5a5e4f28 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,21 +5,8 @@ charset = utf-8 end_of_line = lf insert_final_newline = true tab_width = 4 - -[*.gradle] -indent_style = tab - -[*.java] indent_style = tab [*.json] indent_style = space -indent_size = 2 - -[*.properties] -indent_style = space -indent_size = 2 - -[.editorconfig] -indent_style = space -indent_size = 4 \ No newline at end of file +indent_size = 2 \ No newline at end of file diff --git a/src/main/java/com/terraformersmc/modmenu/ModMenu.java b/src/main/java/com/terraformersmc/modmenu/ModMenu.java index d676725ca..9920ca31b 100644 --- a/src/main/java/com/terraformersmc/modmenu/ModMenu.java +++ b/src/main/java/com/terraformersmc/modmenu/ModMenu.java @@ -39,9 +39,10 @@ public class ModMenu implements ClientModInitializer { public static final Gson GSON_MINIFIED; static { - GsonBuilder builder = new GsonBuilder() - .registerTypeHierarchyAdapter(Enum.class, new EnumToLowerCaseJsonConverter()) - .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); + GsonBuilder builder = new GsonBuilder().registerTypeHierarchyAdapter(Enum.class, + new EnumToLowerCaseJsonConverter() + ) + .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); GSON = builder.setPrettyPrinting().create(); GSON_MINIFIED = builder.create(); } @@ -191,11 +192,7 @@ public static String getDisplayedModCount() { if (!includeLibraries && isLibrary) { return false; } - if (!includeHidden && mod.isHidden()) { - return false; - } - - return true; + return includeHidden || !mod.isHidden(); }).count()); } return NumberFormat.getInstance().format(cachedDisplayedModCount); @@ -204,10 +201,12 @@ public static String getDisplayedModCount() { public static Text createModsButtonText(boolean title) { var titleStyle = ModMenuConfig.MODS_BUTTON_STYLE.getValue(); var gameMenuStyle = ModMenuConfig.GAME_MENU_BUTTON_STYLE.getValue(); - var isIcon = title ? titleStyle == ModMenuConfig.TitleMenuButtonStyle.ICON : gameMenuStyle == - ModMenuConfig.GameMenuButtonStyle.ICON; - var isShort = title ? titleStyle == ModMenuConfig.TitleMenuButtonStyle.SHRINK : gameMenuStyle == - ModMenuConfig.GameMenuButtonStyle.REPLACE_BUGS; + var isIcon = title ? + titleStyle == ModMenuConfig.TitleMenuButtonStyle.ICON : + gameMenuStyle == ModMenuConfig.GameMenuButtonStyle.ICON; + var isShort = title ? + titleStyle == ModMenuConfig.TitleMenuButtonStyle.SHRINK : + gameMenuStyle == ModMenuConfig.GameMenuButtonStyle.REPLACE_BUGS; MutableText modsText = ModMenuScreenTexts.TITLE.copy(); if (ModMenuConfig.MOD_COUNT_LOCATION.getValue().isOnModsButton() && !isIcon) { String count = ModMenu.getDisplayedModCount(); diff --git a/src/main/java/com/terraformersmc/modmenu/ModMenuModMenuCompat.java b/src/main/java/com/terraformersmc/modmenu/ModMenuModMenuCompat.java index 4ed4991e2..4d8a9cd54 100644 --- a/src/main/java/com/terraformersmc/modmenu/ModMenuModMenuCompat.java +++ b/src/main/java/com/terraformersmc/modmenu/ModMenuModMenuCompat.java @@ -6,7 +6,6 @@ import com.terraformersmc.modmenu.gui.ModMenuOptionsScreen; import com.terraformersmc.modmenu.util.mod.fabric.FabricLoaderUpdateChecker; import com.terraformersmc.modmenu.util.mod.quilt.QuiltLoaderUpdateChecker; - import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.option.OptionsScreen; diff --git a/src/main/java/com/terraformersmc/modmenu/api/ModMenuApi.java b/src/main/java/com/terraformersmc/modmenu/api/ModMenuApi.java index 729209f8b..72c9f6266 100644 --- a/src/main/java/com/terraformersmc/modmenu/api/ModMenuApi.java +++ b/src/main/java/com/terraformersmc/modmenu/api/ModMenuApi.java @@ -86,6 +86,5 @@ default Map getProvidedUpdateCheckers() { * provided by a modpack. */ default void attachModpackBadges(Consumer consumer) { - return; } } diff --git a/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java b/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java index 4c51835c9..f4eb2020d 100644 --- a/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java +++ b/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java @@ -6,9 +6,7 @@ * Supported update channels, in ascending order by stability. */ public enum UpdateChannel { - ALPHA, - BETA, - RELEASE; + ALPHA, BETA, RELEASE; /** * @return the user's preferred update channel. diff --git a/src/main/java/com/terraformersmc/modmenu/config/FileOnlyConfig.java b/src/main/java/com/terraformersmc/modmenu/config/FileOnlyConfig.java index b39bcac22..9fe1a28cd 100644 --- a/src/main/java/com/terraformersmc/modmenu/config/FileOnlyConfig.java +++ b/src/main/java/com/terraformersmc/modmenu/config/FileOnlyConfig.java @@ -7,5 +7,4 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) -public @interface FileOnlyConfig { -} +public @interface FileOnlyConfig { } diff --git a/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfig.java b/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfig.java index 6766d7ecb..06b6b185e 100644 --- a/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfig.java +++ b/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfig.java @@ -20,15 +20,18 @@ public class ModMenuConfig { public static final BooleanConfigOption COUNT_LIBRARIES = new BooleanConfigOption("count_libraries", true); public static final BooleanConfigOption COMPACT_LIST = new BooleanConfigOption("compact_list", false); public static final BooleanConfigOption COUNT_CHILDREN = new BooleanConfigOption("count_children", true); - public static final EnumConfigOption MODS_BUTTON_STYLE = new EnumConfigOption<>("mods_button_style", - TitleMenuButtonStyle.CLASSIC + public static final EnumConfigOption MODS_BUTTON_STYLE = new EnumConfigOption<>( + "mods_button_style", + TitleMenuButtonStyle.CLASSIC ); - public static final EnumConfigOption GAME_MENU_BUTTON_STYLE = new EnumConfigOption<>("game_menu_button_style", - GameMenuButtonStyle.REPLACE_BUGS + public static final EnumConfigOption GAME_MENU_BUTTON_STYLE = new EnumConfigOption<>( + "game_menu_button_style", + GameMenuButtonStyle.REPLACE_BUGS ); public static final BooleanConfigOption COUNT_HIDDEN_MODS = new BooleanConfigOption("count_hidden_mods", true); - public static final EnumConfigOption MOD_COUNT_LOCATION = new EnumConfigOption<>("mod_count_location", - ModCountLocation.TITLE_SCREEN + public static final EnumConfigOption MOD_COUNT_LOCATION = new EnumConfigOption<>( + "mod_count_location", + ModCountLocation.TITLE_SCREEN ); public static final BooleanConfigOption HIDE_MOD_LINKS = new BooleanConfigOption("hide_mod_links", false); public static final BooleanConfigOption SHOW_LIBRARIES = new BooleanConfigOption("show_libraries", false); @@ -38,10 +41,14 @@ public class ModMenuConfig { public static final BooleanConfigOption EASTER_EGGS = new BooleanConfigOption("easter_eggs", true); public static final BooleanConfigOption RANDOM_JAVA_COLORS = new BooleanConfigOption("random_java_colors", false); public static final BooleanConfigOption TRANSLATE_NAMES = new BooleanConfigOption("translate_names", true); - public static final BooleanConfigOption TRANSLATE_DESCRIPTIONS = new BooleanConfigOption("translate_descriptions", true); + public static final BooleanConfigOption TRANSLATE_DESCRIPTIONS = new BooleanConfigOption("translate_descriptions", + true + ); public static final BooleanConfigOption UPDATE_CHECKER = new BooleanConfigOption("update_checker", true); public static final BooleanConfigOption BUTTON_UPDATE_BADGE = new BooleanConfigOption("button_update_badge", true); - public static final EnumConfigOption UPDATE_CHANNEL = new EnumConfigOption<>("update_channel", UpdateChannel.RELEASE); + public static final EnumConfigOption UPDATE_CHANNEL = new EnumConfigOption<>("update_channel", + UpdateChannel.RELEASE + ); public static final BooleanConfigOption QUICK_CONFIGURE = new BooleanConfigOption("quick_configure", true); @FileOnlyConfig @@ -53,13 +60,20 @@ public class ModMenuConfig { @FileOnlyConfig public static final BooleanConfigOption CONFIG_MODE = new BooleanConfigOption("config_mode", false); @FileOnlyConfig - public static final BooleanConfigOption DISABLE_DRAG_AND_DROP = new BooleanConfigOption("disable_drag_and_drop", false); + public static final BooleanConfigOption DISABLE_DRAG_AND_DROP = new BooleanConfigOption("disable_drag_and_drop", + false + ); @FileOnlyConfig public static final StringSetConfigOption HIDDEN_MODS = new StringSetConfigOption("hidden_mods", new HashSet<>()); @FileOnlyConfig - public static final StringSetConfigOption HIDDEN_CONFIGS = new StringSetConfigOption("hidden_configs", new HashSet<>()); + public static final StringSetConfigOption HIDDEN_CONFIGS = new StringSetConfigOption("hidden_configs", + new HashSet<>() + ); @FileOnlyConfig - public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption("disable_update_checker", new HashSet<>()); + public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption( + "disable_update_checker", + new HashSet<>() + ); public static SimpleOption[] asOptions() { ArrayList> options = new ArrayList<>(); @@ -77,8 +91,8 @@ public static SimpleOption[] asOptions() { } public enum Sorting { - ASCENDING(Comparator.comparing(mod -> mod.getTranslatedName().toLowerCase(Locale.ROOT))), - DESCENDING(ASCENDING.getComparator().reversed()); + ASCENDING(Comparator.comparing(mod -> mod.getTranslatedName() + .toLowerCase(Locale.ROOT))), DESCENDING(ASCENDING.getComparator().reversed()); private final Comparator comparator; @@ -92,10 +106,9 @@ public Comparator getComparator() { } public enum ModCountLocation { - TITLE_SCREEN(true, false), - MODS_BUTTON(false, true), - TITLE_SCREEN_AND_MODS_BUTTON(true, true), - NONE(false, false); + TITLE_SCREEN(true, false), MODS_BUTTON(false, true), TITLE_SCREEN_AND_MODS_BUTTON(true, true), NONE(false, + false + ); private final boolean titleScreen, modsButton; @@ -114,15 +127,10 @@ public boolean isOnModsButton() { } public enum TitleMenuButtonStyle { - CLASSIC(), - REPLACE_REALMS(), - SHRINK(), - ICON(); + CLASSIC(), REPLACE_REALMS(), SHRINK(), ICON() } public enum GameMenuButtonStyle { - REPLACE_BUGS, - BELOW_BUGS, - ICON; + REPLACE_BUGS, BELOW_BUGS, ICON } } diff --git a/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfigManager.java b/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfigManager.java index c1b350aaf..a83fe8075 100644 --- a/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfigManager.java +++ b/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfigManager.java @@ -9,7 +9,9 @@ import com.terraformersmc.modmenu.config.option.StringSetConfigOption; import net.fabricmc.loader.api.FabricLoader; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; @@ -51,16 +53,24 @@ private static void load() { JsonArray jsonArray = json.getAsJsonArray(field.getName().toLowerCase(Locale.ROOT)); if (jsonArray != null) { StringSetConfigOption option = (StringSetConfigOption) field.get(null); - ConfigOptionStorage.setStringSet(option.getKey(), Sets.newHashSet(jsonArray).stream().map(JsonElement::getAsString).collect(Collectors.toSet())); + ConfigOptionStorage.setStringSet( + option.getKey(), + Sets.newHashSet(jsonArray) + .stream() + .map(JsonElement::getAsString) + .collect(Collectors.toSet()) + ); } } else if (BooleanConfigOption.class.isAssignableFrom(field.getType())) { - JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName().toLowerCase(Locale.ROOT)); + JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName() + .toLowerCase(Locale.ROOT)); if (jsonPrimitive != null && jsonPrimitive.isBoolean()) { BooleanConfigOption option = (BooleanConfigOption) field.get(null); ConfigOptionStorage.setBoolean(option.getKey(), jsonPrimitive.getAsBoolean()); } } else if (EnumConfigOption.class.isAssignableFrom(field.getType()) && field.getGenericType() instanceof ParameterizedType) { - JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName().toLowerCase(Locale.ROOT)); + JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName() + .toLowerCase(Locale.ROOT)); if (jsonPrimitive != null && jsonPrimitive.isString()) { Type generic = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (generic instanceof Class) { @@ -99,7 +109,9 @@ public static void save() { if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { if (BooleanConfigOption.class.isAssignableFrom(field.getType())) { BooleanConfigOption option = (BooleanConfigOption) field.get(null); - config.addProperty(field.getName().toLowerCase(Locale.ROOT), ConfigOptionStorage.getBoolean(option.getKey())); + config.addProperty(field.getName().toLowerCase(Locale.ROOT), + ConfigOptionStorage.getBoolean(option.getKey()) + ); } else if (StringSetConfigOption.class.isAssignableFrom(field.getType())) { StringSetConfigOption option = (StringSetConfigOption) field.get(null); JsonArray array = new JsonArray(); @@ -109,7 +121,11 @@ public static void save() { Type generic = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (generic instanceof Class) { EnumConfigOption option = (EnumConfigOption) field.get(null); - config.addProperty(field.getName().toLowerCase(Locale.ROOT), ConfigOptionStorage.getEnumTypeless(option.getKey(), (Class>) generic).name().toLowerCase(Locale.ROOT)); + config.addProperty(field.getName().toLowerCase(Locale.ROOT), + ConfigOptionStorage.getEnumTypeless(option.getKey(), (Class>) generic) + .name() + .toLowerCase(Locale.ROOT) + ); } } } diff --git a/src/main/java/com/terraformersmc/modmenu/config/option/BooleanConfigOption.java b/src/main/java/com/terraformersmc/modmenu/config/option/BooleanConfigOption.java index b16de1810..13eaea11d 100644 --- a/src/main/java/com/terraformersmc/modmenu/config/option/BooleanConfigOption.java +++ b/src/main/java/com/terraformersmc/modmenu/config/option/BooleanConfigOption.java @@ -45,16 +45,25 @@ public boolean getDefaultValue() { } public Text getButtonText() { - return ScreenTexts.composeGenericOptionText(Text.translatable(translationKey), getValue() ? enabledText : disabledText); + return ScreenTexts.composeGenericOptionText(Text.translatable(translationKey), + getValue() ? enabledText : disabledText + ); } @Override public SimpleOption asOption() { if (enabledText != null && disabledText != null) { - return new SimpleOption<>(translationKey, SimpleOption.emptyTooltip(), - (text, value) -> value ? enabledText : disabledText, SimpleOption.BOOLEAN, getValue(), - newValue -> ConfigOptionStorage.setBoolean(key, newValue)); + return new SimpleOption<>(translationKey, + SimpleOption.emptyTooltip(), + (text, value) -> value ? enabledText : disabledText, + SimpleOption.BOOLEAN, + getValue(), + newValue -> ConfigOptionStorage.setBoolean(key, newValue) + ); } - return SimpleOption.ofBoolean(translationKey, getValue(), (value) -> ConfigOptionStorage.setBoolean(key, value)); + return SimpleOption.ofBoolean(translationKey, + getValue(), + (value) -> ConfigOptionStorage.setBoolean(key, value) + ); } } diff --git a/src/main/java/com/terraformersmc/modmenu/config/option/EnumConfigOption.java b/src/main/java/com/terraformersmc/modmenu/config/option/EnumConfigOption.java index 4780df44b..0d992bf4b 100644 --- a/src/main/java/com/terraformersmc/modmenu/config/option/EnumConfigOption.java +++ b/src/main/java/com/terraformersmc/modmenu/config/option/EnumConfigOption.java @@ -56,13 +56,17 @@ public Text getButtonText() { @Override public SimpleOption asOption() { - return new SimpleOption<>(translationKey, SimpleOption.emptyTooltip(), - (text, value) -> getValueText(this, value), - new SimpleOption.PotentialValuesBasedCallbacks<>(Arrays.asList(enumClass.getEnumConstants()), - Codec.STRING.xmap( - string -> Arrays.stream(enumClass.getEnumConstants()).filter(e -> e.name().toLowerCase().equals(string)).findAny().orElse(null), - newValue -> newValue.name().toLowerCase() - )), - getValue(), value -> ConfigOptionStorage.setEnum(key, value)); + return new SimpleOption<>(translationKey, + SimpleOption.emptyTooltip(), + (text, value) -> getValueText(this, value), + new SimpleOption.PotentialValuesBasedCallbacks<>(Arrays.asList(enumClass.getEnumConstants()), + Codec.STRING.xmap(string -> Arrays.stream(enumClass.getEnumConstants()) + .filter(e -> e.name().toLowerCase().equals(string)) + .findAny() + .orElse(null), newValue -> newValue.name().toLowerCase()) + ), + getValue(), + value -> ConfigOptionStorage.setEnum(key, value) + ); } } diff --git a/src/main/java/com/terraformersmc/modmenu/config/option/StringSetConfigOption.java b/src/main/java/com/terraformersmc/modmenu/config/option/StringSetConfigOption.java index 6fd7c5658..de82c3516 100644 --- a/src/main/java/com/terraformersmc/modmenu/config/option/StringSetConfigOption.java +++ b/src/main/java/com/terraformersmc/modmenu/config/option/StringSetConfigOption.java @@ -1,8 +1,7 @@ package com.terraformersmc.modmenu.config.option; -import net.minecraft.text.Text; - import com.terraformersmc.modmenu.util.TranslationUtil; +import net.minecraft.text.Text; import java.util.Set; diff --git a/src/main/java/com/terraformersmc/modmenu/event/ModMenuEventHandler.java b/src/main/java/com/terraformersmc/modmenu/event/ModMenuEventHandler.java index 52488cede..40da06fee 100644 --- a/src/main/java/com/terraformersmc/modmenu/event/ModMenuEventHandler.java +++ b/src/main/java/com/terraformersmc/modmenu/event/ModMenuEventHandler.java @@ -27,15 +27,16 @@ import java.util.List; public class ModMenuEventHandler { - public static final Identifier FABRIC_ICON_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, "textures/gui/mods_button.png"); + public static final Identifier FABRIC_ICON_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, + "textures/gui/mods_button.png" + ); private static KeyBinding MENU_KEY_BIND; public static void register() { - MENU_KEY_BIND = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.modmenu.open_menu", - InputUtil.Type.KEYSYM, - InputUtil.UNKNOWN_KEY.getCode(), - "key.categories.misc" + MENU_KEY_BIND = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.modmenu.open_menu", + InputUtil.Type.KEYSYM, + InputUtil.UNKNOWN_KEY.getCode(), + "key.categories.misc" )); ClientTickEvents.END_CLIENT_TICK.register(ModMenuEventHandler::onClientEndTick); @@ -67,7 +68,13 @@ private static void afterTitleScreenInit(Screen screen) { } if (buttonHasText(button, "menu.online")) { if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() == ModMenuConfig.TitleMenuButtonStyle.REPLACE_REALMS) { - buttons.set(i, new ModMenuButtonWidget(button.getX(), button.getY(), button.getWidth(), button.getHeight(), ModMenuApi.createModsButtonText(), screen)); + buttons.set(i, new ModMenuButtonWidget(button.getX(), + button.getY(), + button.getWidth(), + button.getHeight(), + ModMenuApi.createModsButtonText(), + screen + )); } else { if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() == ModMenuConfig.TitleMenuButtonStyle.SHRINK) { button.setWidth(98); @@ -83,11 +90,37 @@ private static void afterTitleScreenInit(Screen screen) { } if (modsButtonIndex != -1) { if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() == ModMenuConfig.TitleMenuButtonStyle.CLASSIC) { - buttons.add(modsButtonIndex, new ModMenuButtonWidget(screen.width / 2 - 100, buttonsY + spacing, 200, 20, ModMenuApi.createModsButtonText(), screen)); + buttons.add(modsButtonIndex, new ModMenuButtonWidget(screen.width / 2 - 100, + buttonsY + spacing, + 200, + 20, + ModMenuApi.createModsButtonText(), + screen + )); } else if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() == ModMenuConfig.TitleMenuButtonStyle.SHRINK) { - buttons.add(modsButtonIndex, new ModMenuButtonWidget(screen.width / 2 + 2, buttonsY, 98, 20, ModMenuApi.createModsButtonText(), screen)); + buttons.add(modsButtonIndex, + new ModMenuButtonWidget(screen.width / 2 + 2, + buttonsY, + 98, + 20, + ModMenuApi.createModsButtonText(), + screen + ) + ); } else if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() == ModMenuConfig.TitleMenuButtonStyle.ICON) { - buttons.add(modsButtonIndex, new UpdateCheckerTexturedButtonWidget(screen.width / 2 + 104, buttonsY, 20, 20, 0, 0, 20, FABRIC_ICON_BUTTON_LOCATION, 32, 64, button -> MinecraftClient.getInstance().setScreen(new ModsScreen(screen)), ModMenuApi.createModsButtonText())); + buttons.add(modsButtonIndex, new UpdateCheckerTexturedButtonWidget(screen.width / 2 + 104, + buttonsY, + 20, + 20, + 0, + 0, + 20, + FABRIC_ICON_BUTTON_LOCATION, + 32, + 64, + button -> MinecraftClient.getInstance().setScreen(new ModsScreen(screen)), + ModMenuApi.createModsButtonText() + )); } } } @@ -104,7 +137,8 @@ public static boolean buttonHasText(Widget widget, String translationKey) { if (widget instanceof ButtonWidget button) { Text text = button.getMessage(); TextContent textContent = text.getContent(); - return textContent instanceof TranslatableTextContent && ((TranslatableTextContent) textContent).getKey().equals(translationKey); + return textContent instanceof TranslatableTextContent && ((TranslatableTextContent) textContent).getKey() + .equals(translationKey); } return false; } @@ -112,7 +146,8 @@ public static boolean buttonHasText(Widget widget, String translationKey) { public static void shiftButtons(Widget widget, boolean shiftUp, int spacing) { if (shiftUp) { widget.setY(widget.getY() - spacing / 2); - } else if (!(widget instanceof ClickableWidget button && button.getMessage().equals(Text.translatable("title.credits")))) { + } else if (!(widget instanceof ClickableWidget button && button.getMessage() + .equals(Text.translatable("title.credits")))) { widget.setY(widget.getY() + spacing / 2); } } diff --git a/src/main/java/com/terraformersmc/modmenu/gui/ModsScreen.java b/src/main/java/com/terraformersmc/modmenu/gui/ModsScreen.java index ce4f25f78..faa95cfd0 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/ModsScreen.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/ModsScreen.java @@ -19,10 +19,10 @@ import net.minecraft.client.gui.screen.ConfirmLinkScreen; import net.minecraft.client.gui.screen.ConfirmScreen; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.toast.SystemToast; import net.minecraft.screen.ScreenTexts; @@ -44,8 +44,12 @@ import java.util.stream.Collectors; public class ModsScreen extends Screen { - private static final Identifier FILTERS_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, "textures/gui/filters_button.png"); - private static final Identifier CONFIGURE_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, "textures/gui/configure_button.png"); + private static final Identifier FILTERS_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, + "textures/gui/filters_button.png" + ); + private static final Identifier CONFIGURE_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, + "textures/gui/configure_button.png" + ); private static final Logger LOGGER = LoggerFactory.getLogger("Mod Menu | ModsScreen"); private final Screen previousScreen; @@ -120,7 +124,14 @@ protected void init() { this.rightPaneX = this.width - this.paneWidth; // Mod list (initialized early for updateFiltersX) - this.modList = new ModListWidget(this.client, this.paneWidth, this.height - paneY - 36, paneY, ModMenuConfig.COMPACT_LIST.getValue() ? 23 : 36, this.modList, this); + this.modList = new ModListWidget(this.client, + this.paneWidth, + this.height - paneY - 36, + paneY, + ModMenuConfig.COMPACT_LIST.getValue() ? 23 : 36, + this.modList, + this + ); this.modList.setX(0); // Search box @@ -130,7 +141,14 @@ protected void init() { this.searchBoxX = this.paneWidth / 2 - searchBoxWidth / 2 - filtersButtonSize / 2; - this.searchBox = new TextFieldWidget(this.textRenderer, this.searchBoxX, 22, searchBoxWidth, 20, this.searchBox, ModMenuScreenTexts.SEARCH); + this.searchBox = new TextFieldWidget(this.textRenderer, + this.searchBoxX, + 22, + searchBoxWidth, + 20, + this.searchBox, + ModMenuScreenTexts.SEARCH + ); this.searchBox.setChangedListener(text -> { this.modList.filter(text, false); }); @@ -148,14 +166,17 @@ protected void init() { this.updateFiltersX(); if (!ModMenuConfig.CONFIG_MODE.getValue()) { - this.filtersButton = LegacyTexturedButtonWidget.legacyTexturedBuilder(ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS, button -> { - this.setFilterOptionsShown(!this.filterOptionsShown); - }) - .position(this.paneWidth / 2 + searchBoxWidth / 2 - 20 / 2 + 2, 22) - .size(20, 20) - .uv(0, 0, 20) - .texture(FILTERS_BUTTON_LOCATION, 32, 64) - .build(); + this.filtersButton = LegacyTexturedButtonWidget.legacyTexturedBuilder( + ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS, + button -> { + this.setFilterOptionsShown(!this.filterOptionsShown); + } + ) + .position(this.paneWidth / 2 + searchBoxWidth / 2 - 20 / 2 + 2, 22) + .size(20, 20) + .uv(0, 0, 20) + .texture(FILTERS_BUTTON_LOCATION, 32, 64) + .build(); this.filtersButton.setTooltip(Tooltip.of(ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS)); } @@ -166,10 +187,7 @@ protected void init() { ModMenuConfigManager.save(); modList.reloadFilters(); button.setMessage(ModMenuConfig.SORTING.getButtonText()); - }) - .position(this.filtersX, 45) - .size(sortingWidth, 20) - .build(); + }).position(this.filtersX, 45).size(sortingWidth, 20).build(); // Show libraries button this.librariesButton = ButtonWidget.builder(librariesText, button -> { @@ -177,27 +195,24 @@ protected void init() { ModMenuConfigManager.save(); modList.reloadFilters(); button.setMessage(ModMenuConfig.SHOW_LIBRARIES.getButtonText()); - }) - .position(this.filtersX + sortingWidth + 2, 45) - .size(librariesWidth, 20) - .build(); + }).position(this.filtersX + sortingWidth + 2, 45).size(librariesWidth, 20).build(); // Configure button if (!ModMenuConfig.HIDE_CONFIG_BUTTONS.getValue()) { this.configureButton = LegacyTexturedButtonWidget.legacyTexturedBuilder(ScreenTexts.EMPTY, button -> { - final String id = Objects.requireNonNull(selected).getMod().getId(); - if (modHasConfigScreen.get(id)) { - Screen configScreen = ModMenu.getConfigScreen(id, this); - client.setScreen(configScreen); - } else { - button.active = false; - } - }) - .position(width - 24, RIGHT_PANE_Y) - .size(20, 20) - .uv(0, 0, 20) - .texture(CONFIGURE_BUTTON_LOCATION, 32, 64) - .build(); + final String id = Objects.requireNonNull(selected).getMod().getId(); + if (modHasConfigScreen.get(id)) { + Screen configScreen = ModMenu.getConfigScreen(id, this); + client.setScreen(configScreen); + } else { + button.active = false; + } + }) + .position(width - 24, RIGHT_PANE_Y) + .size(20, 20) + .uv(0, 0, 20) + .texture(CONFIGURE_BUTTON_LOCATION, 32, 64) + .build(); } // Website button @@ -205,55 +220,57 @@ protected void init() { int cappedButtonWidth = Math.min(urlButtonWidths, 200); this.websiteButton = ButtonWidget.builder(ModMenuScreenTexts.WEBSITE, button -> { - final Mod mod = Objects.requireNonNull(selected).getMod(); - this.client.setScreen(new ConfirmLinkScreen(confirmed -> { - if (confirmed) { - Util.getOperatingSystem().open(mod.getWebsite()); - } - this.client.setScreen(this); - }, mod.getWebsite(), false)); - }) - .position(this.rightPaneX + (urlButtonWidths / 2) - (cappedButtonWidth / 2), RIGHT_PANE_Y + 36) - .size(Math.min(urlButtonWidths, 200), 20) - .build(); + final Mod mod = Objects.requireNonNull(selected).getMod(); + this.client.setScreen(new ConfirmLinkScreen(confirmed -> { + if (confirmed) { + Util.getOperatingSystem().open(mod.getWebsite()); + } + this.client.setScreen(this); + }, mod.getWebsite(), false)); + }) + .position(this.rightPaneX + (urlButtonWidths / 2) - (cappedButtonWidth / 2), RIGHT_PANE_Y + 36) + .size(Math.min(urlButtonWidths, 200), 20) + .build(); // Issues button this.issuesButton = ButtonWidget.builder(ModMenuScreenTexts.ISSUES, button -> { - final Mod mod = Objects.requireNonNull(selected).getMod(); - this.client.setScreen(new ConfirmLinkScreen(confirmed -> { - if (confirmed) { - Util.getOperatingSystem().open(mod.getIssueTracker()); - } - this.client.setScreen(this); - }, mod.getIssueTracker(), false)); - }) - .position(this.rightPaneX + urlButtonWidths + 4 + (urlButtonWidths / 2) - (cappedButtonWidth / 2), RIGHT_PANE_Y + 36) - .size(Math.min(urlButtonWidths, 200), 20) - .build(); + final Mod mod = Objects.requireNonNull(selected).getMod(); + this.client.setScreen(new ConfirmLinkScreen(confirmed -> { + if (confirmed) { + Util.getOperatingSystem().open(mod.getIssueTracker()); + } + this.client.setScreen(this); + }, mod.getIssueTracker(), false)); + }) + .position(this.rightPaneX + urlButtonWidths + 4 + (urlButtonWidths / 2) - (cappedButtonWidth / 2), + RIGHT_PANE_Y + 36 + ) + .size(Math.min(urlButtonWidths, 200), 20) + .build(); // Description list - this.descriptionListWidget = new DescriptionListWidget(this.client, this.paneWidth, this.height - RIGHT_PANE_Y - 96, RIGHT_PANE_Y + 60, textRenderer.fontHeight + 1, this); + this.descriptionListWidget = new DescriptionListWidget(this.client, + this.paneWidth, + this.height - RIGHT_PANE_Y - 96, + RIGHT_PANE_Y + 60, + textRenderer.fontHeight + 1, + this + ); this.descriptionListWidget.setX(this.rightPaneX); // Mods folder button this.modsFolderButton = ButtonWidget.builder(ModMenuScreenTexts.MODS_FOLDER, button -> { Util.getOperatingSystem().open(FabricLoader.getInstance().getGameDir().resolve("mods").toUri()); - }) - .position(this.width / 2 - 154, this.height - 28) - .size(150, 20) - .build(); + }).position(this.width / 2 - 154, this.height - 28).size(150, 20).build(); // Done button this.doneButton = ButtonWidget.builder(ScreenTexts.DONE, button -> { client.setScreen(previousScreen); - }) - .position(this.width / 2 + 4, this.height - 28) - .size(150, 20) - .build(); + }).position(this.width / 2 + 4, this.height - 28).size(150, 20).build(); // Initialize data modList.reloadFilters(); - this.setFilterOptionsShown(this.keepFilterOptionsShown ? this.filterOptionsShown : false); + this.setFilterOptionsShown(this.keepFilterOptionsShown && this.filterOptionsShown); // Add children this.addSelectableChild(this.searchBox); @@ -283,7 +300,10 @@ protected void init() { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - return super.keyPressed(keyCode, scanCode, modifiers) || this.searchBox.keyPressed(keyCode, scanCode, modifiers); + return super.keyPressed(keyCode, scanCode, modifiers) || this.searchBox.keyPressed(keyCode, + scanCode, + modifiers + ); } @Override @@ -303,25 +323,71 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta) RenderSystem.disableBlend(); DrawContext.drawCenteredTextWithShadow(this.textRenderer, this.title, this.modList.getWidth() / 2, 8, 16777215); if (!ModMenuConfig.DISABLE_DRAG_AND_DROP.getValue()) { - DrawContext.drawCenteredTextWithShadow(this.textRenderer, ModMenuScreenTexts.DROP_INFO_LINE_1, this.width - this.modList.getWidth() / 2, RIGHT_PANE_Y / 2 - client.textRenderer.fontHeight - 1, Formatting.GRAY.getColorValue()); - DrawContext.drawCenteredTextWithShadow(this.textRenderer, ModMenuScreenTexts.DROP_INFO_LINE_2, this.width - this.modList.getWidth() / 2, RIGHT_PANE_Y / 2 + 1, Formatting.GRAY.getColorValue()); + DrawContext.drawCenteredTextWithShadow(this.textRenderer, + ModMenuScreenTexts.DROP_INFO_LINE_1, + this.width - this.modList.getWidth() / 2, + RIGHT_PANE_Y / 2 - client.textRenderer.fontHeight - 1, + Formatting.GRAY.getColorValue() + ); + DrawContext.drawCenteredTextWithShadow(this.textRenderer, + ModMenuScreenTexts.DROP_INFO_LINE_2, + this.width - this.modList.getWidth() / 2, + RIGHT_PANE_Y / 2 + 1, + Formatting.GRAY.getColorValue() + ); } if (!ModMenuConfig.CONFIG_MODE.getValue()) { Text fullModCount = this.computeModCountText(true); if (!ModMenuConfig.CONFIG_MODE.getValue() && this.updateFiltersX()) { if (this.filterOptionsShown) { if (!ModMenuConfig.SHOW_LIBRARIES.getValue() || textRenderer.getWidth(fullModCount) <= this.filtersX - 5) { - DrawContext.drawText(textRenderer, fullModCount.asOrderedText(), this.searchBoxX, 52, 0xFFFFFF, true); + DrawContext.drawText(textRenderer, + fullModCount.asOrderedText(), + this.searchBoxX, + 52, + 0xFFFFFF, + true + ); } else { - DrawContext.drawText(textRenderer, computeModCountText(false).asOrderedText(), this.searchBoxX, 46, 0xFFFFFF, true); - DrawContext.drawText(textRenderer, computeLibraryCountText().asOrderedText(), this.searchBoxX, 57, 0xFFFFFF, true); + DrawContext.drawText(textRenderer, + computeModCountText(false).asOrderedText(), + this.searchBoxX, + 46, + 0xFFFFFF, + true + ); + DrawContext.drawText(textRenderer, + computeLibraryCountText().asOrderedText(), + this.searchBoxX, + 57, + 0xFFFFFF, + true + ); } } else { if (!ModMenuConfig.SHOW_LIBRARIES.getValue() || textRenderer.getWidth(fullModCount) <= modList.getWidth() - 5) { - DrawContext.drawText(textRenderer, fullModCount.asOrderedText(), this.searchBoxX, 52, 0xFFFFFF, true); + DrawContext.drawText(textRenderer, + fullModCount.asOrderedText(), + this.searchBoxX, + 52, + 0xFFFFFF, + true + ); } else { - DrawContext.drawText(textRenderer, computeModCountText(false).asOrderedText(), this.searchBoxX, 46, 0xFFFFFF, true); - DrawContext.drawText(textRenderer, computeLibraryCountText().asOrderedText(), this.searchBoxX, 57, 0xFFFFFF, true); + DrawContext.drawText(textRenderer, + computeModCountText(false).asOrderedText(), + this.searchBoxX, + 46, + 0xFFFFFF, + true + ); + DrawContext.drawText(textRenderer, + computeLibraryCountText().asOrderedText(), + this.searchBoxX, + 57, + 0xFFFFFF, + true + ); } } } @@ -343,21 +409,42 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta) int maxNameWidth = this.width - (x + imageOffset); if (textRenderer.getWidth(name) > maxNameWidth) { StringVisitable ellipsis = StringVisitable.plain("..."); - trimmedName = StringVisitable.concat(textRenderer.trimToWidth(name, maxNameWidth - textRenderer.getWidth(ellipsis)), ellipsis); + trimmedName = StringVisitable.concat(textRenderer.trimToWidth( + name, + maxNameWidth - textRenderer.getWidth(ellipsis) + ), ellipsis); } - DrawContext.drawText(textRenderer, Language.getInstance().reorder(trimmedName), x + imageOffset, RIGHT_PANE_Y + 1, 0xFFFFFF, true); - if (mouseX > x + imageOffset && mouseY > RIGHT_PANE_Y + 1 && mouseY < RIGHT_PANE_Y + 1 + textRenderer.fontHeight && mouseX < x + imageOffset + textRenderer.getWidth(trimmedName)) { + DrawContext.drawText(textRenderer, + Language.getInstance().reorder(trimmedName), + x + imageOffset, + RIGHT_PANE_Y + 1, + 0xFFFFFF, + true + ); + if (mouseX > x + imageOffset && mouseY > RIGHT_PANE_Y + 1 && mouseY < RIGHT_PANE_Y + 1 + textRenderer.fontHeight && mouseX < x + imageOffset + textRenderer.getWidth( + trimmedName)) { this.setTooltip(ModMenuScreenTexts.modIdTooltip(mod.getId())); } if (this.init || modBadgeRenderer == null || modBadgeRenderer.getMod() != mod) { - modBadgeRenderer = new ModBadgeRenderer(x + imageOffset + this.client.textRenderer.getWidth(trimmedName) + 2, RIGHT_PANE_Y, width - 28, selectedEntry.mod, this); + modBadgeRenderer = new ModBadgeRenderer(x + imageOffset + this.client.textRenderer.getWidth(trimmedName) + 2, + RIGHT_PANE_Y, + width - 28, + selectedEntry.mod, + this + ); this.init = false; } if (!ModMenuConfig.HIDE_BADGES.getValue()) { modBadgeRenderer.draw(DrawContext, mouseX, mouseY); } if (mod.isReal()) { - DrawContext.drawText(textRenderer, mod.getPrefixedVersion(), x + imageOffset, RIGHT_PANE_Y + 2 + lineSpacing, 0x808080, true); + DrawContext.drawText(textRenderer, + mod.getPrefixedVersion(), + x + imageOffset, + RIGHT_PANE_Y + 2 + lineSpacing, + 0x808080, + true + ); } String authors; List names = mod.getAuthors(); @@ -368,16 +455,31 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta) } else { authors = names.get(0); } - DrawingUtil.drawWrappedString(DrawContext, I18n.translate("modmenu.authorPrefix", authors), x + imageOffset, RIGHT_PANE_Y + 2 + lineSpacing * 2, this.paneWidth - imageOffset - 4, 1, 0x808080); + DrawingUtil.drawWrappedString(DrawContext, + I18n.translate("modmenu.authorPrefix", authors), + x + imageOffset, + RIGHT_PANE_Y + 2 + lineSpacing * 2, + this.paneWidth - imageOffset - 4, + 1, + 0x808080 + ); } } } private Text computeModCountText(boolean includeLibs) { - int[] rootMods = formatModCount(ModMenu.ROOT_MODS.values().stream().filter(mod -> !mod.isHidden() && !mod.getBadges().contains(Mod.Badge.LIBRARY)).map(Mod::getId).collect(Collectors.toSet())); + int[] rootMods = formatModCount(ModMenu.ROOT_MODS.values() + .stream() + .filter(mod -> !mod.isHidden() && !mod.getBadges().contains(Mod.Badge.LIBRARY)) + .map(Mod::getId) + .collect(Collectors.toSet())); if (includeLibs && ModMenuConfig.SHOW_LIBRARIES.getValue()) { - int[] rootLibs = formatModCount(ModMenu.ROOT_MODS.values().stream().filter(mod -> !mod.isHidden() && mod.getBadges().contains(Mod.Badge.LIBRARY)).map(Mod::getId).collect(Collectors.toSet())); + int[] rootLibs = formatModCount(ModMenu.ROOT_MODS.values() + .stream() + .filter(mod -> !mod.isHidden() && mod.getBadges().contains(Mod.Badge.LIBRARY)) + .map(Mod::getId) + .collect(Collectors.toSet())); return TranslationUtil.translateNumeric("modmenu.showingModsLibraries", rootMods, rootLibs); } else { return TranslationUtil.translateNumeric("modmenu.showingMods", rootMods); @@ -386,7 +488,11 @@ private Text computeModCountText(boolean includeLibs) { private Text computeLibraryCountText() { if (ModMenuConfig.SHOW_LIBRARIES.getValue()) { - int[] rootLibs = formatModCount(ModMenu.ROOT_MODS.values().stream().filter(mod -> !mod.isHidden() && mod.getBadges().contains(Mod.Badge.LIBRARY)).map(Mod::getId).collect(Collectors.toSet())); + int[] rootLibs = formatModCount(ModMenu.ROOT_MODS.values() + .stream() + .filter(mod -> !mod.isHidden() && mod.getBadges().contains(Mod.Badge.LIBRARY)) + .map(Mod::getId) + .collect(Collectors.toSet())); return TranslationUtil.translateNumeric("modmenu.showingLibraries", rootLibs); } else { return Text.literal(null); @@ -397,9 +503,9 @@ private int[] formatModCount(Set set) { int visible = this.modList.getDisplayedCountFor(set); int total = set.size(); if (visible == total) { - return new int[]{total}; + return new int[]{ total }; } - return new int[]{visible, total}; + return new int[]{ visible, total }; } @Override @@ -427,7 +533,8 @@ public void updateSelectedEntry(ModListEntry entry) { String modId = selected.getMod().getId(); this.configureButton.active = modHasConfigScreen.get(modId); - this.configureButton.visible = selected != null && modHasConfigScreen.get(modId) || modScreenErrors.containsKey(modId); + this.configureButton.visible = selected != null && modHasConfigScreen.get(modId) || modScreenErrors.containsKey( + modId); if (modScreenErrors.containsKey(modId)) { Throwable e = modScreenErrors.get(modId); @@ -458,7 +565,8 @@ public String getSearchInput() { } private boolean updateFiltersX() { - if ((this.filtersWidth + textRenderer.getWidth(this.computeModCountText(true)) + 20) >= this.searchRowWidth && ((this.filtersWidth + textRenderer.getWidth(computeModCountText(false)) + 20) >= this.searchRowWidth || (this.filtersWidth + textRenderer.getWidth(this.computeLibraryCountText()) + 20) >= this.searchRowWidth)) { + if ((this.filtersWidth + textRenderer.getWidth(this.computeModCountText(true)) + 20) >= this.searchRowWidth && ((this.filtersWidth + textRenderer.getWidth( + computeModCountText(false)) + 20) >= this.searchRowWidth || (this.filtersWidth + textRenderer.getWidth(this.computeLibraryCountText()) + 20) >= this.searchRowWidth)) { this.filtersX = this.paneWidth / 2 - this.filtersWidth / 2; return !filterOptionsShown; } else { @@ -472,18 +580,13 @@ public void filesDragged(List paths) { Path modsDirectory = FabricLoader.getInstance().getGameDir().resolve("mods"); // Filter out none mods - List mods = paths.stream() - .filter(ModsScreen::isFabricMod) - .collect(Collectors.toList()); + List mods = paths.stream().filter(ModsScreen::isFabricMod).collect(Collectors.toList()); if (mods.isEmpty()) { return; } - String modList = mods.stream() - .map(Path::getFileName) - .map(Path::toString) - .collect(Collectors.joining(", ")); + String modList = mods.stream().map(Path::getFileName).map(Path::toString).collect(Collectors.joining(", ")); this.client.setScreen(new ConfirmScreen((value) -> { if (value) { @@ -493,7 +596,10 @@ public void filesDragged(List paths) { try { Files.copy(path, modsDirectory.resolve(path.getFileName())); } catch (IOException e) { - LOGGER.warn("Failed to copy mod from {} to {}", path, modsDirectory.resolve(path.getFileName())); + LOGGER.warn("Failed to copy mod from {} to {}", + path, + modsDirectory.resolve(path.getFileName()) + ); SystemToast.addPackCopyFailure(client, path.toString()); allSuccessful = false; break; @@ -501,7 +607,11 @@ public void filesDragged(List paths) { } if (allSuccessful) { - SystemToast.add(client.getToastManager(), SystemToast.Type.PERIODIC_NOTIFICATION, ModMenuScreenTexts.DROP_SUCCESSFUL_LINE_1, ModMenuScreenTexts.DROP_SUCCESSFUL_LINE_1); + SystemToast.add(client.getToastManager(), + SystemToast.Type.PERIODIC_NOTIFICATION, + ModMenuScreenTexts.DROP_SUCCESSFUL_LINE_1, + ModMenuScreenTexts.DROP_SUCCESSFUL_LINE_1 + ); } } this.client.setScreen(this); diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java index 6fb0add21..5cc521ab0 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java @@ -6,9 +6,7 @@ import com.terraformersmc.modmenu.config.ModMenuConfig; import com.terraformersmc.modmenu.gui.ModsScreen; import com.terraformersmc.modmenu.gui.widget.entries.ModListEntry; -import com.terraformersmc.modmenu.util.VersionUtil; import com.terraformersmc.modmenu.util.mod.Mod; -import com.terraformersmc.modmenu.util.mod.ModrinthUpdateInfo; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; @@ -54,12 +52,14 @@ public class DescriptionListWidget extends EntryListWidget { int indent = 8; for (OrderedText line : textRenderer.wrapLines(Text.translatable(key) - .formatted(Formatting.BLUE) - .formatted(Formatting.UNDERLINE), wrapWidth - 16)) { + .formatted(Formatting.BLUE) + .formatted(Formatting.UNDERLINE), + wrapWidth - 16 + )) { children().add(new LinkEntry(line, value, indent)); indent = 16; } @@ -234,7 +236,8 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de var roleName = role.getKey(); for (var line : textRenderer.wrapLines(this.creditsRoleText(roleName), - wrapWidth - 16)) { + wrapWidth - 16 + )) { children().add(new DescriptionEntry(line, indent)); indent = 16; } @@ -262,17 +265,17 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de BufferBuilder bufferBuilder; BuiltBuffer builtBuffer; -// { -// RenderSystem.setShader(GameRenderer::getPositionTexColorProgram); -// RenderSystem.setShaderTexture(0, Screen.OPTIONS_BACKGROUND_TEXTURE); -// RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); -// bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); -// bufferBuilder.vertex(this.getX(), this.getBottom(), 0.0D).texture(this.getX() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); -// bufferBuilder.vertex(this.getRight(), this.getBottom(), 0.0D).texture(this.getRight() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); -// bufferBuilder.vertex(this.getRight(), this.getY(), 0.0D).texture(this.getRight() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); -// bufferBuilder.vertex(this.getX(), this.getY(), 0.0D).texture(this.getX() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); -// tessellator.draw(); -// } + // { + // RenderSystem.setShader(GameRenderer::getPositionTexColorProgram); + // RenderSystem.setShaderTexture(0, Screen.OPTIONS_BACKGROUND_TEXTURE); + // RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + // bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); + // bufferBuilder.vertex(this.getX(), this.getBottom(), 0.0D).texture(this.getX() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); + // bufferBuilder.vertex(this.getRight(), this.getBottom(), 0.0D).texture(this.getRight() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); + // bufferBuilder.vertex(this.getRight(), this.getY(), 0.0D).texture(this.getRight() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); + // bufferBuilder.vertex(this.getX(), this.getY(), 0.0D).texture(this.getX() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255); + // tessellator.draw(); + // } this.enableScissor(DrawContext); super.renderList(DrawContext, mouseX, mouseY, delta); @@ -284,7 +287,8 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, - GlStateManager.DstFactor.ONE); + GlStateManager.DstFactor.ONE + ); RenderSystem.setShader(GameRenderer::getPositionColorProgram); bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); @@ -372,7 +376,7 @@ public void renderScrollBar(BufferBuilder bufferBuilder, Tessellator tessellator private Text creditsRoleText(String roleName) { // Replace spaces and dashes in role names with underscores if they exist // Notably Quilted Fabric API does this with FabricMC as "Upstream Owner" - var translationKey = roleName.replaceAll("[\s-]", "_").toLowerCase(); + var translationKey = roleName.replaceAll("[ -]", "_").toLowerCase(); // Add an s to the default untranslated string if it ends in r since this // Fixes common role names people use in English (e.g. Author -> Authors) @@ -402,16 +406,18 @@ public DescriptionEntry setUpdateTextEntry() { } @Override - public void render(DrawContext DrawContext, - int index, - int y, - int x, - int itemWidth, - int itemHeight, - int mouseX, - int mouseY, - boolean isSelected, - float delta) { + public void render( + DrawContext DrawContext, + int index, + int y, + int x, + int itemWidth, + int itemHeight, + int mouseX, + int mouseY, + boolean isSelected, + float delta + ) { if (updateTextEntry) { UpdateAvailableBadge.renderBadge(DrawContext, x + indent, y); x += 11; diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/LegacyTexturedButtonWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/LegacyTexturedButtonWidget.java index d43883ba5..df81333d0 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/LegacyTexturedButtonWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/LegacyTexturedButtonWidget.java @@ -16,7 +16,20 @@ public class LegacyTexturedButtonWidget extends TexturedButtonWidget { private final int textureWidth; private final int textureHeight; - public LegacyTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) { + public LegacyTexturedButtonWidget( + int x, + int y, + int width, + int height, + int u, + int v, + int hoveredVOffset, + Identifier texture, + int textureWidth, + int textureHeight, + ButtonWidget.PressAction pressAction, + Text message + ) { super(x, y, width, height, null, pressAction, message); this.u = u; @@ -39,7 +52,16 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float delt v += this.hoveredVOffset; } - context.drawTexture(this.texture, this.getX(), this.getY(), this.u, v, this.width, this.height, this.textureWidth, this.textureHeight); + context.drawTexture(this.texture, + this.getX(), + this.getY(), + this.u, + v, + this.width, + this.height, + this.textureWidth, + this.textureHeight + ); } public static Builder legacyTexturedBuilder(Text message, ButtonWidget.PressAction onPress) { @@ -103,7 +125,19 @@ public Builder texture(Identifier texture, int textureWidth, int textureHeight) } public LegacyTexturedButtonWidget build() { - return new LegacyTexturedButtonWidget(this.x, this.y, this.width, this.height, this.u, this.v, this.hoveredVOffset, this.texture, this.textureWidth, this.textureHeight, this.onPress, this.message); + return new LegacyTexturedButtonWidget(this.x, + this.y, + this.width, + this.height, + this.u, + this.v, + this.hoveredVOffset, + this.texture, + this.textureWidth, + this.textureHeight, + this.onPress, + this.message + ); } } } diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/ModListWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/ModListWidget.java index c6e809e70..df695e8f2 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/ModListWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/ModListWidget.java @@ -9,8 +9,8 @@ import com.terraformersmc.modmenu.gui.widget.entries.ModListEntry; import com.terraformersmc.modmenu.gui.widget.entries.ParentEntry; import com.terraformersmc.modmenu.util.mod.Mod; -import com.terraformersmc.modmenu.util.mod.fabric.FabricIconHandler; import com.terraformersmc.modmenu.util.mod.ModSearch; +import com.terraformersmc.modmenu.util.mod.fabric.FabricIconHandler; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; @@ -32,7 +32,15 @@ public class ModListWidget extends AlwaysSelectedEntryListWidget i private boolean scrolling; private final FabricIconHandler iconHandler = new FabricIconHandler(); - public ModListWidget(MinecraftClient client, int width, int height, int y, int itemHeight, ModListWidget list, ModsScreen parent) { + public ModListWidget( + MinecraftClient client, + int width, + int height, + int y, + int itemHeight, + ModListWidget list, + ModsScreen parent + ) { super(client, width, height, y, itemHeight); this.parent = parent; if (list != null) { @@ -47,7 +55,10 @@ public void setScrollAmount(double amount) { if (denominator <= 0) { parent.updateScrollPercent(0); } else { - parent.updateScrollPercent(getScrollAmount() / Math.max(0, this.getMaxPosition() - (this.getBottom() - this.getY() - 4))); + parent.updateScrollPercent(getScrollAmount() / Math.max( + 0, + this.getMaxPosition() - (this.getBottom() - this.getY() - 4) + )); } } @@ -60,7 +71,8 @@ public void select(ModListEntry entry) { this.setSelected(entry); if (entry != null) { Mod mod = entry.getMod(); - this.client.getNarratorManager().narrate(Text.translatable("narrator.select", mod.getTranslatedName()).getString()); + this.client.getNarratorManager() + .narrate(Text.translatable("narrator.select", mod.getTranslatedName()).getString()); } } @@ -115,7 +127,8 @@ private boolean hasVisibleChildMods(Mod parent) { List children = ModMenu.PARENT_MAP.get(parent); boolean hideLibraries = !ModMenuConfig.SHOW_LIBRARIES.getValue(); - return !children.stream().allMatch(child -> child.isHidden() || hideLibraries && child.getBadges().contains(Mod.Badge.LIBRARY)); + return !children.stream() + .allMatch(child -> child.isHidden() || hideLibraries && child.getBadges().contains(Mod.Badge.LIBRARY)); } private void filter(String searchTerm, boolean refresh, boolean search) { @@ -135,7 +148,7 @@ private void filter(String searchTerm, boolean refresh, boolean search) { if (DEBUG) { mods = new ArrayList<>(mods); -// mods.addAll(TestModContainer.getTestModContainers()); + // mods.addAll(TestModContainer.getTestModContainers()); } if (this.mods == null || refresh) { @@ -165,7 +178,11 @@ private void filter(String searchTerm, boolean refresh, boolean search) { if (this.parent.showModChildren.contains(modId)) { List validChildren = ModSearch.search(this.parent, searchTerm, children); for (Mod child : validChildren) { - this.addEntry(new ChildEntry(child, parent, this, validChildren.indexOf(child) == validChildren.size() - 1)); + this.addEntry(new ChildEntry(child, + parent, + this, + validChildren.indexOf(child) == validChildren.size() - 1 + )); } } } else { @@ -175,7 +192,8 @@ private void filter(String searchTerm, boolean refresh, boolean search) { } } - if (parent.getSelectedEntry() != null && !children().isEmpty() || this.getSelectedOrNull() != null && getSelectedOrNull().getMod() != parent.getSelectedEntry().getMod()) { + if (parent.getSelectedEntry() != null && !children().isEmpty() || this.getSelectedOrNull() != null && getSelectedOrNull().getMod() != parent.getSelectedEntry() + .getMod()) { for (ModListEntry entry : children()) { if (entry.getMod().equals(parent.getSelectedEntry().getMod())) { setSelected(entry); @@ -244,7 +262,17 @@ protected void renderList(DrawContext DrawContext, int mouseX, int mouseY, float } entryLeft = this.getRowLeft(); - entry.render(DrawContext, index, entryTop, entryLeft, rowWidth, entryHeight, mouseX, mouseY, this.isMouseOver(mouseX, mouseY) && Objects.equals(this.getEntryAtPos(mouseX, mouseY), entry), delta); + entry.render(DrawContext, + index, + entryTop, + entryLeft, + rowWidth, + entryHeight, + mouseX, + mouseY, + this.isMouseOver(mouseX, mouseY) && Objects.equals(this.getEntryAtPos(mouseX, mouseY), entry), + delta + ); } } } @@ -272,7 +300,9 @@ public boolean mouseClicked(double double_1, double double_2, int int_1) { this.setDragging(true); return true; } - } else if (int_1 == 0 && this.clickedHeader((int) (double_1 - (double) (this.getX() + this.width / 2 - this.getRowWidth() / 2)), (int) (double_2 - (double) this.getY()) + (int) this.getScrollAmount() - 4)) { + } else if (int_1 == 0 && this.clickedHeader((int) (double_1 - (double) (this.getX() + this.width / 2 - this.getRowWidth() / 2)), + (int) (double_2 - (double) this.getY()) + (int) this.getScrollAmount() - 4 + )) { return true; } @@ -293,7 +323,9 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { public final ModListEntry getEntryAtPos(double x, double y) { int int_5 = MathHelper.floor(y - (double) this.getY()) - this.headerHeight + (int) this.getScrollAmount() - 4; int index = int_5 / this.itemHeight; - return x < (double) this.getScrollbarX() && x >= (double) getRowLeft() && x <= (double) (getRowLeft() + getRowWidth()) && index >= 0 && int_5 >= 0 && index < this.getEntryCount() ? this.children().get(index) : null; + return x < (double) this.getScrollbarX() && x >= (double) getRowLeft() && x <= (double) (getRowLeft() + getRowWidth()) && index >= 0 && int_5 >= 0 && index < this.getEntryCount() ? + this.children().get(index) : + null; } @Override diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/ModMenuButtonWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/ModMenuButtonWidget.java index 8d88a2b4e..7fd7746e5 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/ModMenuButtonWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/ModMenuButtonWidget.java @@ -7,19 +7,28 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; public class ModMenuButtonWidget extends ButtonWidget { public ModMenuButtonWidget(int x, int y, int width, int height, Text text, Screen screen) { - super(x, y, width, height, text, button -> MinecraftClient.getInstance().setScreen(new ModsScreen(screen)), ButtonWidget.DEFAULT_NARRATION_SUPPLIER); + super(x, + y, + width, + height, + text, + button -> MinecraftClient.getInstance().setScreen(new ModsScreen(screen)), + ButtonWidget.DEFAULT_NARRATION_SUPPLIER + ); } @Override public void renderWidget(DrawContext DrawContext, int mouseX, int mouseY, float delta) { super.renderWidget(DrawContext, mouseX, mouseY, delta); if (ModMenuConfig.BUTTON_UPDATE_BADGE.getValue() && ModMenu.areModUpdatesAvailable()) { - UpdateAvailableBadge.renderBadge(DrawContext, this.width + this.getX() - 16, this.height / 2 + this.getY() - 4); + UpdateAvailableBadge.renderBadge(DrawContext, + this.width + this.getX() - 16, + this.height / 2 + this.getY() - 4 + ); } } } diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/UpdateCheckerTexturedButtonWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/UpdateCheckerTexturedButtonWidget.java index d8ded470a..7e254e3d9 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/UpdateCheckerTexturedButtonWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/UpdateCheckerTexturedButtonWidget.java @@ -5,12 +5,24 @@ import com.terraformersmc.modmenu.config.ModMenuConfig; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; public class UpdateCheckerTexturedButtonWidget extends LegacyTexturedButtonWidget { - public UpdateCheckerTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) { + public UpdateCheckerTexturedButtonWidget( + int x, + int y, + int width, + int height, + int u, + int v, + int hoveredVOffset, + Identifier texture, + int textureWidth, + int textureHeight, + ButtonWidget.PressAction pressAction, + Text message + ) { super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, message); } diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ChildEntry.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ChildEntry.java index c8f04294e..3dcced89e 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ChildEntry.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ChildEntry.java @@ -6,8 +6,8 @@ import org.lwjgl.glfw.GLFW; public class ChildEntry extends ModListEntry { - private boolean bottomChild; - private ParentEntry parent; + private final boolean bottomChild; + private final ParentEntry parent; public ChildEntry(Mod mod, ParentEntry parent, ModListWidget list, boolean bottomChild) { super(mod, list); @@ -16,7 +16,18 @@ public ChildEntry(Mod mod, ParentEntry parent, ModListWidget list, boolean botto } @Override - public void render(DrawContext DrawContext, int index, int y, int x, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean isSelected, float delta) { + public void render( + DrawContext DrawContext, + int index, + int y, + int x, + int rowWidth, + int rowHeight, + int mouseX, + int mouseY, + boolean isSelected, + float delta + ) { super.render(DrawContext, index, y, x, rowWidth, rowHeight, mouseX, mouseY, isSelected, delta); x += 4; int color = 0xFFA0A0A0; diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ModListEntry.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ModListEntry.java index ce82e83d9..724b1bc12 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ModListEntry.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ModListEntry.java @@ -22,7 +22,9 @@ public class ModListEntry extends AlwaysSelectedEntryListWidget.Entry { public static final Identifier UNKNOWN_ICON = Identifier.ofVanilla("textures/misc/unknown_pack.png"); - private static final Identifier MOD_CONFIGURATION_ICON = Identifier.of(ModMenu.MOD_ID, "textures/gui/mod_configuration.png"); + private static final Identifier MOD_CONFIGURATION_ICON = Identifier.of(ModMenu.MOD_ID, + "textures/gui/mod_configuration.png" + ); private static final Identifier ERROR_ICON = Identifier.ofVanilla("world_list/error"); private static final Identifier ERROR_HIGHLIGHTED_ICON = Identifier.ofVanilla("world_list/error_highlighted"); @@ -46,7 +48,18 @@ public Text getNarration() { } @Override - public void render(DrawContext DrawContext, int index, int y, int x, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float delta) { + public void render( + DrawContext DrawContext, + int index, + int y, + int x, + int rowWidth, + int rowHeight, + int mouseX, + int mouseY, + boolean hovered, + float delta + ) { x += getXOffset(); rowWidth -= getXOffset(); int iconSize = ModMenuConfig.COMPACT_LIST.getValue() ? COMPACT_ICON_SIZE : FULL_ICON_SIZE; @@ -64,38 +77,88 @@ public void render(DrawContext DrawContext, int index, int y, int x, int rowWidt TextRenderer font = this.client.textRenderer; if (font.getWidth(name) > maxNameWidth) { StringVisitable ellipsis = StringVisitable.plain("..."); - trimmedName = StringVisitable.concat(font.trimToWidth(name, maxNameWidth - font.getWidth(ellipsis)), ellipsis); + trimmedName = StringVisitable.concat(font.trimToWidth(name, maxNameWidth - font.getWidth(ellipsis)), + ellipsis + ); } - DrawContext.drawText(font, Language.getInstance().reorder(trimmedName), x + iconSize + 3, y + 1, 0xFFFFFF, true); + DrawContext.drawText(font, + Language.getInstance().reorder(trimmedName), + x + iconSize + 3, + y + 1, + 0xFFFFFF, + true + ); var updateBadgeXOffset = 0; - if (ModMenuConfig.UPDATE_CHECKER.getValue() && !ModMenuConfig.DISABLE_UPDATE_CHECKER.getValue().contains(modId) && (mod.hasUpdate() || mod.getChildHasUpdate())) { + if (ModMenuConfig.UPDATE_CHECKER.getValue() && !ModMenuConfig.DISABLE_UPDATE_CHECKER.getValue() + .contains(modId) && (mod.hasUpdate() || mod.getChildHasUpdate())) { UpdateAvailableBadge.renderBadge(DrawContext, x + iconSize + 3 + font.getWidth(name) + 2, y); updateBadgeXOffset = 11; } if (!ModMenuConfig.HIDE_BADGES.getValue()) { - new ModBadgeRenderer(x + iconSize + 3 + font.getWidth(name) + 2 + updateBadgeXOffset, y, x + rowWidth, mod, list.getParent()).draw(DrawContext, mouseX, mouseY); + new ModBadgeRenderer(x + iconSize + 3 + font.getWidth(name) + 2 + updateBadgeXOffset, + y, + x + rowWidth, + mod, + list.getParent() + ).draw(DrawContext, mouseX, mouseY); } if (!ModMenuConfig.COMPACT_LIST.getValue()) { String summary = mod.getSummary(); - DrawingUtil.drawWrappedString(DrawContext, summary, (x + iconSize + 3 + 4), (y + client.textRenderer.fontHeight + 2), rowWidth - iconSize - 7, 2, 0x808080); + DrawingUtil.drawWrappedString(DrawContext, + summary, + (x + iconSize + 3 + 4), + (y + client.textRenderer.fontHeight + 2), + rowWidth - iconSize - 7, + 2, + 0x808080 + ); } else { - DrawingUtil.drawWrappedString(DrawContext, mod.getPrefixedVersion(), (x + iconSize + 3), (y + client.textRenderer.fontHeight + 2), rowWidth - iconSize - 7, 2, 0x808080); + DrawingUtil.drawWrappedString(DrawContext, + mod.getPrefixedVersion(), + (x + iconSize + 3), + (y + client.textRenderer.fontHeight + 2), + rowWidth - iconSize - 7, + 2, + 0x808080 + ); } - if (!(this instanceof ParentEntry) && ModMenuConfig.QUICK_CONFIGURE.getValue() && (this.list.getParent().getModHasConfigScreen().get(modId) || this.list.getParent().modScreenErrors.containsKey(modId))) { - final int textureSize = ModMenuConfig.COMPACT_LIST.getValue() ? (int) (256 / (FULL_ICON_SIZE / (double) COMPACT_ICON_SIZE)) : 256; + if (!(this instanceof ParentEntry) && ModMenuConfig.QUICK_CONFIGURE.getValue() && (this.list.getParent() + .getModHasConfigScreen() + .get(modId) || this.list.getParent().modScreenErrors.containsKey(modId))) { + final int textureSize = ModMenuConfig.COMPACT_LIST.getValue() ? + (int) (256 / (FULL_ICON_SIZE / (double) COMPACT_ICON_SIZE)) : + 256; if (this.client.options.getTouchscreen().getValue() || hovered) { DrawContext.fill(x, y, x + iconSize, y + iconSize, -1601138544); boolean hoveringIcon = mouseX - x < iconSize; if (this.list.getParent().modScreenErrors.containsKey(modId)) { - DrawContext.drawGuiTexture(hoveringIcon ? ERROR_HIGHLIGHTED_ICON : ERROR_ICON, x, y, iconSize, iconSize); + DrawContext.drawGuiTexture(hoveringIcon ? ERROR_HIGHLIGHTED_ICON : ERROR_ICON, + x, + y, + iconSize, + iconSize + ); if (hoveringIcon) { Throwable e = this.list.getParent().modScreenErrors.get(modId); - this.list.getParent().setTooltip(this.client.textRenderer.wrapLines(ModMenuScreenTexts.configureError(modId, e), 175)); + this.list.getParent() + .setTooltip(this.client.textRenderer.wrapLines( + ModMenuScreenTexts.configureError(modId, e), + 175 + )); } } else { int v = hoveringIcon ? iconSize : 0; - DrawContext.drawTexture(MOD_CONFIGURATION_ICON, x, y, 0.0F, (float) v, iconSize, iconSize, textureSize, textureSize); + DrawContext.drawTexture(MOD_CONFIGURATION_ICON, + x, + y, + 0.0F, + (float) v, + iconSize, + iconSize, + textureSize, + textureSize + ); } } } @@ -104,7 +167,9 @@ public void render(DrawContext DrawContext, int index, int y, int x, int rowWidt @Override public boolean mouseClicked(double mouseX, double mouseY, int delta) { list.select(this); - if (ModMenuConfig.QUICK_CONFIGURE.getValue() && this.list.getParent().getModHasConfigScreen().get(this.mod.getId())) { + if (ModMenuConfig.QUICK_CONFIGURE.getValue() && this.list.getParent() + .getModHasConfigScreen() + .get(this.mod.getId())) { int iconSize = ModMenuConfig.COMPACT_LIST.getValue() ? COMPACT_ICON_SIZE : FULL_ICON_SIZE; if (mouseX - list.getRowLeft() <= iconSize) { this.openConfig(); @@ -127,7 +192,9 @@ public Mod getMod() { public Identifier getIconTexture() { if (this.iconLocation == null) { this.iconLocation = Identifier.of(ModMenu.MOD_ID, mod.getId() + "_icon"); - NativeImageBackedTexture icon = mod.getIcon(list.getFabricIconHandler(), 64 * this.client.options.getGuiScale().getValue()); + NativeImageBackedTexture icon = mod.getIcon(list.getFabricIconHandler(), + 64 * this.client.options.getGuiScale().getValue() + ); if (icon != null) { this.client.getTextureManager().registerTexture(this.iconLocation, icon); } else { diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ParentEntry.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ParentEntry.java index c70358522..b54f5499d 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ParentEntry.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ParentEntry.java @@ -30,13 +30,26 @@ public ParentEntry(Mod parent, List children, ModListWidget list) { } @Override - public void render(DrawContext DrawContext, int index, int y, int x, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean isSelected, float delta) { + public void render( + DrawContext DrawContext, + int index, + int y, + int x, + int rowWidth, + int rowHeight, + int mouseX, + int mouseY, + boolean isSelected, + float delta + ) { super.render(DrawContext, index, y, x, rowWidth, rowHeight, mouseX, mouseY, isSelected, delta); TextRenderer font = client.textRenderer; int childrenBadgeHeight = font.fontHeight; int childrenBadgeWidth = font.fontHeight; int shownChildren = ModSearch.search(list.getParent(), list.getParent().getSearchInput(), getChildren()).size(); - Text str = shownChildren == children.size() ? Text.literal(String.valueOf(shownChildren)) : Text.literal(shownChildren + "/" + children.size()); + Text str = shownChildren == children.size() ? + Text.literal(String.valueOf(shownChildren)) : + Text.literal(shownChildren + "/" + children.size()); int childrenWidth = font.getWidth(str) - 1; if (childrenBadgeWidth < childrenWidth + 4) { childrenBadgeWidth = childrenWidth + 4; @@ -46,19 +59,63 @@ public void render(DrawContext DrawContext, int index, int y, int x, int rowWidt int childrenBadgeY = y + iconSize - childrenBadgeHeight; int childrenOutlineColor = 0xff107454; int childrenFillColor = 0xff093929; - DrawContext.fill(childrenBadgeX + 1, childrenBadgeY, childrenBadgeX + childrenBadgeWidth - 1, childrenBadgeY + 1, childrenOutlineColor); - DrawContext.fill( childrenBadgeX, childrenBadgeY + 1, childrenBadgeX + 1, childrenBadgeY + childrenBadgeHeight - 1, childrenOutlineColor); - DrawContext.fill( childrenBadgeX + childrenBadgeWidth - 1, childrenBadgeY + 1, childrenBadgeX + childrenBadgeWidth, childrenBadgeY + childrenBadgeHeight - 1, childrenOutlineColor); - DrawContext.fill( childrenBadgeX + 1, childrenBadgeY + 1, childrenBadgeX + childrenBadgeWidth - 1, childrenBadgeY + childrenBadgeHeight - 1, childrenFillColor); - DrawContext.fill( childrenBadgeX + 1, childrenBadgeY + childrenBadgeHeight - 1, childrenBadgeX + childrenBadgeWidth - 1, childrenBadgeY + childrenBadgeHeight, childrenOutlineColor); - DrawContext.drawText(font, str.asOrderedText(), (int) (childrenBadgeX + (float) childrenBadgeWidth / 2 - (float) childrenWidth / 2), childrenBadgeY + 1, 0xCACACA, false); + DrawContext.fill(childrenBadgeX + 1, + childrenBadgeY, + childrenBadgeX + childrenBadgeWidth - 1, + childrenBadgeY + 1, + childrenOutlineColor + ); + DrawContext.fill(childrenBadgeX, + childrenBadgeY + 1, + childrenBadgeX + 1, + childrenBadgeY + childrenBadgeHeight - 1, + childrenOutlineColor + ); + DrawContext.fill(childrenBadgeX + childrenBadgeWidth - 1, + childrenBadgeY + 1, + childrenBadgeX + childrenBadgeWidth, + childrenBadgeY + childrenBadgeHeight - 1, + childrenOutlineColor + ); + DrawContext.fill(childrenBadgeX + 1, + childrenBadgeY + 1, + childrenBadgeX + childrenBadgeWidth - 1, + childrenBadgeY + childrenBadgeHeight - 1, + childrenFillColor + ); + DrawContext.fill(childrenBadgeX + 1, + childrenBadgeY + childrenBadgeHeight - 1, + childrenBadgeX + childrenBadgeWidth - 1, + childrenBadgeY + childrenBadgeHeight, + childrenOutlineColor + ); + DrawContext.drawText(font, + str.asOrderedText(), + (int) (childrenBadgeX + (float) childrenBadgeWidth / 2 - (float) childrenWidth / 2), + childrenBadgeY + 1, + 0xCACACA, + false + ); this.hoveringIcon = mouseX >= x - 1 && mouseX <= x - 1 + iconSize && mouseY >= y - 1 && mouseY <= y - 1 + iconSize; if (isMouseOver(mouseX, mouseY)) { DrawContext.fill(x, y, x + iconSize, y + iconSize, 0xA0909090); int xOffset = list.getParent().showModChildren.contains(getMod().getId()) ? iconSize : 0; int yOffset = hoveringIcon ? iconSize : 0; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - DrawContext.drawTexture(PARENT_MOD_TEXTURE, x, y, xOffset, yOffset, iconSize + xOffset, iconSize + yOffset, ModMenuConfig.COMPACT_LIST.getValue() ? (int) (256 / (FULL_ICON_SIZE / (double) COMPACT_ICON_SIZE)) : 256, ModMenuConfig.COMPACT_LIST.getValue() ? (int) (256 / (FULL_ICON_SIZE / (double) COMPACT_ICON_SIZE)) : 256); + DrawContext.drawTexture(PARENT_MOD_TEXTURE, + x, + y, + xOffset, + yOffset, + iconSize + xOffset, + iconSize + yOffset, + ModMenuConfig.COMPACT_LIST.getValue() ? + (int) (256 / (FULL_ICON_SIZE / (double) COMPACT_ICON_SIZE)) : + 256, + ModMenuConfig.COMPACT_LIST.getValue() ? + (int) (256 / (FULL_ICON_SIZE / (double) COMPACT_ICON_SIZE)) : + 256 + ); } } diff --git a/src/main/java/com/terraformersmc/modmenu/mixin/AccessorGridWidget.java b/src/main/java/com/terraformersmc/modmenu/mixin/AccessorGridWidget.java index 7aeea886e..a74069862 100644 --- a/src/main/java/com/terraformersmc/modmenu/mixin/AccessorGridWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/mixin/AccessorGridWidget.java @@ -1,6 +1,5 @@ package com.terraformersmc.modmenu.mixin; -import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.client.gui.widget.GridWidget; import net.minecraft.client.gui.widget.Widget; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/com/terraformersmc/modmenu/mixin/MixinGameMenu.java b/src/main/java/com/terraformersmc/modmenu/mixin/MixinGameMenu.java index 1b6ee63b7..03187cb78 100644 --- a/src/main/java/com/terraformersmc/modmenu/mixin/MixinGameMenu.java +++ b/src/main/java/com/terraformersmc/modmenu/mixin/MixinGameMenu.java @@ -51,7 +51,13 @@ private void onInitWidgets(CallbackInfo ci, GridWidget gridWidget, GridWidget.Ad modsButtonIndex = i + 1; reportBugsY = widget.getY(); if (style == ModMenuConfig.GameMenuButtonStyle.REPLACE_BUGS) { - buttons.set(i, new ModMenuButtonWidget(widget.getX(), widget.getY(), widget.getWidth(), widget.getHeight(), ModMenuApi.createModsButtonText(), this)); + buttons.set(i, new ModMenuButtonWidget(widget.getX(), + widget.getY(), + widget.getWidth(), + widget.getHeight(), + ModMenuApi.createModsButtonText(), + this + )); } else { modsButtonIndex = i + 1; if (!(widget instanceof ClickableWidget button) || button.visible) { @@ -62,9 +68,27 @@ private void onInitWidgets(CallbackInfo ci, GridWidget gridWidget, GridWidget.Ad } if (modsButtonIndex != -1) { if (style == ModMenuConfig.GameMenuButtonStyle.BELOW_BUGS) { - buttons.add(modsButtonIndex, new ModMenuButtonWidget(this.width / 2 - 102, buttonsY + spacing, 204, 20, ModMenuApi.createModsButtonText(), this)); + buttons.add(modsButtonIndex, new ModMenuButtonWidget(this.width / 2 - 102, + buttonsY + spacing, + 204, + 20, + ModMenuApi.createModsButtonText(), + this + )); } else if (style == ModMenuConfig.GameMenuButtonStyle.ICON) { - buttons.add(modsButtonIndex, new UpdateCheckerTexturedButtonWidget(this.width / 2 + 4 + 100 + 2, reportBugsY, 20, 20, 0, 0, 20, ModMenuEventHandler.FABRIC_ICON_BUTTON_LOCATION, 32, 64, button -> MinecraftClient.getInstance().setScreen(new ModsScreen(this)), ModMenuApi.createModsButtonText())); + buttons.add(modsButtonIndex, new UpdateCheckerTexturedButtonWidget(this.width / 2 + 4 + 100 + 2, + reportBugsY, + 20, + 20, + 0, + 0, + 20, + ModMenuEventHandler.FABRIC_ICON_BUTTON_LOCATION, + 32, + 64, + button -> MinecraftClient.getInstance().setScreen(new ModsScreen(this)), + ModMenuApi.createModsButtonText() + )); } } } diff --git a/src/main/java/com/terraformersmc/modmenu/mixin/MixinTitleScreen.java b/src/main/java/com/terraformersmc/modmenu/mixin/MixinTitleScreen.java index dca724e53..e4c3d1352 100644 --- a/src/main/java/com/terraformersmc/modmenu/mixin/MixinTitleScreen.java +++ b/src/main/java/com/terraformersmc/modmenu/mixin/MixinTitleScreen.java @@ -22,7 +22,8 @@ private int adjustRealmsHeight(int height) { @ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Ljava/lang/String;III)I", ordinal = 0)) private String onRender(String string) { - if (ModMenuConfig.MODIFY_TITLE_SCREEN.getValue() && ModMenuConfig.MOD_COUNT_LOCATION.getValue().isOnTitleScreen()) { + if (ModMenuConfig.MODIFY_TITLE_SCREEN.getValue() && ModMenuConfig.MOD_COUNT_LOCATION.getValue() + .isOnTitleScreen()) { String count = ModMenu.getDisplayedModCount(); String specificKey = "modmenu.mods." + count; String replacementKey = I18n.hasTranslation(specificKey) ? specificKey : "modmenu.mods.n"; diff --git a/src/main/java/com/terraformersmc/modmenu/util/DrawingUtil.java b/src/main/java/com/terraformersmc/modmenu/util/DrawingUtil.java index 40b4fd3f8..e03274fd9 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/DrawingUtil.java +++ b/src/main/java/com/terraformersmc/modmenu/util/DrawingUtil.java @@ -7,8 +7,10 @@ import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.*; +import net.minecraft.text.OrderedText; +import net.minecraft.text.StringVisitable; +import net.minecraft.text.Style; +import net.minecraft.text.Text; import net.minecraft.util.Language; import net.minecraft.util.math.MathHelper; @@ -19,7 +21,14 @@ public class DrawingUtil { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); - public static void drawRandomVersionBackground(Mod mod, DrawContext DrawContext, int x, int y, int width, int height) { + public static void drawRandomVersionBackground( + Mod mod, + DrawContext DrawContext, + int x, + int y, + int width, + int height + ) { int seed = mod.getName().hashCode() + mod.getVersion().hashCode(); Random random = new Random(seed); int color = 0xFF000000 | MathHelper.hsvToRgb(random.nextFloat(1f), random.nextFloat(0.7f, 0.8f), 0.9f); @@ -30,11 +39,20 @@ public static void drawRandomVersionBackground(Mod mod, DrawContext DrawContext, DrawContext.fill(x, y, x + width, y + height, color); } - public static void drawWrappedString(DrawContext DrawContext, String string, int x, int y, int wrapWidth, int lines, int color) { + public static void drawWrappedString( + DrawContext DrawContext, + String string, + int x, + int y, + int wrapWidth, + int lines, + int color + ) { while (string != null && string.endsWith("\n")) { string = string.substring(0, string.length() - 1); } - List strings = CLIENT.textRenderer.getTextHandler().wrapLines(Text.literal(string), wrapWidth, Style.EMPTY); + List strings = CLIENT.textRenderer.getTextHandler() + .wrapLines(Text.literal(string), wrapWidth, Style.EMPTY); for (int i = 0; i < strings.size(); i++) { if (i >= lines) { break; @@ -53,12 +71,32 @@ public static void drawWrappedString(DrawContext DrawContext, String string, int } } - public static void drawBadge(DrawContext DrawContext, int x, int y, int tagWidth, OrderedText text, int outlineColor, int fillColor, int textColor) { + public static void drawBadge( + DrawContext DrawContext, + int x, + int y, + int tagWidth, + OrderedText text, + int outlineColor, + int fillColor, + int textColor + ) { DrawContext.fill(x + 1, y - 1, x + tagWidth, y, outlineColor); DrawContext.fill(x, y, x + 1, y + CLIENT.textRenderer.fontHeight, outlineColor); - DrawContext.fill(x + 1, y + 1 + CLIENT.textRenderer.fontHeight - 1, x + tagWidth, y + CLIENT.textRenderer.fontHeight + 1, outlineColor); - DrawContext.fill( x + tagWidth, y, x + tagWidth + 1, y + CLIENT.textRenderer.fontHeight, outlineColor); - DrawContext.fill( x + 1, y, x + tagWidth, y + CLIENT.textRenderer.fontHeight, fillColor); - DrawContext.drawText(CLIENT.textRenderer, text, (int) (x + 1 + (tagWidth - CLIENT.textRenderer.getWidth(text)) / (float) 2), y + 1, textColor, false); + DrawContext.fill(x + 1, + y + 1 + CLIENT.textRenderer.fontHeight - 1, + x + tagWidth, + y + CLIENT.textRenderer.fontHeight + 1, + outlineColor + ); + DrawContext.fill(x + tagWidth, y, x + tagWidth + 1, y + CLIENT.textRenderer.fontHeight, outlineColor); + DrawContext.fill(x + 1, y, x + tagWidth, y + CLIENT.textRenderer.fontHeight, fillColor); + DrawContext.drawText(CLIENT.textRenderer, + text, + (int) (x + 1 + (tagWidth - CLIENT.textRenderer.getWidth(text)) / (float) 2), + y + 1, + textColor, + false + ); } } diff --git a/src/main/java/com/terraformersmc/modmenu/util/EnumToLowerCaseJsonConverter.java b/src/main/java/com/terraformersmc/modmenu/util/EnumToLowerCaseJsonConverter.java index 9d470dc55..08646d348 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/EnumToLowerCaseJsonConverter.java +++ b/src/main/java/com/terraformersmc/modmenu/util/EnumToLowerCaseJsonConverter.java @@ -18,9 +18,11 @@ public JsonElement serialize(final Enum src, final Type typeOfSrc, final Json } @Override - public Enum deserialize(final JsonElement json, - final Type type, - final JsonDeserializationContext context) throws JsonParseException { + public Enum deserialize( + final JsonElement json, + final Type type, + final JsonDeserializationContext context + ) throws JsonParseException { if (json == null || json.isJsonNull()) { return null; } diff --git a/src/main/java/com/terraformersmc/modmenu/util/HttpUtil.java b/src/main/java/com/terraformersmc/modmenu/util/HttpUtil.java index 82ccd94c3..fffa01d91 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/HttpUtil.java +++ b/src/main/java/com/terraformersmc/modmenu/util/HttpUtil.java @@ -1,25 +1,28 @@ package com.terraformersmc.modmenu.util; +import com.terraformersmc.modmenu.ModMenu; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.SharedConstants; + import java.io.IOException; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; -import com.terraformersmc.modmenu.ModMenu; - -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.SharedConstants; - public class HttpUtil { private static final String USER_AGENT = buildUserAgent(); private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient(); - private HttpUtil() {} + private HttpUtil() { + } - public static HttpResponse request(HttpRequest.Builder builder, HttpResponse.BodyHandler handler) throws IOException, InterruptedException { + public static HttpResponse request( + HttpRequest.Builder builder, + HttpResponse.BodyHandler handler + ) throws IOException, InterruptedException { builder.setHeader("User-Agent", USER_AGENT); return HTTP_CLIENT.send(builder.build(), handler); - } + } private static String buildUserAgent() { String env = ModMenu.DEV_ENVIRONMENT ? "/development" : ""; diff --git a/src/main/java/com/terraformersmc/modmenu/util/JsonUtil.java b/src/main/java/com/terraformersmc/modmenu/util/JsonUtil.java index 4a5e7b2da..1278bc41b 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/JsonUtil.java +++ b/src/main/java/com/terraformersmc/modmenu/util/JsonUtil.java @@ -1,12 +1,13 @@ package com.terraformersmc.modmenu.util; -import java.util.Optional; - import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import java.util.Optional; + public class JsonUtil { - private JsonUtil() {} + private JsonUtil() { + } public static Optional getString(JsonObject parent, String field) { if (!parent.has(field)) { @@ -15,7 +16,7 @@ public static Optional getString(JsonObject parent, String field) { var value = parent.get(field); - if (!value.isJsonPrimitive() || !((JsonPrimitive)value).isString()) { + if (!value.isJsonPrimitive() || !((JsonPrimitive) value).isString()) { return Optional.empty(); } @@ -29,7 +30,7 @@ public static Optional getBoolean(JsonObject parent, String field) { var value = parent.get(field); - if (!value.isJsonPrimitive() || !((JsonPrimitive)value).isBoolean()) { + if (!value.isJsonPrimitive() || !((JsonPrimitive) value).isBoolean()) { return Optional.empty(); } diff --git a/src/main/java/com/terraformersmc/modmenu/util/ModMenuScreenTexts.java b/src/main/java/com/terraformersmc/modmenu/util/ModMenuScreenTexts.java index 209c28dee..d34792604 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/ModMenuScreenTexts.java +++ b/src/main/java/com/terraformersmc/modmenu/util/ModMenuScreenTexts.java @@ -19,7 +19,6 @@ public final class ModMenuScreenTexts { public static final Text WEBSITE = Text.translatable("modmenu.website"); private ModMenuScreenTexts() { - return; } public static Text modIdTooltip(String modId) { diff --git a/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java b/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java index 815e3fdd6..953b07cea 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java +++ b/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java @@ -127,7 +127,8 @@ private static void checkForUpdates0() { LOGGER.info("Update available for '{}@{}', (-> {})", mod.getId(), mod.getVersion(), - data.versionNumber); + data.versionNumber + ); } } } @@ -151,15 +152,13 @@ private static Map> getModHashes(Collection mods) { LOGGER.error("Error getting mod hash for mod {}: ", modId, e); } } - ; return results; } public static void triggerV2DeprecatedToast() { if (modrinthApiV2Deprecated && ModMenuConfig.UPDATE_CHECKER.getValue()) { - MinecraftClient.getInstance().getToastManager().add(new SystemToast( - SystemToast.Type.PERIODIC_NOTIFICATION, + MinecraftClient.getInstance().getToastManager().add(new SystemToast(SystemToast.Type.PERIODIC_NOTIFICATION, Text.translatable("modmenu.modrinth.v2_deprecated.title"), Text.translatable("modmenu.modrinth.v2_deprecated.description") )); @@ -244,7 +243,8 @@ private static UpdateChannel getUpdateChannel(String versionType) { String body = ModMenu.GSON_MINIFIED.toJson(new LatestVersionsFromHashesBody(modHashes, loaders, mcVer, - updateChannels)); + updateChannels + )); LOGGER.debug("Body: {}", body); var latestVersionsRequest = HttpRequest.newBuilder() @@ -270,8 +270,12 @@ private static UpdateChannel getUpdateChannel(String versionType) { var versionType = versionObj.get("version_type").getAsString(); var versionNumber = versionObj.get("version_number").getAsString(); var versionId = versionObj.get("id").getAsString(); - var primaryFile = versionObj.get("files").getAsJsonArray().asList().stream() - .filter(file -> file.getAsJsonObject().get("primary").getAsBoolean()).findFirst(); + var primaryFile = versionObj.get("files") + .getAsJsonArray() + .asList() + .stream() + .filter(file -> file.getAsJsonObject().get("primary").getAsBoolean()) + .findFirst(); if (primaryFile.isEmpty()) { return; @@ -294,7 +298,8 @@ private static UpdateChannel getUpdateChannel(String versionType) { .getAsString(); results.put(lookupHash, - new VersionUpdate(projectId, versionId, versionNumber, date, updateChannel, versionHash)); + new VersionUpdate(projectId, versionId, versionNumber, date, updateChannel, versionHash) + ); }); return results; @@ -328,10 +333,12 @@ public static class LatestVersionsFromHashesBody { @SerializedName("version_types") public Collection versionTypes; - public LatestVersionsFromHashesBody(Collection hashes, - Collection loaders, - String mcVersion, - Collection updateChannels) { + public LatestVersionsFromHashesBody( + Collection hashes, + Collection loaders, + String mcVersion, + Collection updateChannels + ) { this.hashes = hashes; this.loaders = loaders; this.gameVersions = Set.of(mcVersion); diff --git a/src/main/java/com/terraformersmc/modmenu/util/VersionUtil.java b/src/main/java/com/terraformersmc/modmenu/util/VersionUtil.java index 29e1a81c6..d89ec397e 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/VersionUtil.java +++ b/src/main/java/com/terraformersmc/modmenu/util/VersionUtil.java @@ -5,7 +5,7 @@ public final class VersionUtil { private static final List PREFIXES = List.of("version", "ver", "v"); - private VersionUtil() {} + private VersionUtil() { } public static String stripPrefix(String version) { version = version.trim(); diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java index 7b5e7e7b9..84a3a7ecf 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/Mod.java @@ -37,8 +37,9 @@ default String getTranslatedName() { @NotNull default String getSummary() { String string = getTranslatedSummary(); - return ModMenu.TEXT_PLACEHOLDER_COMPAT ? TextPlaceholderApiCompat.PARSER.parseText(string, ParserContext.of()) - .getString() : string; + return ModMenu.TEXT_PLACEHOLDER_COMPAT ? + TextPlaceholderApiCompat.PARSER.parseText(string, ParserContext.of()).getString() : + string; } @NotNull @@ -65,8 +66,9 @@ default String getTranslatedDescription() { default Text getFormattedDescription() { String string = getTranslatedDescription(); - return ModMenu.TEXT_PLACEHOLDER_COMPAT ? TextPlaceholderApiCompat.PARSER.parseText(string, - ParserContext.of()) : Text.literal(string); + return ModMenu.TEXT_PLACEHOLDER_COMPAT ? + TextPlaceholderApiCompat.PARSER.parseText(string, ParserContext.of()) : + Text.literal(string); } @NotNull String getVersion(); @@ -132,12 +134,20 @@ default boolean hasUpdate() { boolean isHidden(); enum Badge { - LIBRARY("modmenu.badge.library", 0xff107454, 0xff093929, "library"), - CLIENT("modmenu.badge.clientsideOnly", 0xff2b4b7c, 0xff0e2a55, null), - DEPRECATED("modmenu.badge.deprecated", 0xff841426, 0xff530C17, "deprecated"), - PATCHWORK_FORGE("modmenu.badge.forge", 0xff1f2d42, 0xff101721, null), - MODPACK("modmenu.badge.modpack", 0xff7a2b7c, 0xff510d54, null), - MINECRAFT("modmenu.badge.minecraft", 0xff6f6c6a, 0xff31302f, null); + LIBRARY("modmenu.badge.library", 0xff107454, 0xff093929, "library"), CLIENT("modmenu.badge.clientsideOnly", + 0xff2b4b7c, + 0xff0e2a55, + null + ), DEPRECATED("modmenu.badge.deprecated", 0xff841426, 0xff530C17, "deprecated"), PATCHWORK_FORGE( + "modmenu.badge.forge", + 0xff1f2d42, + 0xff101721, + null + ), MODPACK("modmenu.badge.modpack", 0xff7a2b7c, 0xff510d54, null), MINECRAFT("modmenu.badge.minecraft", + 0xff6f6c6a, + 0xff31302f, + null + ); private final Text text; private final int outlineColor, fillColor; @@ -164,16 +174,13 @@ public int getFillColor() { } public static Set convert(Set badgeKeys, String modId) { - return badgeKeys.stream() - .map(key -> { - if (!KEY_MAP.containsKey(key)) { - ModMenu.LOGGER.warn("Skipping unknown badge key '{}' specified by mod '{}'", key, modId); - } - - return KEY_MAP.get(key); - }) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); + return badgeKeys.stream().map(key -> { + if (!KEY_MAP.containsKey(key)) { + ModMenu.LOGGER.warn("Skipping unknown badge key '{}' specified by mod '{}'", key, modId); + } + + return KEY_MAP.get(key); + }).filter(Objects::nonNull).collect(Collectors.toSet()); } static { diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/ModBadgeRenderer.java b/src/main/java/com/terraformersmc/modmenu/util/mod/ModBadgeRenderer.java index 324dcc338..73d69b39b 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/ModBadgeRenderer.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/ModBadgeRenderer.java @@ -1,16 +1,11 @@ package com.terraformersmc.modmenu.util.mod; -import com.terraformersmc.modmenu.config.ModMenuConfig; import com.terraformersmc.modmenu.gui.ModsScreen; import com.terraformersmc.modmenu.util.DrawingUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; -import java.nio.charset.StandardCharsets; -import java.util.Calendar; import java.util.Set; public class ModBadgeRenderer { @@ -36,10 +31,23 @@ public void draw(DrawContext DrawContext, int mouseX, int mouseY) { } public void drawBadge(DrawContext DrawContext, Mod.Badge badge, int mouseX, int mouseY) { - this.drawBadge(DrawContext, badge.getText().asOrderedText(), badge.getOutlineColor(), badge.getFillColor(), mouseX, mouseY); + this.drawBadge(DrawContext, + badge.getText().asOrderedText(), + badge.getOutlineColor(), + badge.getFillColor(), + mouseX, + mouseY + ); } - public void drawBadge(DrawContext DrawContext, OrderedText text, int outlineColor, int fillColor, int mouseX, int mouseY) { + public void drawBadge( + DrawContext DrawContext, + OrderedText text, + int outlineColor, + int fillColor, + int mouseX, + int mouseY + ) { int width = client.textRenderer.getWidth(text) + 6; if (badgeX + width < badgeMax) { DrawingUtil.drawBadge(DrawContext, badgeX, badgeY, width, text, outlineColor, fillColor, 0xCACACA); diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/ModSearch.java b/src/main/java/com/terraformersmc/modmenu/util/mod/ModSearch.java index 8c5b530e4..91612888b 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/ModSearch.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/ModSearch.java @@ -21,11 +21,13 @@ public static List search(ModsScreen screen, String query, List candid return candidates; } return candidates.stream() - .map(modContainer -> new Pair<>(modContainer, passesFilters(screen, modContainer, query.toLowerCase(Locale.ROOT)))) - .filter(pair -> pair.getRight() > 0) - .sorted((a, b) -> b.getRight() - a.getRight()) - .map(Pair::getLeft) - .collect(Collectors.toList()); + .map(modContainer -> new Pair<>(modContainer, + passesFilters(screen, modContainer, query.toLowerCase(Locale.ROOT)) + )) + .filter(pair -> pair.getRight() > 0) + .sorted((a, b) -> b.getRight() - a.getRight()) + .map(Pair::getLeft) + .collect(Collectors.toList()); } private static int passesFilters(ModsScreen screen, Mod mod, String query) { @@ -50,22 +52,25 @@ private static int passesFilters(ModsScreen screen, Mod mod, String query) { // Some basic search, could do with something more advanced but this will do for now if (modName.toLowerCase(Locale.ROOT).contains(query) // Search default mod name - || modTranslatedName.toLowerCase(Locale.ROOT).contains(query) // Search localized mod name - || modId.toLowerCase(Locale.ROOT).contains(query) // Search mod ID + || modTranslatedName.toLowerCase(Locale.ROOT).contains(query) // Search localized mod name + || modId.toLowerCase(Locale.ROOT).contains(query) // Search mod ID ) { return query.length() >= 3 ? 2 : 1; } if (modDescription.toLowerCase(Locale.ROOT).contains(query) // Search default mod description - || modSummary.toLowerCase(Locale.ROOT).contains(query) // Search mod summary - || authorMatches(mod, query) // Search via author - || library.contains(query) && mod.getBadges().contains(Mod.Badge.LIBRARY) // Search for lib mods - || patchwork.contains(query) && mod.getBadges().contains(Mod.Badge.PATCHWORK_FORGE) // Search for patchwork mods - || modpack.contains(query) && mod.getBadges().contains(Mod.Badge.MODPACK) // Search for modpack mods - || deprecated.contains(query) && mod.getBadges().contains(Mod.Badge.DEPRECATED) // Search for deprecated mods - || clientside.contains(query) && mod.getBadges().contains(Mod.Badge.CLIENT) // Search for clientside mods - || configurable.contains(query) && screen.getModHasConfigScreen().get(modId) // Search for mods that can be configured - || hasUpdate.contains(query) && mod.hasUpdate() // Search for mods that have updates + || modSummary.toLowerCase(Locale.ROOT).contains(query) // Search mod summary + || authorMatches(mod, query) // Search via author + || library.contains(query) && mod.getBadges().contains(Mod.Badge.LIBRARY) // Search for lib mods + || patchwork.contains(query) && mod.getBadges() + .contains(Mod.Badge.PATCHWORK_FORGE) // Search for patchwork mods + || modpack.contains(query) && mod.getBadges().contains(Mod.Badge.MODPACK) // Search for modpack mods + || deprecated.contains(query) && mod.getBadges() + .contains(Mod.Badge.DEPRECATED) // Search for deprecated mods + || clientside.contains(query) && mod.getBadges().contains(Mod.Badge.CLIENT) // Search for clientside mods + || configurable.contains(query) && screen.getModHasConfigScreen() + .get(modId) // Search for mods that can be configured + || hasUpdate.contains(query) && mod.hasUpdate() // Search for mods that have updates ) { return 1; } @@ -84,9 +89,10 @@ private static int passesFilters(ModsScreen screen, Mod mod, String query) { } private static boolean authorMatches(Mod mod, String query) { - return mod.getAuthors().stream() - .map(s -> s.toLowerCase(Locale.ROOT)) - .anyMatch(s -> s.contains(query.toLowerCase(Locale.ROOT))); + return mod.getAuthors() + .stream() + .map(s -> s.toLowerCase(Locale.ROOT)) + .anyMatch(s -> s.contains(query.toLowerCase(Locale.ROOT))); } } diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/ModrinthUpdateInfo.java b/src/main/java/com/terraformersmc/modmenu/util/mod/ModrinthUpdateInfo.java index 2586da8ab..ebb318c69 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/ModrinthUpdateInfo.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/ModrinthUpdateInfo.java @@ -1,12 +1,10 @@ package com.terraformersmc.modmenu.util.mod; -import org.jetbrains.annotations.Nullable; - import com.terraformersmc.modmenu.api.UpdateChannel; import com.terraformersmc.modmenu.api.UpdateInfo; import com.terraformersmc.modmenu.util.VersionUtil; - import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; public class ModrinthUpdateInfo implements UpdateInfo { protected final String projectId; diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java index e3c1e7d38..532822c90 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricDummyParentMod.java @@ -60,8 +60,13 @@ public FabricDummyParentMod(FabricMod host, String id) { } } final String finalIconSourceId = iconSourceId; - ModContainer iconSource = FabricLoader.getInstance().getModContainer(iconSourceId).orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Fabric mod with id " + finalIconSourceId)); - return Objects.requireNonNull(iconHandler.createIcon(iconSource, iconPath), "Mod icon for " + getId() + " is null somehow (should be filled with default in this case)"); + ModContainer iconSource = FabricLoader.getInstance() + .getModContainer(iconSourceId) + .orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Fabric mod with id " + finalIconSourceId)); + return Objects.requireNonNull( + iconHandler.createIcon(iconSource, iconPath), + "Mod icon for " + getId() + " is null somehow (should be filled with default in this case)" + ); } @Override diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricIconHandler.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricIconHandler.java index acca60a36..87b3afd98 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricIconHandler.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricIconHandler.java @@ -41,7 +41,11 @@ public NativeImageBackedTexture createIcon(ModContainer iconSource, String iconP } catch (IllegalStateException e) { if (e.getMessage().equals("Must be square icon")) { - LOGGER.error("Mod icon must be a square for icon source {}: {}", iconSource.getMetadata().getId(), iconPath, e); + LOGGER.error("Mod icon must be a square for icon source {}: {}", + iconSource.getMetadata().getId(), + iconPath, + e + ); } return null; diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricLoaderUpdateChecker.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricLoaderUpdateChecker.java index 513714bd1..5ac99f50c 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricLoaderUpdateChecker.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricLoaderUpdateChecker.java @@ -1,14 +1,5 @@ package com.terraformersmc.modmenu.util.mod.fabric; -import java.io.IOException; -import java.net.URI; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; - -import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.JsonParser; import com.terraformersmc.modmenu.api.UpdateChannel; import com.terraformersmc.modmenu.api.UpdateChecker; @@ -16,12 +7,19 @@ import com.terraformersmc.modmenu.util.HttpUtil; import com.terraformersmc.modmenu.util.JsonUtil; import com.terraformersmc.modmenu.util.OptionalUtil; - import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.SemanticVersion; import net.fabricmc.loader.api.Version; import net.fabricmc.loader.api.VersionParsingException; import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; public class FabricLoaderUpdateChecker implements UpdateChecker { public static final Logger LOGGER = LoggerFactory.getLogger("Mod Menu/Fabric Update Checker"); diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java index ad9197a9c..d993719a1 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/fabric/FabricMod.java @@ -73,11 +73,11 @@ public FabricMod(ModContainer modContainer, Set modpackMods) { CustomValue.CvObject parentObj = parentCv.getAsObject(); parentId = CustomValueUtil.getString("id", parentObj); parentData = new ModMenuData.DummyParentData( - parentId.orElseThrow(() -> new RuntimeException("Parent object lacks an id")), - CustomValueUtil.getString("name", parentObj), - CustomValueUtil.getString("description", parentObj), - CustomValueUtil.getString("icon", parentObj), - CustomValueUtil.getStringSet("badges", parentObj).orElse(new HashSet<>()) + parentId.orElseThrow(() -> new RuntimeException("Parent object lacks an id")), + CustomValueUtil.getString("name", parentObj), + CustomValueUtil.getString("description", parentObj), + CustomValueUtil.getString("icon", parentObj), + CustomValueUtil.getStringSet("badges", parentObj).orElse(new HashSet<>()) ); if (parentId.orElse("").equals(id)) { parentId = Optional.empty(); @@ -93,23 +93,22 @@ public FabricMod(ModContainer modContainer, Set modpackMods) { links.putAll(CustomValueUtil.getStringMap("links", modMenuObject).orElse(new HashMap<>())); allowsUpdateChecks = CustomValueUtil.getBoolean("update_checker", modMenuObject).orElse(true); } - this.modMenuData = new ModMenuData( - badgeNames, - parentId, - parentData, - id - ); + this.modMenuData = new ModMenuData(badgeNames, parentId, parentData, id); /* Hardcode parents and badges for Fabric API & Fabric Loader */ if (id.startsWith("fabric") && metadata.containsCustomValue("fabric-api:module-lifecycle")) { - if (FabricLoader.getInstance().isModLoaded("fabric-api") || !FabricLoader.getInstance().isModLoaded("fabric")) { + if (FabricLoader.getInstance().isModLoaded("fabric-api") || !FabricLoader.getInstance() + .isModLoaded("fabric")) { modMenuData.fillParentIfEmpty("fabric-api"); } else { modMenuData.fillParentIfEmpty("fabric"); } modMenuData.badges.add(Badge.LIBRARY); } - if (id.startsWith("fabric") && (id.equals("fabricloader") || metadata.getProvides().contains("fabricloader") || id.equals("fabric") || id.equals("fabric-api") || metadata.getProvides().contains("fabric") || metadata.getProvides().contains("fabric-api") || id.equals("fabric-language-kotlin"))) { + if (id.startsWith("fabric") && (id.equals("fabricloader") || metadata.getProvides() + .contains("fabricloader") || id.equals("fabric") || id.equals("fabric-api") || metadata.getProvides() + .contains("fabric") || metadata.getProvides() + .contains("fabric-api") || id.equals("fabric-language-kotlin"))) { modMenuData.badges.add(Badge.LIBRARY); } @@ -118,7 +117,10 @@ public FabricMod(ModContainer modContainer, Set modpackMods) { if (this.metadata.getEnvironment() == ModEnvironment.CLIENT) { badges.add(Badge.CLIENT); } - if (OptionalUtil.isPresentAndTrue(CustomValueUtil.getBoolean("fabric-loom:generated", metadata)) || "java".equals(id)) { + if (OptionalUtil.isPresentAndTrue(CustomValueUtil.getBoolean( + "fabric-loom:generated", + metadata + )) || "java".equals(id)) { badges.add(Badge.LIBRARY); } if ("deprecated".equals(CustomValueUtil.getString("fabric-api:module-lifecycle", metadata).orElse(null))) { @@ -161,14 +163,21 @@ public FabricMod(ModContainer modContainer, Set modpackMods) { iconPath = "assets/" + ModMenu.MOD_ID + "/java_icon.png"; } final String finalIconSourceId = iconSourceId; - ModContainer iconSource = FabricLoader.getInstance().getModContainer(iconSourceId).orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Fabric mod with id " + finalIconSourceId)); + ModContainer iconSource = FabricLoader.getInstance() + .getModContainer(iconSourceId) + .orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Fabric mod with id " + finalIconSourceId)); NativeImageBackedTexture icon = iconHandler.createIcon(iconSource, iconPath); if (icon == null) { if (defaultIconWarning) { LOGGER.warn("Warning! Mod {} has a broken icon, loading default icon", metadata.getId()); defaultIconWarning = false; } - return iconHandler.createIcon(FabricLoader.getInstance().getModContainer(ModMenu.MOD_ID).orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Fabric mod with id " + ModMenu.MOD_ID)), "assets/" + ModMenu.MOD_ID + "/unknown_icon.png"); + return iconHandler.createIcon( + FabricLoader.getInstance() + .getModContainer(ModMenu.MOD_ID) + .orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Fabric mod with id " + ModMenu.MOD_ID)), + "assets/" + ModMenu.MOD_ID + "/unknown_icon.png" + ); } return icon; } @@ -335,7 +344,9 @@ public ModMenuData getModMenuData() { public @Nullable String getSha512Hash() throws IOException { if (container.getContainingMod().isEmpty() && container.getOrigin().getKind() == ModOrigin.Kind.PATH) { List paths = container.getOrigin().getPaths(); - var fileOptional = paths.stream().filter(path -> path.toString().toLowerCase(Locale.ROOT).endsWith(".jar")).findFirst(); + var fileOptional = paths.stream() + .filter(path -> path.toString().toLowerCase(Locale.ROOT).endsWith(".jar")) + .findFirst(); if (fileOptional.isPresent()) { var file = fileOptional.get().toFile(); if (file.isFile()) { @@ -410,7 +421,13 @@ public static class DummyParentData { private final Optional icon; private final Set badges; - public DummyParentData(String id, Optional name, Optional description, Optional icon, Set badges) { + public DummyParentData( + String id, + Optional name, + Optional description, + Optional icon, + Set badges + ) { this.id = id; this.name = name; this.description = description; diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltLoaderUpdateChecker.java b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltLoaderUpdateChecker.java index 4f7eefc21..1ef7e818b 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltLoaderUpdateChecker.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltLoaderUpdateChecker.java @@ -1,25 +1,23 @@ package com.terraformersmc.modmenu.util.mod.quilt; -import java.io.IOException; -import java.net.URI; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; - -import org.jetbrains.annotations.Nullable; -import org.quiltmc.loader.api.QuiltLoader; -import org.quiltmc.loader.api.Version; -import org.quiltmc.loader.api.VersionFormatException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.JsonParser; import com.terraformersmc.modmenu.api.UpdateChannel; import com.terraformersmc.modmenu.api.UpdateChecker; import com.terraformersmc.modmenu.api.UpdateInfo; import com.terraformersmc.modmenu.util.HttpUtil; import com.terraformersmc.modmenu.util.JsonUtil; - import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; +import org.quiltmc.loader.api.QuiltLoader; +import org.quiltmc.loader.api.Version; +import org.quiltmc.loader.api.VersionFormatException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; public class QuiltLoaderUpdateChecker implements UpdateChecker { public static final Logger LOGGER = LoggerFactory.getLogger("Mod Menu/Quilt Update Checker"); @@ -120,7 +118,8 @@ private static Version.Semantic getCurrentVersion() { } private static boolean isStableOrBeta(String preRelease) { - return preRelease.isEmpty() || preRelease.startsWith("beta") || preRelease.startsWith("pre") || preRelease.startsWith("rc"); + return preRelease.isEmpty() || preRelease.startsWith("beta") || preRelease.startsWith("pre") || + preRelease.startsWith("rc"); } private static class QuiltLoaderUpdateInfo implements UpdateInfo { diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java index de7a2a630..b77f1ae07 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java @@ -15,16 +15,7 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; +import java.util.*; import java.util.stream.Collectors; public class QuiltMod extends FabricMod { @@ -43,9 +34,16 @@ public QuiltMod(net.fabricmc.loader.api.ModContainer fabricModContainer, Set getAuthors() { - List authors = metadata.contributors().stream().filter(contributor -> contributor.role().equals("Author") || contributor.role().equals("Owner")).map(ModContributor::name).collect(Collectors.toList()); + List authors = metadata.contributors() + .stream() + .filter(contributor -> contributor.role().equals("Author") || contributor.role().equals("Owner")) + .map(ModContributor::name) + .collect(Collectors.toList()); if (authors.isEmpty()) { - metadata.contributors().stream().findFirst().ifPresent(modContributor -> authors.add(modContributor.name())); + metadata.contributors() + .stream() + .findFirst() + .ifPresent(modContributor -> authors.add(modContributor.name())); } if (authors.isEmpty()) { if ("minecraft".equals(getId())) { @@ -89,16 +87,21 @@ public QuiltMod(net.fabricmc.loader.api.ModContainer fabricModContainer, Set jars = paths.stream().filter(p -> p.toString().toLowerCase(Locale.ROOT).endsWith(".jar")).toList(); + List jars = paths.stream() + .filter(p -> p.toString().toLowerCase(Locale.ROOT).endsWith(".jar")) + .toList(); if (jars.size() == 1 && jars.get(0).getFileSystem() == FileSystems.getDefault()) { var path = jars.get(0); if (Files.exists(path)) { UpdateCheckerUtil.LOGGER.debug("Found {} hash", getId()); - return com.google.common.io.Files.asByteSource(path.toFile()).hash(Hashing.sha512()).toString(); + return com.google.common.io.Files.asByteSource(path.toFile()) + .hash(Hashing.sha512()) + .toString(); } } } diff --git a/src/main/resources/assets/modmenu/lang/be_by.json b/src/main/resources/assets/modmenu/lang/be_by.json index 33bfdc8e3..3daa863f9 100644 --- a/src/main/resources/assets/modmenu/lang/be_by.json +++ b/src/main/resources/assets/modmenu/lang/be_by.json @@ -86,7 +86,7 @@ "modmenu.twitter": "X (былы Twitter)", "modmenu.wiki": "Wiki", "modmenu.youtube": "YouTube", - + "modmenu.credits.role.author": "Аўтары", "modmenu.credits.role.contributor": "Укладальнікі", "modmenu.credits.role.translator": "Перакладчыкі", diff --git a/src/main/resources/assets/modmenu/lang/en_us.json b/src/main/resources/assets/modmenu/lang/en_us.json index ba9380a9f..a3a7f272d 100644 --- a/src/main/resources/assets/modmenu/lang/en_us.json +++ b/src/main/resources/assets/modmenu/lang/en_us.json @@ -4,7 +4,7 @@ "modmenu.title": "Mods", "modmenu.nameTranslation.modmenu": "Mod Menu", "modmenu.descriptionTranslation.modmenu": "Adds a mod menu to view the list of mods you have installed.", - + "modmenu.loaded": "(%s Loaded)", "modmenu.loaded.short": "(%s)", "modmenu.loaded.69.secret": "(%s Loaded...nice)", @@ -13,7 +13,7 @@ "modmenu.mods.1": " (%s Mod)", "modmenu.mods.69.secret": " (%s Mods...nice)", "modmenu.mods.420.secret": " (%s Mods...blaze it)", - + "modmenu.search": "Search for mods", "modmenu.searchTerms.library": "api library", "modmenu.searchTerms.patchwork": "patchwork forge fml", @@ -22,7 +22,7 @@ "modmenu.searchTerms.clientside": "clientside gameside", "modmenu.searchTerms.configurable": "configurations configs configures configurable options settings", "modmenu.searchTerms.hasUpdate": "updates version", - + "modmenu.toggleFilterOptions": "Toggle Filter Options", "modmenu.showingMods.n": "Showing %s mods", "modmenu.showingMods.1": "Showing %s mod", @@ -32,20 +32,20 @@ "modmenu.showingModsLibraries.n.1": "Showing %s mods and %s library", "modmenu.showingModsLibraries.1.n": "Showing %s mod and %s libraries", "modmenu.showingModsLibraries.1.1": "Showing %s mod and %s library", - + "modmenu.badge.library": "Library", "modmenu.badge.clientsideOnly": "Client", "modmenu.badge.deprecated": "Deprecated", "modmenu.badge.forge": "Forge", "modmenu.badge.modpack": "Modpack", "modmenu.badge.minecraft": "Minecraft", - + "modmenu.dropInfo.line1": "Drag and drop files into", "modmenu.dropInfo.line2": "this window to add mods", "modmenu.dropConfirm": "Do you want to copy the following mods into the mods directory?", "modmenu.dropSuccessful.line1": "Successfully copied mods", "modmenu.dropSuccessful.line2": "Restart game to load mods", - + "modmenu.modIdToolTip": "Mod ID: %s", "modmenu.authorPrefix": "By %s", "modmenu.config": "Edit Config", @@ -53,7 +53,7 @@ "modmenu.configure.error": "Failed to load config screen for '%s'\nReport to '%s', not Mod Menu", "modmenu.website": "Website", "modmenu.issues": "Issues", - + "modmenu.credits": "Credits:", "modmenu.viewCredits": "View Credits", "modmenu.license": "License:", @@ -65,7 +65,7 @@ "modmenu.updateText": "v%s on %s", "modmenu.install_version": "Install version %s", "modmenu.downloadLink": "Download", - + "modmenu.buymeacoffee": "Buy Me a Coffee", "modmenu.coindrop": "Coindrop", "modmenu.crowdin": "Crowdin", @@ -87,7 +87,7 @@ "modmenu.twitter": "X (Twitter)", "modmenu.wiki": "Wiki", "modmenu.youtube": "YouTube", - + "modmenu.credits.role.author": "Authors", "modmenu.credits.role.contributor": "Contributors", "modmenu.credits.role.translator": "Translators", @@ -95,16 +95,16 @@ "modmenu.credits.role.playtester": "Playtesters", "modmenu.credits.role.illustrator": "Illustrators", "modmenu.credits.role.owner": "Owners", - + "modmenu.modsFolder": "Open Mods Folder", "modmenu.configsFolder": "Open Configs Folder", - + "modmenu.nameTranslation.minecraft": "Minecraft", "modmenu.descriptionTranslation.minecraft": "The base game.", "modmenu.nameTranslation.java": "Java", "modmenu.descriptionTranslation.java": "The Java runtime environment.", "modmenu.javaDistributionName": "Running: %s", - + "modmenu.options": "Mod Menu Options", "option.modmenu.sorting": "Sort", "option.modmenu.sorting.ascending": "A-Z", diff --git a/src/main/resources/assets/modmenu/lang/no_no.json b/src/main/resources/assets/modmenu/lang/no_no.json index 5d5391085..c29c2784f 100644 --- a/src/main/resources/assets/modmenu/lang/no_no.json +++ b/src/main/resources/assets/modmenu/lang/no_no.json @@ -2,9 +2,9 @@ "category.modmenu.name": "Mod Menu", "key.modmenu.open_menu": "Åpne moddmeny", "modmenu.title": "Modifikasjoner", -"modmenu.nameTranslation.modmenu": "Modifikasjonsmeny", + "modmenu.nameTranslation.modmenu": "Modifikasjonsmeny", "modmenu.descriptionTranslation.modmenu": "Legger til en meny for modifikasjoner, for å vise en liste over modder du har installert.", - + "modmenu.loaded": "(%s Lastet)", "modmenu.loaded.short": "(%s)", "modmenu.loaded.69.secret": "(%s Lastet...nice)", @@ -13,7 +13,7 @@ "modmenu.mods.1": " (%s Mod)", "modmenu.mods.69.secret": " (%s Modder...nice)", "modmenu.mods.420.secret": " (%s Modder...blaze it)", - + "modmenu.search": "Søk etter modder", "modmenu.searchTerms.library": "api bibliotek", "modmenu.searchTerms.patchwork": "patchwork forge fml", @@ -22,7 +22,7 @@ "modmenu.searchTerms.clientside": "clientside gameside", "modmenu.searchTerms.configurable": "configurations configs configures configurable options", "modmenu.searchTerms.hasUpdate": "oppdateringer versjon", - + "modmenu.toggleFilterOptions": "Veksle filteralternativer", "modmenu.showingMods.n": "Viser %s modder", "modmenu.showingMods.1": "Viser %s mod", @@ -32,20 +32,20 @@ "modmenu.showingModsLibraries.n.1": "Viser %s modder og %s bibliotek", "modmenu.showingModsLibraries.1.n": "Viser %s mod og %s biblioteker", "modmenu.showingModsLibraries.1.1": "Viser %s mod og %s bibliotek", - + "modmenu.badge.library": "Bibliotek", "modmenu.badge.clientsideOnly": "Klient", "modmenu.badge.deprecated": "Foreldet", "modmenu.badge.forge": "Forge", "modmenu.badge.modpack": "Modpakke", "modmenu.badge.minecraft": "Minecraft", - + "modmenu.dropInfo.line1": "Dra og slipp filer i dette vinduet", "modmenu.dropInfo.line2": "for å legge til modifikasjoner", "modmenu.dropConfirm": "Vil du kopiere de følgende moddene til modsmappen?", "modmenu.dropSuccessful.line1": "Klarte å kopiere modder", "modmenu.dropSuccessful.line2": "Restart spillet for å laste inn modder", - + "modmenu.modIdToolTip": "Mod ID: %s", "modmenu.authorPrefix": "Av %s", "modmenu.config": "Endre konfigurasjon", @@ -53,7 +53,7 @@ "modmenu.configure.error": "Kunne ikke laste inn konfigurasjonsskjermen for '%s'\nRapporter til '%s', ingen mod-meny", "modmenu.website": "Nettsted", "modmenu.issues": "Problemer", - + "modmenu.credits": "Medvirkende:", "modmenu.viewCredits": "Vis medvirkende", "modmenu.license": "Lisens:", @@ -63,7 +63,7 @@ "modmenu.experimental": "(Mod-menyens oppdaterings-sjekker er eksperimentell!)", "modmenu.childHasUpdate": "Et barn av denne modden har en oppdatering tilgjengelig.", "modmenu.updateText": "v%s på %s", - + "modmenu.buymeacoffee": "Buy Me a Coffee", "modmenu.coindrop": "Coindrop", "modmenu.crowdin": "Crowdin", @@ -85,16 +85,16 @@ "modmenu.twitter": "Twitter", "modmenu.wiki": "Wiki", "modmenu.youtube": "YouTube", - + "modmenu.modsFolder": "Åpne mappe for modder", "modmenu.configsFolder": "Åpne mappe for konfigurasjonsfiler", - + "modmenu.nameTranslation.minecraft": "Minecraft", "modmenu.descriptionTranslation.minecraft": "Grunnspillet.", "modmenu.nameTranslation.java": "Java", "modmenu.descriptionTranslation.java": "Java runtime miljøet.", "modmenu.javaDistributionName": "Kjører: %s", - + "modmenu.options": "Instillinger for modmeny", "option.modmenu.sorting": "Sorter", "option.modmenu.sorting.ascending": "A-Z", diff --git a/src/main/resources/assets/modmenu/lang/pl_pl.json b/src/main/resources/assets/modmenu/lang/pl_pl.json index cd4e559d9..4954c08c8 100644 --- a/src/main/resources/assets/modmenu/lang/pl_pl.json +++ b/src/main/resources/assets/modmenu/lang/pl_pl.json @@ -4,7 +4,7 @@ "modmenu.title": "Mody", "modmenu.nameTranslation.modmenu": "Menu Modów", "modmenu.descriptionTranslation.modmenu": "Dodaje menu modów umożliwiające wyświetlenie listy z zainstalowanymi modami.", - + "modmenu.loaded": "(%s załadowanych)", "modmenu.loaded.short": "(%s)", "modmenu.loaded.69.secret": "(%s załadowanych... nieźle)", @@ -13,7 +13,7 @@ "modmenu.mods.1": " (%s Mod)", "modmenu.mods.69.secret": " (%s modów...nieźle)", "modmenu.mods.420.secret": " (%s modów... jesteś tego pewien?)", - + "modmenu.search": "Szukaj modów", "modmenu.searchTerms.library": "api biblioteka", "modmenu.searchTerms.patchwork": "patchwork forge fml", @@ -32,20 +32,20 @@ "modmenu.showingModsLibraries.n.1": "Pokazuję %s modyfikacji oraz %s bibliotekę", "modmenu.showingModsLibraries.1.n": "Pokazuję %s modyfikację oraz %s bibliotek", "modmenu.showingModsLibraries.1.1": "Pokazuję %s modyfikację oraz %s bibliotekę", - + "modmenu.badge.library": "Biblioteka", "modmenu.badge.clientsideOnly": "Klient", "modmenu.badge.deprecated": "Przestarzały", "modmenu.badge.forge": "Forge", "modmenu.badge.modpack": "Paczka modów", "modmenu.badge.minecraft": "Minecraft", - + "modmenu.dropInfo.line1": "Przeciągnij i upuść mody", "modmenu.dropInfo.line2": "w to okno, aby je dodać", "modmenu.dropConfirm": "Czy chcesz skopiować wybrane mody do folderu z modami?", "modmenu.dropSuccessful.line1": "Mody zostały pomyślnie skopiowane", "modmenu.dropSuccessful.line2": "Zrestartuj grę, aby załadować mody", - + "modmenu.modIdToolTip": "ID moda: %s", "modmenu.authorPrefix": "Stworzone przez %s", "modmenu.config": "Edytuj konfigurację", @@ -53,7 +53,7 @@ "modmenu.configure.error": "Nie udało się załadować ekranu konfiguracyjnego dla '%s'\nZgłoś do '%s', a nie Menu Modów", "modmenu.website": "Strona", "modmenu.issues": "Błędy", - + "modmenu.credits": "Autorzy:", "modmenu.viewCredits": "Pokaż napisy końcowe", "modmenu.license": "Licencja:", @@ -86,7 +86,7 @@ "modmenu.twitter": "X (Twitter)", "modmenu.wiki": "Dokumentacja", "modmenu.youtube": "YouTube", - + "modmenu.credits.role.author": "Autorzy", "modmenu.credits.role.contributor": "Kontrybutorzy", "modmenu.credits.role.translator": "Tłumacze", @@ -94,16 +94,16 @@ "modmenu.credits.role.playtester": "Testerzy", "modmenu.credits.role.illustrator": "Ilustratorzy", "modmenu.credits.role.owner": "Właściciele", - + "modmenu.modsFolder": "Otwórz folder z modami", "modmenu.configsFolder": "Otwórz folder z plikami konfiguracyjnymi", - + "modmenu.nameTranslation.minecraft": "Minecraft", "modmenu.descriptionTranslation.minecraft": "Gra podstawowa.", "modmenu.nameTranslation.java": "Java", "modmenu.descriptionTranslation.java": "Środowisko wykonawcze Java.", "modmenu.javaDistributionName": "Uruchomione: %s", - + "modmenu.options": "Opcje Mod Menu", "option.modmenu.sorting": "Sortuj", "option.modmenu.sorting.ascending": "A-Z", diff --git a/src/main/resources/assets/modmenu/lang/tt_ru.json b/src/main/resources/assets/modmenu/lang/tt_ru.json index 06f596e46..81574a1fe 100644 --- a/src/main/resources/assets/modmenu/lang/tt_ru.json +++ b/src/main/resources/assets/modmenu/lang/tt_ru.json @@ -86,7 +86,7 @@ "modmenu.twitter": "Twitter", "modmenu.wiki": "Вики", "modmenu.youtube": "YouTube", - + "modmenu.credits.role.author": "Авторлар", "modmenu.credits.role.contributor": "Катнашучылар", "modmenu.credits.role.translator": "Тәрҗемәчеләр",