From 6f696910d28a557b8606bed9068cc05c1c70714d Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Thu, 23 May 2024 22:18:16 +1000 Subject: [PATCH] 1.7 part 1 - Fix https://github.com/hamarb123/MCMacOSInputFixes/issues/27 --- README.md | 7 ++-- gradle.properties | 2 +- .../FabricReflectionHelper.java | 2 +- .../macos_input_fixes/MixinPlugin.java | 14 ++++++-- ...in1.java => MouseOptionsScreenMixin9.java} | 2 +- .../mixin/gui/OptionListWidgetMixin8.java | 36 +++++++++++++++++++ ...ixin1.java => OptionListWidgetMixin9.java} | 2 +- 7 files changed, 57 insertions(+), 8 deletions(-) rename src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/{MouseOptionsScreenMixin1.java => MouseOptionsScreenMixin9.java} (95%) create mode 100644 src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin8.java rename src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/{OptionListWidgetMixin1.java => OptionListWidgetMixin9.java} (97%) diff --git a/README.md b/README.md index f90f1e9..d6bc305 100644 --- a/README.md +++ b/README.md @@ -61,17 +61,20 @@ If you make changes, you should test everything works properly on the following - 1.19 - 1.19.3 - 1.20 +- 1.21 ## Mixin Naming Scheme Some mixins are in a folder called `gui`, these mixins are to do with the option menu interface, or only used by other option menu interface code. Some mixins have a number at the end of their name, these mixins are conditionally loaded based on whether certain classes are available at runtime. The numbering is currently as follows (note some of the classes may have different names in different intermediary mappings, consult the latest applicable version if you can't find the class): 1. The `SimpleOption` class is available (1.19+) -2. The `Option` class is available (1.14-1.18) +2. The `Option` class is available (1.14-1.18.x) 3. The `CyclingButtonWidget` class is available (1.17+) -4. Both the `Option` and `CyclingButtonWidget` classes are available (1.17-1.18) +4. Both the `Option` and `CyclingButtonWidget` classes are available (1.17-1.18.x) 5. The `GameOptionsScreen.getHoveredButtonTooltip(ButtonListWidget, int, int)` function exists (1.16.2-1.19.2) 6. The `GameOptionsScreen.getHoveredButtonTooltip(ButtonListWidget, int, int)` function doesn't exist, the `Screen.renderTooltip(MatrixStack, List, int, int)` function exists, and the `Option` class exists (1.16-1.16.1) 7. Either 5 or 6 (1.16-1.19.2) +8. 1 and doesn't have `MouseOptionsScreen.init()` (1.21+) +9. 1 and has `MouseOptionsScreen.init()` (1.19-1.20.x) ## License diff --git a/gradle.properties b/gradle.properties index e19d11a..c501b0f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.14.22 # Mod Properties - mod_version = 1.6 + mod_version = 1.7 maven_group = com.hamarb123.macos_input_fixes archives_base_name = macos-input-fixes diff --git a/src/main/java/com/hamarb123/macos_input_fixes/FabricReflectionHelper.java b/src/main/java/com/hamarb123/macos_input_fixes/FabricReflectionHelper.java index f81345b..09566dc 100644 --- a/src/main/java/com/hamarb123/macos_input_fixes/FabricReflectionHelper.java +++ b/src/main/java/com/hamarb123/macos_input_fixes/FabricReflectionHelper.java @@ -537,7 +537,7 @@ public static Class SimpleOption_Callbacks() /** *

Intemediary name: {@code net.minecraft.class_7172$class_7277}

*

Mapped name: {@code net.minecraft.client.option.SimpleOption$TooltipFactoryGetter}

- *

Versions: 1.19+

+ *

Versions: 1.19-1.19.2

*/ public static Class SimpleOption_TooltipFactory() { diff --git a/src/main/java/com/hamarb123/macos_input_fixes/MixinPlugin.java b/src/main/java/com/hamarb123/macos_input_fixes/MixinPlugin.java index 3e3a184..110f470 100644 --- a/src/main/java/com/hamarb123/macos_input_fixes/MixinPlugin.java +++ b/src/main/java/com/hamarb123/macos_input_fixes/MixinPlugin.java @@ -49,6 +49,9 @@ public List getMixins() boolean hasScreen_renderTooltip = isMethodPresent(resolver.mapClassName("intermediary", "net.minecraft.class_437"), resolver.mapMethodName("intermediary", "net.minecraft.class_437", "method_25417", "(Lnet/minecraft/class_4587;Ljava/util/List;II)V"), "(L" + resolver.mapClassName("intermediary", "net.minecraft.class_4587").replace(".", "/") + ";Ljava/util/List;II)V"); + boolean hasMouseOptionsScreen_init = isMethodPresent(resolver.mapClassName("intermediary", "net.minecraft.class_4288"), + resolver.mapMethodName("intermediary", "net.minecraft.class_4288", "method_25426", "()V"), + "()V"); if (hasOptionClass) { li.add("gui.MouseOptionsScreenMixin2"); @@ -59,9 +62,16 @@ public List getMixins() } else { - li.add("gui.MouseOptionsScreenMixin1"); - li.add("gui.OptionListWidgetMixin1"); li.add("gui.SimpleOptionMixin1"); + if (hasMouseOptionsScreen_init) + { + li.add("gui.MouseOptionsScreenMixin9"); + li.add("gui.OptionListWidgetMixin9"); + } + else + { + li.add("gui.OptionListWidgetMixin8"); + } } if (hasCyclingButtonWidgetClass) { diff --git a/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/MouseOptionsScreenMixin1.java b/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/MouseOptionsScreenMixin9.java similarity index 95% rename from src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/MouseOptionsScreenMixin1.java rename to src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/MouseOptionsScreenMixin9.java index 3e716f3..5e3bc40 100644 --- a/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/MouseOptionsScreenMixin1.java +++ b/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/MouseOptionsScreenMixin9.java @@ -8,7 +8,7 @@ import net.minecraft.client.gui.screen.option.MouseOptionsScreen; @Mixin(MouseOptionsScreen.class) -public class MouseOptionsScreenMixin1 +public class MouseOptionsScreenMixin9 { //sets the modifyAddAllParameter() flag, which is checked and reset in ButtonListWidgetMixin1 @Inject(method = "init()V", at = @At("HEAD")) diff --git a/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin8.java b/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin8.java new file mode 100644 index 0000000..8b96fb1 --- /dev/null +++ b/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin8.java @@ -0,0 +1,36 @@ +package com.hamarb123.macos_input_fixes.mixin.gui; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import com.hamarb123.macos_input_fixes.ModOptions; +import net.minecraft.client.gui.screen.option.GameOptionsScreen; +import net.minecraft.client.gui.screen.option.MouseOptionsScreen; +import net.minecraft.client.gui.widget.OptionListWidget; +import net.minecraft.client.option.SimpleOption; + +@Mixin(OptionListWidget.class) +public class OptionListWidgetMixin8 +{ + @Shadow(remap = false, aliases = {"field_49483"}) + private GameOptionsScreen optionsScreen; + + //this is where we add additional menu options + @ModifyVariable(method = "addAll([Lnet/minecraft/client/option/SimpleOption;)V", at = @At("HEAD"), ordinal = 0) + private SimpleOption[] modifyAddAllParameter1(SimpleOption[] options) + { + //check if it's a MouseOptionsScreen, otherwise we don't want to modify + if (!(optionsScreen instanceof MouseOptionsScreen)) return options; + + //get the mod options so we can add them to the game options + Object[] modOptions = ModOptions.getModOptions(); + if (modOptions == null) return options; + + //combine the game options and mod options + SimpleOption[] newOptions = new SimpleOption[options.length + modOptions.length]; + for (int i = 0; i < options.length; i++) newOptions[i] = options[i]; + for (int i = 0; i < modOptions.length; i++) newOptions[options.length + i] = (SimpleOption)modOptions[i]; + return newOptions; + } +} diff --git a/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin1.java b/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin9.java similarity index 97% rename from src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin1.java rename to src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin9.java index 98a2c62..2ff4515 100644 --- a/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin1.java +++ b/src/main/java/com/hamarb123/macos_input_fixes/mixin/gui/OptionListWidgetMixin9.java @@ -9,7 +9,7 @@ import net.minecraft.client.option.SimpleOption; @Mixin(OptionListWidget.class) -public class OptionListWidgetMixin1 +public class OptionListWidgetMixin9 { //this is where we add additional menu options @ModifyVariable(method = "addAll([Lnet/minecraft/client/option/SimpleOption;)V", at = @At("HEAD"), ordinal = 0)