From 8228947989acd5c538d0f1c51eeba1c2054e5298 Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Mon, 18 Sep 2023 16:41:19 -0400 Subject: [PATCH] Update the mod to work with all versions from >=1.16 Support for older versions is planned, but I don't have a reason to actively work on it The mixins are updated to apply the smallest change possible: only replacing relevant accesses to `MinecraftClient.IS_SYSTEM_MAC` with `false`. --- build.gradle | 39 +++--- gradle.properties | 8 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../dev/pfaff/thinksame/mixin/MouseMixin.java | 113 +----------------- .../pfaff/thinksame/mixin/ScreenMixin.java | 19 +-- src/main/resources/fabric.mod.json | 2 +- version.properties | 4 +- 7 files changed, 39 insertions(+), 148 deletions(-) diff --git a/build.gradle b/build.gradle index 03efe47..df6c693 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,8 @@ plugins { - id 'fabric-loom' version '0.6-SNAPSHOT' + id 'fabric-loom' version '1.3-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 - archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group @@ -59,15 +56,15 @@ dependencies { } processResources { - inputs.property "version", "${project.version}+build.${versionBuild}" + inputs.property "version", project.version + inputs.property "minecraft_version", project.minecraft_version + inputs.property "loader_version", project.loader_version + filteringCharset "UTF-8" - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" - expand "version": "${project.version}+build.${versionBuild}" - } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" + filesMatching("fabric.mod.json") { + expand "version": project.version, + "minecraft_version": project.minecraft_version, + "loader_version": project.loader_version } } @@ -78,20 +75,22 @@ tasks.withType(JavaCompile) { options.encoding = "UTF-8" } -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource -} - gradle.taskGraph.whenReady {taskGraph -> if (taskGraph.hasTask(build)) { /* when run remapJar, build, runClient, or runServer task */ autoIncrementBuildNumber() } } +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + jar { from "LICENSE" } diff --git a/gradle.properties b/gradle.properties index 3cac24c..d109141 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,11 +2,11 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.16.4 -yarn_mappings=1.16.4+build.9 -loader_version=0.10.8 +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.10 +loader_version=0.14.22 # Mod Properties -mod_version=1.1.0 +mod_version=1.1.1 maven_group=dev.pfaff archives_base_name=thinksame diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bb8b2fc..db9a6b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/dev/pfaff/thinksame/mixin/MouseMixin.java b/src/main/java/dev/pfaff/thinksame/mixin/MouseMixin.java index bbfead9..f6807ff 100644 --- a/src/main/java/dev/pfaff/thinksame/mixin/MouseMixin.java +++ b/src/main/java/dev/pfaff/thinksame/mixin/MouseMixin.java @@ -1,117 +1,16 @@ package dev.pfaff.thinksame.mixin; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.Mouse; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.options.KeyBinding; -import net.minecraft.client.util.GlfwUtil; -import net.minecraft.client.util.InputUtil; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; + +import static org.objectweb.asm.Opcodes.GETSTATIC; -// TODO: modify injection to not overwrite whole method. @Mixin(Mouse.class) public abstract class MouseMixin { - @Shadow @Final private MinecraftClient client; - - @Shadow private int field_1796; - - @Shadow private int activeButton; - - @Shadow private double glfwTime; - - @Shadow private boolean cursorLocked; - - @Shadow public abstract void lockCursor(); - - @Shadow private double x; - - @Shadow private double y; - - @Shadow private boolean leftButtonClicked; - - @Shadow private boolean middleButtonClicked; - - @Shadow private boolean rightButtonClicked; - - @Inject(method = "onMouseButton", at = @At("HEAD"), cancellable = true) - private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) { - ci.cancel(); - - if (window == this.client.getWindow().getHandle()) { - boolean bl = action == 1; -// if (MinecraftClient.IS_SYSTEM_MAC && button == 0) { -// if (bl) { -// if ((mods & 2) == 2) { -// button = 1; -// ++this.controlLeftTicks; -// } -// } else if (this.controlLeftTicks > 0) { -// button = 1; -// --this.controlLeftTicks; -// } -// } - - if (bl) { - if (this.client.options.touchscreen && this.field_1796++ > 0) { - return; - } - - this.activeButton = button; - this.glfwTime = GlfwUtil.getTime(); - } else if (this.activeButton != -1) { - if (this.client.options.touchscreen && --this.field_1796 > 0) { - return; - } - - this.activeButton = -1; - } - - boolean[] bls = new boolean[]{false}; - if (this.client.overlay == null) { - if (this.client.currentScreen == null) { - if (!this.cursorLocked && bl) { - this.lockCursor(); - } - } else { - double d = this.x * (double)this.client.getWindow().getScaledWidth() / (double)this.client.getWindow().getWidth(); - double e = this.y * (double)this.client.getWindow().getScaledHeight() / (double)this.client.getWindow().getHeight(); - if (bl) { - Screen.wrapScreenError(() -> { - bls[0] = this.client.currentScreen.mouseClicked(d, e, button); - }, "mouseClicked event handler", this.client.currentScreen.getClass().getCanonicalName()); - } else { - Screen.wrapScreenError(() -> { - bls[0] = this.client.currentScreen.mouseReleased(d, e, button); - }, "mouseReleased event handler", this.client.currentScreen.getClass().getCanonicalName()); - } - } - } - - if (!bls[0] && (this.client.currentScreen == null || this.client.currentScreen.passEvents) && this.client.overlay == null) { - if (button == 0) { - this.leftButtonClicked = bl; - } else if (button == 2) { - this.middleButtonClicked = bl; - } else if (button == 1) { - this.rightButtonClicked = bl; - } - - KeyBinding.setKeyPressed(InputUtil.Type.MOUSE.createFromCode(button), bl); - if (bl) { - if (this.client.player.isSpectator() && button == 2) { - this.client.inGameHud.getSpectatorHud().useSelectedCommand(); - } else { - KeyBinding.onKeyPressed(InputUtil.Type.MOUSE.createFromCode(button)); - } - } - } - - } + @Redirect(method = "onMouseButton", at = @At(value = "FIELD", opcode = GETSTATIC, target = "Lnet/minecraft/client/MinecraftClient;IS_SYSTEM_MAC:Z")) + private boolean onMouseButton$noMacOS() { + return false; } } diff --git a/src/main/java/dev/pfaff/thinksame/mixin/ScreenMixin.java b/src/main/java/dev/pfaff/thinksame/mixin/ScreenMixin.java index e29046f..a98aada 100644 --- a/src/main/java/dev/pfaff/thinksame/mixin/ScreenMixin.java +++ b/src/main/java/dev/pfaff/thinksame/mixin/ScreenMixin.java @@ -1,23 +1,16 @@ package dev.pfaff.thinksame.mixin; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.Redirect; + +import static org.objectweb.asm.Opcodes.GETSTATIC; @Mixin(Screen.class) public abstract class ScreenMixin { - @Inject(method = "hasControlDown", at = @At("HEAD"), cancellable = true) - private static void hasControlDown(CallbackInfoReturnable ci) { -// if (MinecraftClient.IS_SYSTEM_MAC) { -// return InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 343) || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 347); -// } else { -// return InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 341) || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 345); -// } - - ci.setReturnValue(InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 341) || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 345)); + @Redirect(method = "hasControlDown", at = @At(value = "FIELD", opcode = GETSTATIC, target = "Lnet/minecraft/client/MinecraftClient;IS_SYSTEM_MAC:Z")) + private static boolean hasControlDown$noMacOS() { + return false; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c146878..25542aa 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,6 +26,6 @@ ], "depends": { "fabricloader": ">=0.10.8", - "minecraft": "1.16.x" + "minecraft": ">=1.16" } } diff --git a/version.properties b/version.properties index 94aab16..ac4e3ff 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -#Wed Mar 24 03:57:29 EDT 2021 -VERSION_BUILD=9 +#Mon Sep 18 16:40:55 EDT 2023 +VERSION_BUILD=20