Skip to content

Commit 47a607d

Browse files
committed
Working 1.21.9 support
- Reduce min loader version back to 0.15.0 - Fix some whitespace - Fix `InputUtil_isKeyPressed_1` missing the return type - Use `Common.IS_SYSTEM_MAC` instead of `Util.getOperatingSystem() ` - Fix some mixins on older versions where the remapping no longer works due to updated mappings - Use java nio in ModOptions consistently
1 parent 298d42d commit 47a607d

12 files changed

Lines changed: 64 additions & 64 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx1G
55
# check these on https://fabricmc.net/develop
66
minecraft_version=1.21.9
77
yarn_mappings=1.21.9+build.1
8-
loader_version=0.17.2
8+
loader_version=0.15.0
99
loom_version=1.11-SNAPSHOT
1010

1111
# Mod Properties

settings.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
pluginManagement
22
{
3-
repositories
4-
{
5-
maven
6-
{
7-
name = 'Fabric'
8-
url = 'https://maven.fabricmc.net/'
9-
}
10-
mavenCentral()
11-
gradlePluginPortal()
12-
}
3+
repositories
4+
{
5+
maven
6+
{
7+
name = 'Fabric'
8+
url = 'https://maven.fabricmc.net/'
9+
}
10+
mavenCentral()
11+
gradlePluginPortal()
12+
}
1313
}

src/client/java/com/hamarb123/macos_input_fixes/client/FabricReflectionHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ public static String NbtCompound_getString_1(NbtCompound instance, String key)
731731
*/
732732
public static boolean InputUtil_isKeyPressed_1(long handle, int code)
733733
{
734-
if (_InputUtil_isKeyPressed_1Method == null) _InputUtil_isKeyPressed_1Method = lookupMethod("net.minecraft.class_3675", "method_15987", "(JI)Z", true, false, InputUtil.class, "isKeyPressed", long.class, int.class);
734+
if (_InputUtil_isKeyPressed_1Method == null) _InputUtil_isKeyPressed_1Method = lookupMethod("net.minecraft.class_3675", "method_15987", "(JI)Z", true, false, InputUtil.class, "isKeyPressed", boolean.class, long.class, int.class);
735735
return (boolean)invokeMethod("isKeyPressed", _InputUtil_isKeyPressed_1Method, handle, code);
736736
}
737737
private static MethodHandle _InputUtil_isKeyPressed_1Method;

src/client/java/com/hamarb123/macos_input_fixes/client/MacOSInputFixesClientMod.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.IOException;
44
import net.fabricmc.api.ClientModInitializer;
5-
import net.minecraft.util.Util;
65

76
public class MacOSInputFixesClientMod implements ClientModInitializer
87
{
@@ -20,7 +19,7 @@ public void onInitializeClient()
2019

2120
static
2221
{
23-
if (Util.getOperatingSystem() == Util.OperatingSystem.OSX)
22+
if (Common.IS_SYSTEM_MAC)
2423
{
2524
try
2625
{

src/client/java/com/hamarb123/macos_input_fixes/client/MixinPlugin.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,47 +125,47 @@ public List<String> getMixins()
125125

126126
private static boolean isClassPresent(String className)
127127
{
128-
try
128+
try
129129
{
130-
MixinService.getService().getBytecodeProvider().getClassNode(className);
131-
return true;
132-
}
130+
MixinService.getService().getBytecodeProvider().getClassNode(className);
131+
return true;
132+
}
133133
catch (ClassNotFoundException ignored)
134134
{
135-
// Class isn't present, skip this mixin.
136-
return false;
137-
}
135+
// Class isn't present, skip this mixin.
136+
return false;
137+
}
138138
catch (Exception e)
139139
{
140-
// Something else went wrong which might be more serious.
141-
e.printStackTrace();
142-
return false;
143-
}
144-
}
140+
// Something else went wrong which might be more serious.
141+
e.printStackTrace();
142+
return false;
143+
}
144+
}
145145

146146
private static boolean isMethodPresent(String className, String methodName, String descriptor)
147147
{
148-
try
148+
try
149149
{
150-
ClassNode classNode = MixinService.getService().getBytecodeProvider().getClassNode(className);
150+
ClassNode classNode = MixinService.getService().getBytecodeProvider().getClassNode(className);
151151
for (MethodNode methodNode : classNode.methods)
152152
{
153153
if (methodNode.name.equals(methodName) && methodNode.desc.equals(descriptor)) return true;
154154
}
155-
return false;
156-
}
155+
return false;
156+
}
157157
catch (ClassNotFoundException ignored)
158158
{
159-
// Class isn't present, skip this mixin.
160-
return false;
161-
}
159+
// Class isn't present, skip this mixin.
160+
return false;
161+
}
162162
catch (Exception e)
163163
{
164-
// Something else went wrong which might be more serious.
165-
e.printStackTrace();
166-
return false;
167-
}
168-
}
164+
// Something else went wrong which might be more serious.
165+
e.printStackTrace();
166+
return false;
167+
}
168+
}
169169

170170
@Override
171171
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo)

src/client/java/com/hamarb123/macos_input_fixes/client/ModOptions.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.hamarb123.macos_input_fixes.client;
22

3-
import java.io.File;
4-
import java.io.FileInputStream;
5-
import java.io.FileOutputStream;
63
import java.io.IOException;
74
import java.io.OutputStreamWriter;
85
import java.io.PrintWriter;
96
import java.lang.reflect.Constructor;
107
import java.lang.reflect.ParameterizedType;
118
import java.nio.charset.StandardCharsets;
129
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
1312
import java.util.ArrayList;
1413
import java.util.Iterator;
1514
import java.util.List;
@@ -31,7 +30,6 @@
3130
import net.minecraft.client.option.GameOptions;
3231
import net.minecraft.nbt.NbtCompound;
3332
import net.minecraft.text.Text;
34-
import net.minecraft.util.Util;
3533

3634
@Environment(EnvType.CLIENT)
3735
public class ModOptions
@@ -522,41 +520,41 @@ private static String getStringHelper(NbtCompound instance, String key)
522520
}
523521
}
524522

525-
public static File optionsFile;
523+
public static Path optionsFile;
526524

527525
@SuppressWarnings("resource")
528526
public static void loadOptions()
529527
{
530528
//locate options file
531-
optionsFile = new File(FabricLoader.getInstance().getConfigDir().toAbsolutePath().toString(), "macos_input_fixes.txt");
529+
optionsFile = FabricLoader.getInstance().getConfigDir().resolve("macos_input_fixes.txt");
532530

533531
//check if we need to migrate from the old path
534-
if (!optionsFile.exists())
532+
if (!Files.exists(optionsFile))
535533
{
536-
File oldFile = new File(MinecraftClient.getInstance().runDirectory, "options_macos_input_fixes.txt");
537-
if (oldFile.exists())
534+
Path oldFile = Paths.get(MinecraftClient.getInstance().runDirectory.getAbsolutePath(), "options_macos_input_fixes.txt");
535+
if (Files.exists(oldFile))
538536
{
539-
optionsFile.getParentFile().mkdir();
540537
try
541538
{
542-
Files.copy(oldFile.toPath(), optionsFile.toPath());
539+
Files.createDirectories(optionsFile.getParent());
540+
Files.copy(oldFile, optionsFile);
541+
Files.deleteIfExists(oldFile);
543542
}
544543
catch (IOException e)
545544
{
546-
throw new RuntimeException("Failed to migrate old macos input fixes options file from " + oldFile.toPath() + " to " + optionsFile.toPath(), e);
545+
throw new RuntimeException("Failed to migrate old macos input fixes options file from " + oldFile + " to " + optionsFile, e);
547546
}
548-
oldFile.delete();
549547
}
550548
}
551549

552550
//load options similarly to how minecraft does
553551
try
554552
{
555-
if (!optionsFile.exists())
553+
if (!Files.exists(optionsFile))
556554
{
557555
return;
558556
}
559-
List<String> lines = IOUtils.readLines(new FileInputStream(optionsFile), StandardCharsets.UTF_8); //split by lines
557+
List<String> lines = IOUtils.readLines(Files.newInputStream(optionsFile), StandardCharsets.UTF_8); //split by lines
560558
NbtCompound compoundTag = new NbtCompound();
561559
for (String line : lines) //read the lines into a tag
562560
{
@@ -666,7 +664,7 @@ public static void loadOptions()
666664
public static void saveOptions()
667665
{
668666
//write the options to the file in a similar way to minecraft
669-
try (PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(optionsFile), StandardCharsets.UTF_8)))
667+
try (PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(Files.newOutputStream(optionsFile), StandardCharsets.UTF_8)))
670668
{
671669
printWriter.println("trackpadSensitivity:" + trackpadSensitivity);
672670
printWriter.println("reverseHotbarScrolling:" + reverseHotbarScrolling);
@@ -690,7 +688,7 @@ public static void saveOptions()
690688
public static void setTrackpadSensitivity(double value)
691689
{
692690
trackpadSensitivity = value;
693-
if (Util.getOperatingSystem() != Util.OperatingSystem.OSX) return;
691+
if (!Common.IS_SYSTEM_MAC) return;
694692

695693
//set the value in the native library also, ensure the value is clamped here
696694
if (value < 0) value = 0.0;
@@ -714,7 +712,7 @@ public static void setTrackpadSensitivity(double value)
714712
public static void setMomentumScrolling(boolean value)
715713
{
716714
momentumScrolling = value;
717-
if (Util.getOperatingSystem() != Util.OperatingSystem.OSX) return;
715+
if (!Common.IS_SYSTEM_MAC) return;
718716

719717
//set the value in the native library also
720718
MacOSInputFixesClientMod.setMomentumScrolling(value);
@@ -726,7 +724,7 @@ public static void setMomentumScrolling(boolean value)
726724
public static void setInterfaceSmoothScroll(boolean value)
727725
{
728726
interfaceSmoothScroll = value;
729-
if (Util.getOperatingSystem() != Util.OperatingSystem.OSX) return;
727+
if (!Common.IS_SYSTEM_MAC) return;
730728

731729
//set the value in the native library also
732730
MacOSInputFixesClientMod.setInterfaceSmoothScroll(value);

src/client/java/com/hamarb123/macos_input_fixes/client/mixin/HandledScreenMixin13.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
public class HandledScreenMixin13
1515
{
1616
@ModifyExpressionValue(method = "keyPressed(Lnet/minecraft/client/input/KeyInput;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/KeyInput;hasCtrl()Z"))
17-
private boolean keyPressedHasCtrlAdjustment(boolean result, @Local(argsOnly = true) KeyInput input)
17+
private boolean keyPressedHasCtrlAdjustment(boolean result, @Local(argsOnly = true) KeyInput input)
1818
{
1919
if (!result && Common.IS_SYSTEM_MAC)
2020
{
2121
result = (((AbstractInput)Common.asObject(input)).modifiers() & 2) != 0;
2222
}
2323
return result;
24-
}
24+
}
2525
}

src/client/java/com/hamarb123/macos_input_fixes/client/mixin/KeyboardMixin12.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
@Mixin(Keyboard.class)
1414
public class KeyboardMixin12
1515
{
16-
@Inject(at = @At("HEAD"), method = "onKey(JIIII)V", cancellable = true)
16+
//@Inject(at = @At("HEAD"), method = "onKey(JIIII)V", cancellable = true)
17+
@Inject(at = @At("HEAD"), method = "method_1466(JIIII)V", cancellable = true, remap = false)
1718
public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo info)
1819
{
1920
if (Common.IS_SYSTEM_MAC)

src/client/java/com/hamarb123/macos_input_fixes/client/mixin/PlayerInventoryMixin10.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
@Mixin(PlayerInventory.class)
1212
public class PlayerInventoryMixin10
1313
{
14-
@ModifyVariable(method = "scrollInHotbar(D)V", at = @At("HEAD"), ordinal = 0)
14+
//@ModifyVariable(method = "scrollInHotbar(D)V", at = @At("HEAD"), ordinal = 0)
15+
@ModifyVariable(method = "method_7373(D)V", at = @At("HEAD"), ordinal = 0)
1516
private double fixHotbarScrollDirection(double d)
1617
{
1718
//if the reverse hotbar scrolling option is enabled, reverse the scroll value

src/client/java/com/hamarb123/macos_input_fixes/client/mixin/gui/MouseOptionsScreenMixin5.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@Mixin(MouseOptionsScreen.class)
1717
public abstract class MouseOptionsScreenMixin5
1818
{
19-
@Shadow
19+
@Shadow(aliases = "field_19246", remap = false)
2020
private OptionListWidget buttonList;
2121

2222
@Inject(method = "method_25394(Lnet/minecraft/class_4587;IIF)V", at = @At("RETURN"), cancellable = true, remap = false)

0 commit comments

Comments
 (0)