From b3e2973231d1e8a93293c97e3da36032118f126b Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Fri, 17 Mar 2023 09:35:16 +0100 Subject: [PATCH] feat: Support 1.19.4 --- gradle.properties | 10 +++---- .../modsettings/gui/MenuScreensChanger.java | 26 +++++-------------- .../modsettings/gui/ModSettingsScreen.java | 2 +- .../mag/modsettings/mixin/ScreenMixin.java | 10 +++---- src/main/resources/fabric.mod.json | 2 +- 5 files changed, 19 insertions(+), 31 deletions(-) diff --git a/gradle.properties b/gradle.properties index 37576a4..ef24e02 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.19.3 -yarn_mappings=1.19.3+build.5 -loader_version=0.14.17 +minecraft_version=1.19.4 +yarn_mappings=1.19.4+build.2 +loader_version=0.15.10 # Mod Properties project_name=Mod Settings -mod_version=1.1.0+1.19.3 +mod_version=1.1.0+1.19.4 maven_group=se.icus.mag archives_base_name=modsettings # Fabric api -fabric_version=0.76.0+1.19.3 +fabric_version=0.87.2+1.19.4 diff --git a/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java b/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java index 28252fa..1133b98 100644 --- a/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java +++ b/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java @@ -1,19 +1,11 @@ package se.icus.mag.modsettings.gui; -import java.util.Optional; +import java.util.List; import net.fabricmc.fabric.api.client.screen.v1.Screens; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.GameMenuScreen; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.TitleScreen; import net.minecraft.client.gui.widget.ClickableWidget; -import net.minecraft.client.gui.widget.GridWidget; -import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableTextContent; - -import java.util.List; -import se.icus.mag.modsettings.mixin.GridWidgetAccessor; public abstract class MenuScreensChanger { private static final int TITLE_FULL_BUTTON_WIDTH = 200; @@ -22,17 +14,14 @@ public abstract class MenuScreensChanger { private static final int BUTTON_HEIGHT = 20; private static final int BUTTON_VERICAL_SPACING = 24; - public static void postTitleScreenInit(TitleScreen screen) { + public static void postTitleScreenInit(Screen screen) { List buttons = Screens.getButtons(screen); - injectModSettingsButton(screen, buttons, TITLE_FULL_BUTTON_WIDTH, 2, BUTTON_VERICAL_SPACING / 2); + injectModSettingsButton(screen, buttons, TITLE_FULL_BUTTON_WIDTH, 2, BUTTON_VERICAL_SPACING / 2); } - public static void postGameMenuScreenInit(GameMenuScreen screen) { - Optional gridWidgetOpt = Screens.getButtons(screen).stream().filter(w -> w instanceof GridWidget).findFirst(); - if (gridWidgetOpt.isEmpty()) return; - - List buttons = ((GridWidgetAccessor) gridWidgetOpt.get()).getChildren(); - injectModSettingsButton(screen, buttons, INGAME_FULL_BUTTON_WIDTH, 4, 0); + public static void postGameMenuScreenInit(Screen screen) { + List buttons = Screens.getButtons(screen); + injectModSettingsButton(screen, buttons, INGAME_FULL_BUTTON_WIDTH, 4, 0); } private static void injectModSettingsButton(Screen screen, List buttons, int fullButtonWidth, @@ -85,8 +74,7 @@ private static void injectModSettingsButton(Screen screen, List private static boolean buttonHasText(ClickableWidget button, String translationKey) { Text text = button.getMessage(); - return text instanceof MutableText mutableText && - mutableText.getContent().equals(new TranslatableTextContent(translationKey)); + return text.getContent().equals(Text.translatable(translationKey).getContent()); } public static class ModSettingsButton extends Button { diff --git a/src/main/java/se/icus/mag/modsettings/gui/ModSettingsScreen.java b/src/main/java/se/icus/mag/modsettings/gui/ModSettingsScreen.java index c548187..4d70174 100644 --- a/src/main/java/se/icus/mag/modsettings/gui/ModSettingsScreen.java +++ b/src/main/java/se/icus/mag/modsettings/gui/ModSettingsScreen.java @@ -62,7 +62,7 @@ private ModSettingsOption[] getAllModConfigOptions() { public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { this.renderBackground(matrices); this.list.render(matrices, mouseX, mouseY, delta); - drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 5, TITLE_COLOR); + drawCenteredTextWithShadow(matrices, this.textRenderer, this.title, this.width / 2, 5, TITLE_COLOR); super.render(matrices, mouseX, mouseY, delta); } diff --git a/src/main/java/se/icus/mag/modsettings/mixin/ScreenMixin.java b/src/main/java/se/icus/mag/modsettings/mixin/ScreenMixin.java index a06ca5d..da08450 100644 --- a/src/main/java/se/icus/mag/modsettings/mixin/ScreenMixin.java +++ b/src/main/java/se/icus/mag/modsettings/mixin/ScreenMixin.java @@ -1,8 +1,6 @@ package se.icus.mag.modsettings.mixin; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.AbstractParentElement; -import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.screen.GameMenuScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.TitleScreen; @@ -12,11 +10,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import se.icus.mag.modsettings.gui.MenuScreensChanger; -// Set priority so we run after ModMenu (1000) and MinimalMenu (1100) +// Set priority so we run after Fabric API, used by ModMenu, which uses +// the default priority (1000). We also avoid conflict with MinimalMenu +// which hooks into TitleScreen.init(), which is called as part of Screen.init() @Mixin(value = Screen.class, priority = 1500) -public abstract class ScreenMixin extends AbstractParentElement implements Drawable { +public abstract class ScreenMixin { - @Inject(method = "init(Lnet/minecraft/client/MinecraftClient;II)V", at = @At("RETURN")) + @Inject(method = "init(Lnet/minecraft/client/MinecraftClient;II)V", at = @At("TAIL")) private void init(MinecraftClient client, int width, int height, CallbackInfo info) { Screen screen = (Screen) (Object) this; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 20edc1a..93fa89c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,6 +33,6 @@ "fabricloader": ">=0.7.4", "fabric-screen-api-v1": ">=1.0.4", "fabric-key-binding-api-v1": ">=1.0.1", - "minecraft": "~1.19" + "minecraft": "1.19.4" } }