From c44c0859b54c6a130e2c932ae800b8b1bc1bb5d9 Mon Sep 17 00:00:00 2001 From: XXMA16 <81380344+XXMA16@users.noreply.github.com> Date: Wed, 8 Mar 2023 01:54:11 +0200 Subject: [PATCH 01/13] Fix renderBlock call in lower versions (<=1.18.2) (#986) * Fix 1.18.2 Fabric API --------- Co-authored-by: XXMA16 --- .../me/modmuss50/optifabric/patcher/fixes/ChunkRendererFix.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/me/modmuss50/optifabric/patcher/fixes/ChunkRendererFix.java b/src/main/java/me/modmuss50/optifabric/patcher/fixes/ChunkRendererFix.java index ed6fc929..c756d46e 100644 --- a/src/main/java/me/modmuss50/optifabric/patcher/fixes/ChunkRendererFix.java +++ b/src/main/java/me/modmuss50/optifabric/patcher/fixes/ChunkRendererFix.java @@ -41,6 +41,8 @@ public void fix(ClassNode classNode, ClassNode old) { if (trailingBoolean) end--; boolean trailingRenderLayer = RemappingUtils.getClassName("class_1921").equals(args[end].getInternalName()); if (trailingRenderLayer) end--; + assert "net/minecraftforge/client/model/data/IModelData".equals(args[end].getInternalName()); + end--; assert end > 0 && Type.BOOLEAN == args[end - 1].getSort(); boolean nativeRandom = "java/util/Random".equals(args[end].getInternalName()); String desc = "(Lnet/minecraft/class_2680;" From 3c74384a28581c58fe8ccc1a8ab4c49a1d663341 Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Tue, 14 Mar 2023 18:28:08 +0200 Subject: [PATCH 02/13] Fix multiconnect beta versions --- src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 4797af8f..59c1ba3d 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -253,7 +253,7 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.compat.trumpet-skeleton.mixins.json"); } - if (isPresent("multiconnect", ">1.3.14")) { + if (isPresent("multiconnect", ">1.3.14 <1.6-beta.1")) { Mixins.addConfiguration("optifabric.compat.multiconnect.mixins.json"); } From 95f7f519bcabd02acce1dc452a73467be8ac29f8 Mon Sep 17 00:00:00 2001 From: Chocohead Date: Wed, 22 Mar 2023 01:58:10 +0000 Subject: [PATCH 03/13] Add support for 1.19.4 Needs another Fabric API fix (which also applies to 1.19.3) --- gradle.properties | 2 +- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index bfd10724..22ea41c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ loader_version=0.12.5 fabric_version=0.42.0+1.16 fabric_asm_version=v2.3 -mod_version = 1.13.21 +mod_version = 1.13.22 maven_group = me.modmuss50 archives_base_name = optifabric diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5c33b768..6ff1e350 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -35,7 +35,7 @@ }, "depends": { "fabricloader": ">=0.8.0", - "minecraft": ["1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5", "1.17-alpha.21.8.b", "1.17-beta.4", "1.17", "1.17.1", "1.18-beta.1", "1.18", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3"], + "minecraft": ["1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5", "1.17-alpha.21.8.b", "1.17-beta.4", "1.17", "1.17.1", "1.18-beta.1", "1.18", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4"], "mm": ">=2.0" }, "conflicts": { From 013de6a71e8ba8c0d4f62bc3ebb8ff2d1a1c8045 Mon Sep 17 00:00:00 2001 From: Chocohead Date: Wed, 22 Mar 2023 02:06:37 +0000 Subject: [PATCH 04/13] Fix Fabric API 0.76.0+ Hopefully Forge's patch doesn't cause too much chaos with Fabric's on top in practice --- build.gradle | 2 + gradle.properties | 2 +- .../RenderingExtraMixinPlugin.java | 74 +++++++++++++++++++ .../mixin/ShaderProgramMixin.java | 26 +++++++ .../optifabric/mod/OptifabricSetup.java | 3 + ....compat.fabric-rendering.extra-mixins.json | 8 ++ src/shim/java/net/minecraft/class_5944.java | 4 + 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/modmuss50/optifabric/compat/fabricrendering/RenderingExtraMixinPlugin.java create mode 100644 src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/ShaderProgramMixin.java create mode 100644 src/main/resources/optifabric.compat.fabric-rendering.extra-mixins.json create mode 100644 src/shim/java/net/minecraft/class_5944.java diff --git a/build.gradle b/build.gradle index a59c6f8c..14abd265 100644 --- a/build.gradle +++ b/build.gradle @@ -71,6 +71,8 @@ compileJava { method 'net/minecraft/client/render/WorldRenderer', '(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;' + 'Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lorg/joml/Matrix4f;)V', 'render', 'method_22710' method 'net/minecraft/client/gui/screen/Screen', '(Lnet/minecraft/client/util/math/MatrixStack;IIF)V', 'renderWithTooltip', 'method_47413' + classes += ['net/minecraft/class_5944': 'net/minecraft/class_5944'] + method 'net/minecraft/class_5944', '(Lnet/minecraft/class_5912;Lnet/minecraft/util/Identifier;Lnet/minecraft/client/render/VertexFormat;)V', '', '' } } diff --git a/gradle.properties b/gradle.properties index 22ea41c8..d7ce1aba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ loader_version=0.12.5 fabric_version=0.42.0+1.16 fabric_asm_version=v2.3 -mod_version = 1.13.22 +mod_version = 1.13.23 maven_group = me.modmuss50 archives_base_name = optifabric diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/RenderingExtraMixinPlugin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/RenderingExtraMixinPlugin.java new file mode 100644 index 00000000..e879a809 --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/RenderingExtraMixinPlugin.java @@ -0,0 +1,74 @@ +package me.modmuss50.optifabric.compat.fabricrendering; + +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InsnList; +import org.objectweb.asm.tree.JumpInsnNode; +import org.objectweb.asm.tree.LabelNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; + +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import me.modmuss50.optifabric.compat.InterceptingMixinPlugin; +import me.modmuss50.optifabric.util.RemappingUtils; + +public class RenderingExtraMixinPlugin extends InterceptingMixinPlugin { + private static final String FAKE_IDENTIFIER = "me/modmuss50/optifabric/fake/Identifier"; + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + if ("ShaderProgramMixin".equals(mixinInfo.getName())) {//(ResourceFactory, VertexFormat) + String desc = RemappingUtils.mapMethodDescriptor("(Lnet/minecraft/class_5912;Ljava/lang/String;Lnet/minecraft/class_293;)V"); + + for (MethodNode method : targetClass.methods) { + if ("".equals(method.name) && desc.equals(method.desc)) { + String identifier = RemappingUtils.getClassName("class_2960"); + + for (AbstractInsnNode insn : method.instructions) { + if (insn.getType() == AbstractInsnNode.METHOD_INSN && insn.getOpcode() == Opcodes.INVOKESPECIAL) { + MethodInsnNode minsn = (MethodInsnNode) insn; + + if (identifier.equals(minsn.owner) && "".equals(minsn.name) && "(Ljava/lang/String;)V".equals(minsn.desc)) { + minsn.owner = FAKE_IDENTIFIER; + } + } + } + + InsnList extra = new InsnList(); + LabelNode skip = new LabelNode(); + extra.add(new JumpInsnNode(Opcodes.GOTO, skip)); + extra.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, identifier, "", "(Ljava/lang/String;)V", false)); + extra.add(skip); + method.instructions.insertBefore(method.instructions.getLast(), extra); + break; + } + } + } + + super.preApply(targetClassName, targetClass, mixinClassName, mixinInfo); + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + if ("ShaderProgramMixin".equals(mixinInfo.getName())) {//(ResourceFactory, VertexFormat) + String desc = RemappingUtils.mapMethodDescriptor("(Lnet/minecraft/class_5912;Ljava/lang/String;Lnet/minecraft/class_293;)V"); + + for (MethodNode method : targetClass.methods) { + if ("".equals(method.name) && desc.equals(method.desc)) { + String identifier = RemappingUtils.getClassName("class_2960"); + + for (AbstractInsnNode insn : method.instructions) { + if (insn.getType() == AbstractInsnNode.METHOD_INSN && FAKE_IDENTIFIER.equals(((MethodInsnNode) insn).owner)) { + ((MethodInsnNode) insn).owner = identifier; + } + } + break; + } + } + } + + super.postApply(targetClassName, targetClass, mixinClassName, mixinInfo); + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/ShaderProgramMixin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/ShaderProgramMixin.java new file mode 100644 index 00000000..1e5260ff --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/ShaderProgramMixin.java @@ -0,0 +1,26 @@ +package me.modmuss50.optifabric.compat.fabricrendering.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +import net.minecraft.class_5944; +import net.minecraft.util.Identifier; + +import me.modmuss50.optifabric.compat.InterceptingMixin; +import me.modmuss50.optifabric.compat.Shim; + +@Mixin(class_5944.class) +@InterceptingMixin("net/fabricmc/fabric/mixin/client/rendering/shader/ShaderProgramMixin") +abstract class ShaderProgramMixin { + @Shim + private native String modifyProgramId(String id); + + @ModifyVariable(method = "(Lnet/minecraft/class_5912;Lnet/minecraft/util/Identifier;Lnet/minecraft/client/render/VertexFormat;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Identifier;getNamespace()Ljava/lang/String;", ordinal = 0), argsOnly = true, allow = 1) + private Identifier modifyProgramID(Identifier id) { + String in = id.toString(); + String out = modifyProgramId(in); + return in != out ? new Identifier(out) : id; + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 59c1ba3d..c5e2399d 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -134,6 +134,9 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.compat.fabric-rendering.mixins.json"); } } + if (isPresent("fabric-rendering-v1", ">=1.13.0 <2.0") || isPresent("fabric-rendering-v1", ">=2.1.0")) { + Mixins.addConfiguration("optifabric.compat.fabric-rendering.extra-mixins.json"); + } if (isPresent("fabric-rendering-data-attachment-v1")) { Mixins.addConfiguration("optifabric.compat.fabric-rendering-data.mixins.json"); diff --git a/src/main/resources/optifabric.compat.fabric-rendering.extra-mixins.json b/src/main/resources/optifabric.compat.fabric-rendering.extra-mixins.json new file mode 100644 index 00000000..8d7fba3e --- /dev/null +++ b/src/main/resources/optifabric.compat.fabric-rendering.extra-mixins.json @@ -0,0 +1,8 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.fabricrendering.mixin", + "plugin": "me.modmuss50.optifabric.compat.fabricrendering.RenderingExtraMixinPlugin", + "mixins": [ + "ShaderProgramMixin" + ] +} \ No newline at end of file diff --git a/src/shim/java/net/minecraft/class_5944.java b/src/shim/java/net/minecraft/class_5944.java new file mode 100644 index 00000000..95d75012 --- /dev/null +++ b/src/shim/java/net/minecraft/class_5944.java @@ -0,0 +1,4 @@ +package net.minecraft; + +public class class_5944 { +} \ No newline at end of file From f0e558c43362ea2a38e8d2e801217190a58e9666 Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Sun, 19 Mar 2023 12:27:55 +0200 Subject: [PATCH 05/13] Fix architectury 1.19.3 --- .../mixin/GameRendererNewerererMixin.java | 47 +++++++++++++++++++ .../optifabric/mod/OptifabricSetup.java | 4 +- ...mpat.architectury-AB.newererer-mixins.json | 8 ++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNewerererMixin.java create mode 100644 src/main/resources/optifabric.compat.architectury-AB.newererer-mixins.json diff --git a/src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNewerererMixin.java b/src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNewerererMixin.java new file mode 100644 index 00000000..15003892 --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNewerererMixin.java @@ -0,0 +1,47 @@ +package me.modmuss50.optifabric.compat.architectury.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.util.Window; +import net.minecraft.client.util.math.MatrixStack; +import org.joml.Matrix4f; + +import me.modmuss50.optifabric.compat.InterceptingMixin; +import me.modmuss50.optifabric.compat.PlacatingSurrogate; +import me.modmuss50.optifabric.compat.Shim; + +@Mixin(GameRenderer.class) +@InterceptingMixin("dev/architectury/mixin/fabric/client/MixinGameRenderer") +abstract class GameRendererNewerererMixin { + @Shim + private native void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, MatrixStack matrices, MatrixStack matrices2); + + @PlacatingSurrogate + private void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices) { + } + + @Inject(method = "render(FJZ)V", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", ordinal = 0)) + private void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices, MatrixStack matrices2) { + renderScreenPre(tickDelta, startTime, tick, ci, mouseX, mouseY, window, matrix, matrices, matrices2); + } + + @Shim + private native void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, MatrixStack matrices, MatrixStack matrices2); + + @PlacatingSurrogate + private void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices) { + } + + @Inject(method = "render(FJZ)V", locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", shift = Shift.AFTER, ordinal = 0)) + private void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices, MatrixStack matrices2) { + renderScreenPost(tickDelta, startTime, tick, ci, mouseX, mouseY, window, matrix, matrices, matrices2); + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index c5e2399d..0aff144f 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -400,7 +400,9 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.compat.images.mixins.json"); } - if (isPresent("architectury", ">=3.7")) { + if (isPresent("architectury", ">=7.0.52")) { + Mixins.addConfiguration("optifabric.compat.architectury-AB.newererer-mixins.json"); + } else if (isPresent("architectury", ">=3.7")) { Mixins.addConfiguration("optifabric.compat.architectury-AB.newerer-mixins.json"); } else if (isPresent("architectury", ">=2.0")) { assert isPresent("minecraft", ">=1.17-beta.1"); diff --git a/src/main/resources/optifabric.compat.architectury-AB.newererer-mixins.json b/src/main/resources/optifabric.compat.architectury-AB.newererer-mixins.json new file mode 100644 index 00000000..3d927ebe --- /dev/null +++ b/src/main/resources/optifabric.compat.architectury-AB.newererer-mixins.json @@ -0,0 +1,8 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.architectury.mixin", + "plugin": "me.modmuss50.optifabric.compat.InterceptingMixinPlugin", + "mixins": [ + "GameRendererNewerererMixin" + ] +} \ No newline at end of file From 9a9a80488df42b4b88bd1121f19814b2aeda3579 Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Sun, 19 Mar 2023 15:26:33 +0200 Subject: [PATCH 06/13] Fix JEI --- .../optifabric/patcher/fixes/KeyboardFix.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java b/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java index bf4a3c1d..d614ae53 100644 --- a/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java +++ b/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java @@ -1,5 +1,6 @@ package me.modmuss50.optifabric.patcher.fixes; +import com.google.common.collect.ImmutableList; import com.google.common.collect.MoreCollectors; import org.apache.commons.lang3.Validate; @@ -14,14 +15,26 @@ import me.modmuss50.optifabric.util.RemappingUtils; +import java.util.List; + public class KeyboardFix implements ClassFixer { //net/minecraft/client/Keyboard.onKey(JIIII)V private final String onKeyName = RemappingUtils.getMethodName("class_309", "method_1466", "(JIIII)V"); + private final String screenClass = RemappingUtils.getClassName("class_437"); + private final List onKeyLambdasNames = ImmutableList.of( + RemappingUtils.getMethodName("class_309", "method_1458", "(L" + screenClass + ";II)V"), + RemappingUtils.getMethodName("class_309", "method_1473", "(L" + screenClass + ";CI)V")); @Override public void fix(ClassNode optifine, ClassNode minecraft) { Validate.notNull(onKeyName, "onKeyName null"); + //Needed for JEI, might as well remove the useless forge checks optifine does + optifine.methods.removeIf(methodNode -> onKeyLambdasNames.contains(methodNode.name)); + minecraft.methods.stream() + .filter(methodNode -> onKeyLambdasNames.contains(methodNode.name)) + .forEach(methodNode -> optifine.methods.add(methodNode)); + //Remove the old "broken" method optifine.methods.removeIf(methodNode -> methodNode.name.equals(onKeyName)); From 647312a38672cf0635bef3f0f304f3de96b34510 Mon Sep 17 00:00:00 2001 From: Chocohead Date: Sat, 25 Mar 2023 03:29:06 +0000 Subject: [PATCH 07/13] Fix screenshotting on 1.19.4 The number of reverted `Keyboard` methods grows Fixes #1005 --- gradle.properties | 2 +- .../optifabric/patcher/fixes/KeyboardFix.java | 51 +++++++++---------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/gradle.properties b/gradle.properties index d7ce1aba..80ff143c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ loader_version=0.12.5 fabric_version=0.42.0+1.16 fabric_asm_version=v2.3 -mod_version = 1.13.23 +mod_version = 1.13.24 maven_group = me.modmuss50 archives_base_name = optifabric diff --git a/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java b/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java index d614ae53..131cb887 100644 --- a/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java +++ b/src/main/java/me/modmuss50/optifabric/patcher/fixes/KeyboardFix.java @@ -1,9 +1,13 @@ package me.modmuss50.optifabric.patcher.fixes; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.MoreCollectors; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableSet; import org.apache.commons.lang3.Validate; + import org.objectweb.asm.Handle; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; @@ -15,40 +19,33 @@ import me.modmuss50.optifabric.util.RemappingUtils; -import java.util.List; - public class KeyboardFix implements ClassFixer { - //net/minecraft/client/Keyboard.onKey(JIIII)V - private final String onKeyName = RemappingUtils.getMethodName("class_309", "method_1466", "(JIIII)V"); private final String screenClass = RemappingUtils.getClassName("class_437"); - private final List onKeyLambdasNames = ImmutableList.of( + private final Set revertMethods = ImmutableSet.of( + RemappingUtils.getMethodName("class_309", "method_1466", "(JIIII)V"), //Keyboard, onKey + RemappingUtils.getMethodName("class_309", "method_1454", "(IL" + screenClass + ";[ZIII)V"), RemappingUtils.getMethodName("class_309", "method_1458", "(L" + screenClass + ";II)V"), - RemappingUtils.getMethodName("class_309", "method_1473", "(L" + screenClass + ";CI)V")); + RemappingUtils.getMethodName("class_309", "method_1473", "(L" + screenClass + ";CI)V"), + RemappingUtils.getMethodName("class_309", "method_1463", "(Lnet/minecraft/class_2561)V"), + RemappingUtils.getMethodName("class_309", "method_1464", "(Lnet/minecraft/class_2561)V") + ); @Override public void fix(ClassNode optifine, ClassNode minecraft) { - Validate.notNull(onKeyName, "onKeyName null"); - - //Needed for JEI, might as well remove the useless forge checks optifine does - optifine.methods.removeIf(methodNode -> onKeyLambdasNames.contains(methodNode.name)); - minecraft.methods.stream() - .filter(methodNode -> onKeyLambdasNames.contains(methodNode.name)) - .forEach(methodNode -> optifine.methods.add(methodNode)); + Validate.noNullElements(revertMethods, "Failed to remap Keyboard method name %d"); //ImmutableSet iteration order is stable - //Remove the old "broken" method - optifine.methods.removeIf(methodNode -> methodNode.name.equals(onKeyName)); + //Remove the "broken" OptiFine methods + optifine.methods.removeIf(method -> revertMethods.contains(method.name)); - //Find the vanilla method - MethodNode methodNode = minecraft.methods.stream().filter(node -> node.name.equals(onKeyName)).collect(MoreCollectors.onlyElement()); - Validate.notNull(methodNode, "old method null"); - - //Find the lambda inside the vanilla method (not matched as Optifine changes its descriptor) - MethodNode lambdaNode = minecraft.methods.stream().filter(node -> "method_1454".equals(node.name)).collect(MoreCollectors.onlyElement()); - Validate.notNull(lambdaNode, "old method lambda null"); + //Find the vanilla methods to revert back to + List lambdas = minecraft.methods.stream().filter(method -> revertMethods.contains(method.name)).collect(Collectors.toList()); + if (lambdas.size() != revertMethods.size()) { + Set foundLambdas = lambdas.stream().map(method -> method.name).collect(Collectors.toSet()); + throw new RuntimeException(revertMethods.stream().filter(name -> !foundLambdas.contains(name)).collect(Collectors.joining(", ", "Failed to find Keyboard methods: ", ""))); + } //Add the vanilla methods back in - optifine.methods.add(methodNode); - optifine.methods.add(lambdaNode); + optifine.methods.addAll(lambdas); //lambda$chatTyped(Screen,int,int)void String targetDescC = RemappingUtils.mapMethodDescriptor("(Lnet/minecraft/class_437;CI)V"); // method_1473 @@ -62,7 +59,7 @@ public void fix(ClassNode optifine, ClassNode minecraft) { } } } else { - for (AbstractInsnNode ain : method.instructions.toArray()) { + for (AbstractInsnNode ain : method.instructions) { if (ain.getOpcode() == Opcodes.INVOKEDYNAMIC) { InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) ain; if (idin.bsmArgs.length == 3 && idin.bsmArgs[1] instanceof Handle) { From 7f99ee6ed37020e4e091a290dddc5c7a10bea850 Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Wed, 29 Mar 2023 19:06:07 +0300 Subject: [PATCH 08/13] Fix Borderless Mining >=1.0.6 --- .../BorderlessMiningMixinPlugin.java | 6 ++++- .../BorderlessMiningNewMixinPlugin.java | 8 +++++++ .../OptionFullscreenResolutionNewMixin.java | 22 +++++++++++++++++++ .../optifabric/mod/OptifabricSetup.java | 10 +++++---- ...ic.compat.borderlessmining.new-mixins.json | 9 ++++++++ 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningNewMixinPlugin.java create mode 100644 src/main/java/me/modmuss50/optifabric/compat/borderlessmining/mixin/OptionFullscreenResolutionNewMixin.java create mode 100644 src/main/resources/optifabric.compat.borderlessmining.new-mixins.json diff --git a/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningMixinPlugin.java b/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningMixinPlugin.java index f5a882f1..11c55497 100644 --- a/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningMixinPlugin.java +++ b/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningMixinPlugin.java @@ -23,7 +23,7 @@ public void preApply(String targetClassName, ClassNode targetClass, String mixin for (MethodNode method : targetClass.methods) { if (init.equals(method.name) && "()V".equals(method.desc)) { - Member createSimpleOption = RemappingUtils.mapMethod("class_7172", "", "(Ljava/lang/String;Lnet/minecraft/class_7172$class_7307;Lnet/minecraft/class_7172$class_7303;Lnet/minecraft/class_7172$class_7178;Ljava/lang/Object;Ljava/util/function/Consumer;)V"); + Member createSimpleOption = RemappingUtils.mapMethod("class_7172", "", getCreateSimpleOptionInitDescriptor()); InsnList extra = new InsnList(); LabelNode skip = new LabelNode(); @@ -39,4 +39,8 @@ public void preApply(String targetClassName, ClassNode targetClass, String mixin super.preApply(targetClassName, targetClass, mixinClassName, mixinInfo); } + + protected String getCreateSimpleOptionInitDescriptor() { + return "(Ljava/lang/String;Lnet/minecraft/class_7172$class_7307;Lnet/minecraft/class_7172$class_7303;Lnet/minecraft/class_7172$class_7178;Ljava/lang/Object;Ljava/util/function/Consumer;)V"; + } } \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningNewMixinPlugin.java b/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningNewMixinPlugin.java new file mode 100644 index 00000000..2723231b --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/BorderlessMiningNewMixinPlugin.java @@ -0,0 +1,8 @@ +package me.modmuss50.optifabric.compat.borderlessmining; + +public class BorderlessMiningNewMixinPlugin extends BorderlessMiningMixinPlugin { + @Override + protected String getCreateSimpleOptionInitDescriptor() { + return "(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;Lnet/minecraft/class_7172$class_7303;Lnet/minecraft/class_7172$class_7178;Ljava/lang/Object;Ljava/util/function/Consumer;)V"; + } +} diff --git a/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/mixin/OptionFullscreenResolutionNewMixin.java b/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/mixin/OptionFullscreenResolutionNewMixin.java new file mode 100644 index 00000000..42660fc6 --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/borderlessmining/mixin/OptionFullscreenResolutionNewMixin.java @@ -0,0 +1,22 @@ +package me.modmuss50.optifabric.compat.borderlessmining.mixin; + +import me.modmuss50.optifabric.compat.borderlessmining.MagicMixinBridge; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.option.VideoOptionsScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +@Pseudo +@Mixin(targets = "net.optifine.gui.OptionFullscreenResolution", remap = false) +abstract class OptionFullscreenResolutionNewMixin { + @ModifyArgs(method = "make", + at = @At(value = "INVOKE", target = "Lnet/minecraft/class_7172;(Ljava/lang/String;Lnet/minecraft/class_7172$class_7307;Lnet/minecraft/class_7172$class_7277;Lnet/minecraft/class_7172$class_7178;Ljava/lang/Object;Ljava/util/function/Consumer;)V", remap = true)) + private static void modifyOption(Args args) { + Screen screen = MinecraftClient.getInstance().currentScreen; + ((MagicMixinBridge) (screen instanceof MagicMixinBridge ? screen : new VideoOptionsScreen(screen, MinecraftClient.getInstance().options))).optifabric£modifyFullscreenButton(args); + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 0aff144f..9fe1df43 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -177,7 +177,7 @@ protected boolean isPresent() { for (MethodNode method : node.methods) { if ("renderBatched".equals(method.name) && method.desc.endsWith(desc)) { - Mixins.addConfiguration("optifabric.compat.indigo.newer-mixins.json"); + Mixins.addConfiguration("optifabric.compat.indigo.newer-mixins.json"); return; } } @@ -235,7 +235,7 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.optifine.old-mixins.json"); } - if (isPresent("fabricloader", ">=0.13.0") && (isPresent("cloth-client-events-v0", ">=3.1.58") || isPresent("cloth-client-events-v0", ">=2.1.60 <3.0") || isPresent("cloth-client-events-v0", ">=1.6.59 <2.0"))) { + if (isPresent("fabricloader", ">=0.13.0") && (isPresent("cloth-client-events-v0", ">=3.1.58") || isPresent("cloth-client-events-v0", ">=2.1.60 <3.0") || isPresent("cloth-client-events-v0", ">=1.6.59 <2.0"))) { // no mixins are needed -- cloth had a workaround for https://github.com/FabricMC/Mixin/issues/80 // but it is now fixed in fabricloader } else if (isPresent("cloth-client-events-v0", ">=2.0")) { @@ -377,7 +377,7 @@ protected boolean isPresent() { } } }); - } + } } else if (isPresent("charm", ">=3.0 <4.0")) { Mixins.addConfiguration("optifabric.compat.charm.mixins.json"); } else if (isPresent("charm", ">=4.0")) { @@ -510,7 +510,9 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.compat.zoomify.mixins.json"); } - if (isPresent("borderlessmining", ">=1.1.3")) { + if (isPresent("borderlessmining", ">=1.1.6")) { + Mixins.addConfiguration("optifabric.compat.borderlessmining.new-mixins.json"); + } else if (isPresent("borderlessmining", ">=1.1.3")) { Mixins.addConfiguration("optifabric.compat.borderlessmining.mixins.json"); } diff --git a/src/main/resources/optifabric.compat.borderlessmining.new-mixins.json b/src/main/resources/optifabric.compat.borderlessmining.new-mixins.json new file mode 100644 index 00000000..87e15f90 --- /dev/null +++ b/src/main/resources/optifabric.compat.borderlessmining.new-mixins.json @@ -0,0 +1,9 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.borderlessmining.mixin", + "plugin": "me.modmuss50.optifabric.compat.borderlessmining.BorderlessMiningNewMixinPlugin", + "mixins": [ + "VideoOptionsScreenMixin", + "OptionFullscreenResolutionNewMixin" + ] +} \ No newline at end of file From c2597cfc20c6dfad6c39607f83d066c8e20bf3eb Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Wed, 12 Jul 2023 15:53:59 +0300 Subject: [PATCH 09/13] Add support for 1.20 and 1.20.1 --- .../optifabric/mixin/MixinTitleScreen.java | 9 ++-- .../modmuss50/optifabric/mod/DrawContext.java | 10 +++++ .../optifabric/mod/DrawContextSetup.java | 41 +++++++++++++++++++ src/main/resources/fabric.mod.json | 5 ++- 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 src/main/java/me/modmuss50/optifabric/mod/DrawContext.java create mode 100644 src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java diff --git a/src/main/java/me/modmuss50/optifabric/mixin/MixinTitleScreen.java b/src/main/java/me/modmuss50/optifabric/mixin/MixinTitleScreen.java index c5015d97..5f44581d 100644 --- a/src/main/java/me/modmuss50/optifabric/mixin/MixinTitleScreen.java +++ b/src/main/java/me/modmuss50/optifabric/mixin/MixinTitleScreen.java @@ -8,13 +8,13 @@ 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.Coerce; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.client.gui.screen.ConfirmScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Formatting; import net.minecraft.util.Util; import net.minecraft.util.math.MathHelper; @@ -22,6 +22,7 @@ import net.fabricmc.loader.api.FabricLoader; import me.modmuss50.optifabric.compat.fabricscreenapi.Events; +import me.modmuss50.optifabric.mod.DrawContext; import me.modmuss50.optifabric.mod.OptifabricError; import me.modmuss50.optifabric.mod.OptifabricSetup; import me.modmuss50.optifabric.mod.OptifineVersion; @@ -90,15 +91,15 @@ private void init(CallbackInfo info) { } } - @Inject(method = "render", at = @At("RETURN")) - private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) { + @Inject(method = {"render(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", "method_25394(Lnet/minecraft/class_332;IIF)V"}, at = @At("RETURN"), require = 1) + private void render(@Coerce Object matricesOrContext, int mouseX, int mouseY, float delta, CallbackInfo info) { if (!OptifabricError.hasError()) { float fadeTime = doBackgroundFade ? (Util.getMeasuringTimeMs() - backgroundFadeStart) / 1000F : 1F; float fadeColor = doBackgroundFade ? MathHelper.clamp(fadeTime - 1F, 0F, 1F) : 1F; int alpha = MathHelper.ceil(fadeColor * 255F) << 24; if ((alpha & 0xFC000000) != 0) { - textRenderer.drawWithShadow(matrices, OptifineVersion.version, 2, height - 20, 0xFFFFFF | alpha); + DrawContext.drawTextWithShadow(textRenderer, matricesOrContext, OptifineVersion.version, 2, height -20, 0xFFFFFF | alpha); } } } diff --git a/src/main/java/me/modmuss50/optifabric/mod/DrawContext.java b/src/main/java/me/modmuss50/optifabric/mod/DrawContext.java new file mode 100644 index 00000000..6e4125cc --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/mod/DrawContext.java @@ -0,0 +1,10 @@ +package me.modmuss50.optifabric.mod; + +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.util.math.MatrixStack; + +public class DrawContext { + public static int drawTextWithShadow(TextRenderer textRenderer, Object matrices, String text, int x, int y, int color) { + return textRenderer.drawWithShadow((MatrixStack) matrices, text, x, y, color); + } +} diff --git a/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java b/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java new file mode 100644 index 00000000..4e5bd96e --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java @@ -0,0 +1,41 @@ +package me.modmuss50.optifabric.mod; + +import com.chocohead.mm.api.ClassTinkerers; +import me.modmuss50.optifabric.util.RemappingUtils; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.*; + +public class DrawContextSetup implements Runnable { + @Override + public void run() { + if (OptifabricSetup.isPresent("minecraft", ">=1.20")) { + // changes call to DrawContext.drawTextWithShadow(LTextRenderer;String;III)I + ClassTinkerers.addTransformation("me/modmuss50/optifabric/mod/DrawContext", node -> { + String drawContext = "class_332"; + String drawTextWithShadowDesc = "(Lnet/minecraft/class_327;Ljava/lang/String;III)I"; + for (MethodNode method : node.methods) { + if ("drawTextWithShadow".equals(method.name)) { + for (AbstractInsnNode insn : method.instructions) { + // swap stack order of TextRenderer and DrawContext + if (insn.getOpcode() == Opcodes.ALOAD && ((VarInsnNode) insn).var == 1) { + method.instructions.remove(insn.getPrevious()); // ALOAD 0 + method.instructions.insert(insn.getNext(), new VarInsnNode(Opcodes.ALOAD, 0)); + // cast to DrawContext instead of MatrixStack + } else if (insn.getOpcode() == Opcodes.CHECKCAST) { + ((TypeInsnNode) insn).desc = RemappingUtils.getClassName(drawContext); + // change method + } else if (insn.getOpcode() == Opcodes.INVOKEVIRTUAL) { + ((MethodInsnNode) insn).owner = RemappingUtils.getClassName(drawContext); + ((MethodInsnNode) insn).desc = RemappingUtils.mapMethodDescriptor(drawTextWithShadowDesc); + ((MethodInsnNode) insn).name = RemappingUtils.getMethodName(drawContext, "method_25303", drawTextWithShadowDesc); + // method takes ints instead of floats + } else if (insn.getOpcode() == Opcodes.I2F) { + method.instructions.remove(insn); + } + } + } + } + }); + } + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6ff1e350..4d73bf81 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -24,7 +24,8 @@ "mm:early_risers": [ "me.modmuss50.optifabric.mod.TextSetup", "me.modmuss50.optifabric.mod.RegistriesSetup", - "me.modmuss50.optifabric.mod.OptifabricSetup" + "me.modmuss50.optifabric.mod.OptifabricSetup", + "me.modmuss50.optifabric.mod.DrawContextSetup" ], "preLaunch": [ "me.modmuss50.optifabric.mod.OptifabricLoadGuard" @@ -35,7 +36,7 @@ }, "depends": { "fabricloader": ">=0.8.0", - "minecraft": ["1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5", "1.17-alpha.21.8.b", "1.17-beta.4", "1.17", "1.17.1", "1.18-beta.1", "1.18", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4"], + "minecraft": ["1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5", "1.17-alpha.21.8.b", "1.17-beta.4", "1.17", "1.17.1", "1.18-beta.1", "1.18", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", "1.20", "1.20.1"], "mm": ">=2.0" }, "conflicts": { From 97ac3af69cae0ea97bb33d1b284cd1e79f371553 Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Wed, 12 Jul 2023 21:00:38 +0300 Subject: [PATCH 10/13] Fix Fabric API 0.81.0+ --- build.gradle | 1 + .../mixin/GameRendererNew3erMixin.java | 49 +++++++++++++++++++ .../mixin/GameRendererNew4erMixin.java | 49 +++++++++++++++++++ .../optifabric/mod/OptifabricSetup.java | 6 ++- ...ompat.fabric-screen-api.new3er-mixins.json | 8 +++ ...ompat.fabric-screen-api.new4er-mixins.json | 8 +++ 6 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew3erMixin.java create mode 100644 src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew4erMixin.java create mode 100644 src/main/resources/optifabric.compat.fabric-screen-api.new3er-mixins.json create mode 100644 src/main/resources/optifabric.compat.fabric-screen-api.new4er-mixins.json diff --git a/build.gradle b/build.gradle index 14abd265..9ba81565 100644 --- a/build.gradle +++ b/build.gradle @@ -73,6 +73,7 @@ compileJava { method 'net/minecraft/client/gui/screen/Screen', '(Lnet/minecraft/client/util/math/MatrixStack;IIF)V', 'renderWithTooltip', 'method_47413' classes += ['net/minecraft/class_5944': 'net/minecraft/class_5944'] method 'net/minecraft/class_5944', '(Lnet/minecraft/class_5912;Lnet/minecraft/util/Identifier;Lnet/minecraft/client/render/VertexFormat;)V', '', '' + method 'net/minecraft/client/gui/screen/Screen', '(Lnet/minecraft/class_332;IIF)V', 'renderWithTooltip', 'method_47413' } } diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew3erMixin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew3erMixin.java new file mode 100644 index 00000000..1def470a --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew3erMixin.java @@ -0,0 +1,49 @@ +package me.modmuss50.optifabric.compat.fabricscreenapi.mixin; + +import me.modmuss50.optifabric.compat.InterceptingMixin; +import me.modmuss50.optifabric.compat.PlacatingSurrogate; +import me.modmuss50.optifabric.compat.Shim; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.util.Window; +import net.minecraft.client.util.math.MatrixStack; +import org.joml.Matrix4f; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(GameRenderer.class) +@InterceptingMixin("net/fabricmc/fabric/mixin/screen/GameRendererMixin") +abstract class GameRendererNew3erMixin { + @Shim + private native void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, MatrixStack matrixstack, MatrixStack drawContext); + + @PlacatingSurrogate + private void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float guiFarPlane) { + } + + @Inject(method = "render(FJZ)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", ordinal = 0), + locals = LocalCapture.CAPTURE_FAILHARD, + cancellable = true) + private void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, MatrixStack drawContext) { + onBeforeRenderScreen(tickDelta, startTime, tick, call, mouseX, mouseY, matrixstack, drawContext); + } + + @Shim + private native void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, MatrixStack matrixstack, MatrixStack drawContext); + + @PlacatingSurrogate + private void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float guiFarPlane) { + } + + @Inject(method = "render(FJZ)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", shift = Shift.AFTER, ordinal = 0), + locals = LocalCapture.CAPTURE_FAILHARD) + private void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, MatrixStack drawContext) { + onAfterRenderScreen(tickDelta, startTime, tick, call, mouseX, mouseY, matrixstack, drawContext); + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew4erMixin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew4erMixin.java new file mode 100644 index 00000000..32858d4f --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew4erMixin.java @@ -0,0 +1,49 @@ +package me.modmuss50.optifabric.compat.fabricscreenapi.mixin; + +import me.modmuss50.optifabric.compat.InterceptingMixin; +import me.modmuss50.optifabric.compat.PlacatingSurrogate; +import me.modmuss50.optifabric.compat.Shim; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.util.Window; +import net.minecraft.client.util.math.MatrixStack; +import org.joml.Matrix4f; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(GameRenderer.class) +@InterceptingMixin("net/fabricmc/fabric/mixin/screen/GameRendererMixin") +abstract class GameRendererNew4erMixin { + @Shim + private native void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, MatrixStack matrixstack, DrawableHelper drawContext); + + @PlacatingSurrogate + private void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float idk) { + } + + @Inject(method = "render(FJZ)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/class_332;IIF)V", ordinal = 0), + locals = LocalCapture.CAPTURE_FAILHARD, + cancellable = true) + private void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, float idk, DrawableHelper drawContext) { + onBeforeRenderScreen(tickDelta, startTime, tick, call, mouseX, mouseY, matrixstack, drawContext); + } + + @Shim + private native void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, MatrixStack matrixstack, DrawableHelper drawContext); + + @PlacatingSurrogate + private void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float idk) { + } + + @Inject(method = "render(FJZ)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/class_332;IIF)V", shift = Shift.AFTER, ordinal = 0), + locals = LocalCapture.CAPTURE_FAILHARD) + private void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, float idk, DrawableHelper drawContext) { + onAfterRenderScreen(tickDelta, startTime, tick, call, mouseX, mouseY, matrixstack, drawContext); + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 9fe1df43..799b5946 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -210,7 +210,11 @@ protected boolean isPresent() { } if (isPresent("fabric-screen-api-v1")) { - if (isPresent("minecraft", ">=1.19.3")) { + if (isPresent("minecraft", ">=1.20")) { + Mixins.addConfiguration("optifabric.compat.fabric-screen-api.new4er-mixins.json"); + } else if (isPresent("fabric-api", ">=0.81.0")) { + Mixins.addConfiguration("optifabric.compat.fabric-screen-api.new3er-mixins.json"); + } else if (isPresent("minecraft", ">=1.19.3")) { Mixins.addConfiguration("optifabric.compat.fabric-screen-api.newerer-mixins.json"); } else if (isPresent("minecraft", ">=1.17-alpha.21.10.a")) { if (farPlanePresent.getAsBoolean()) { diff --git a/src/main/resources/optifabric.compat.fabric-screen-api.new3er-mixins.json b/src/main/resources/optifabric.compat.fabric-screen-api.new3er-mixins.json new file mode 100644 index 00000000..6874bcbc --- /dev/null +++ b/src/main/resources/optifabric.compat.fabric-screen-api.new3er-mixins.json @@ -0,0 +1,8 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.fabricscreenapi.mixin", + "plugin": "me.modmuss50.optifabric.compat.InterceptingMixinPlugin", + "mixins": [ + "GameRendererNew3erMixin" + ] +} \ No newline at end of file diff --git a/src/main/resources/optifabric.compat.fabric-screen-api.new4er-mixins.json b/src/main/resources/optifabric.compat.fabric-screen-api.new4er-mixins.json new file mode 100644 index 00000000..90213257 --- /dev/null +++ b/src/main/resources/optifabric.compat.fabric-screen-api.new4er-mixins.json @@ -0,0 +1,8 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.fabricscreenapi.mixin", + "plugin": "me.modmuss50.optifabric.compat.InterceptingMixinPlugin", + "mixins": [ + "GameRendererNew4erMixin" + ] +} \ No newline at end of file From 0bb44d31800b8b8653356d4527fa6af769c64f69 Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Thu, 13 Jul 2023 13:14:04 +0300 Subject: [PATCH 11/13] Clean up `DrawContextSetup` --- .../modmuss50/optifabric/mod/DrawContextSetup.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java b/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java index 4e5bd96e..b256eb7f 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java @@ -2,6 +2,7 @@ import com.chocohead.mm.api.ClassTinkerers; import me.modmuss50.optifabric.util.RemappingUtils; +import net.fabricmc.tinyremapper.IMappingProvider.Member; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; @@ -11,8 +12,7 @@ public void run() { if (OptifabricSetup.isPresent("minecraft", ">=1.20")) { // changes call to DrawContext.drawTextWithShadow(LTextRenderer;String;III)I ClassTinkerers.addTransformation("me/modmuss50/optifabric/mod/DrawContext", node -> { - String drawContext = "class_332"; - String drawTextWithShadowDesc = "(Lnet/minecraft/class_327;Ljava/lang/String;III)I"; + Member drawTextWithShadow = RemappingUtils.mapMethod("class_332", "method_25303", "(Lnet/minecraft/class_327;Ljava/lang/String;III)I"); for (MethodNode method : node.methods) { if ("drawTextWithShadow".equals(method.name)) { for (AbstractInsnNode insn : method.instructions) { @@ -22,17 +22,18 @@ public void run() { method.instructions.insert(insn.getNext(), new VarInsnNode(Opcodes.ALOAD, 0)); // cast to DrawContext instead of MatrixStack } else if (insn.getOpcode() == Opcodes.CHECKCAST) { - ((TypeInsnNode) insn).desc = RemappingUtils.getClassName(drawContext); + ((TypeInsnNode) insn).desc = drawTextWithShadow.owner; // change method } else if (insn.getOpcode() == Opcodes.INVOKEVIRTUAL) { - ((MethodInsnNode) insn).owner = RemappingUtils.getClassName(drawContext); - ((MethodInsnNode) insn).desc = RemappingUtils.mapMethodDescriptor(drawTextWithShadowDesc); - ((MethodInsnNode) insn).name = RemappingUtils.getMethodName(drawContext, "method_25303", drawTextWithShadowDesc); + ((MethodInsnNode) insn).owner = drawTextWithShadow.owner; + ((MethodInsnNode) insn).desc = drawTextWithShadow.desc; + ((MethodInsnNode) insn).name = drawTextWithShadow.name; // method takes ints instead of floats } else if (insn.getOpcode() == Opcodes.I2F) { method.instructions.remove(insn); } } + break; } } }); From 43db809eb3c87c39596b9ea18fe4c07b389e53a6 Mon Sep 17 00:00:00 2001 From: XXMA16 Date: Thu, 13 Jul 2023 14:11:25 +0300 Subject: [PATCH 12/13] Fix Architectury 1.20.x --- .../mixin/GameRendererNew4erMixin.java | 46 +++++++++++++++++++ .../optifabric/mod/OptifabricSetup.java | 6 ++- ....compat.architectury-AB.new4er-mixins.json | 8 ++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNew4erMixin.java create mode 100644 src/main/resources/optifabric.compat.architectury-AB.new4er-mixins.json diff --git a/src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNew4erMixin.java b/src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNew4erMixin.java new file mode 100644 index 00000000..d5b5ff73 --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNew4erMixin.java @@ -0,0 +1,46 @@ +package me.modmuss50.optifabric.compat.architectury.mixin; + +import me.modmuss50.optifabric.compat.InterceptingMixin; +import me.modmuss50.optifabric.compat.PlacatingSurrogate; +import me.modmuss50.optifabric.compat.Shim; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.util.Window; +import net.minecraft.client.util.math.MatrixStack; +import org.joml.Matrix4f; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(GameRenderer.class) +@InterceptingMixin("dev/architectury/mixin/fabric/client/MixinGameRenderer") +abstract class GameRendererNew4erMixin { + @Shim + private native void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, MatrixStack matrices, DrawableHelper drawContext); + + @PlacatingSurrogate + private void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices) { + } + + @Inject(method = "render(FJZ)V", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/class_332;IIF)V", ordinal = 0)) + private void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices, float idk, DrawableHelper drawContext) { + renderScreenPre(tickDelta, startTime, tick, ci, mouseX, mouseY, window, matrix, matrices, drawContext); + } + + @Shim + private native void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, MatrixStack matrices, DrawableHelper drawContext); + + @PlacatingSurrogate + private void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices) { + } + + @Inject(method = "render(FJZ)V", locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/class_332;IIF)V", shift = Shift.AFTER, ordinal = 0)) + private void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f matrix, MatrixStack matrices, float idk, DrawableHelper drawContext) { + renderScreenPost(tickDelta, startTime, tick, ci, mouseX, mouseY, window, matrix, matrices, drawContext); + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 799b5946..0a35c9c6 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -67,7 +67,7 @@ protected boolean isPresent() { return injector.predictFuture(RemappingUtils.getClassName("class_702")).filter(node -> {//ParticleManager //(MatrixStack, VertexConsumerProvider$Immediate, LightmapTextureManager, Camera, Frustum) String desc = RemappingUtils.mapMethodDescriptor("(Lnet/minecraft/class_4587;Lnet/minecraft/class_4597$class_4598;" - + "Lnet/minecraft/class_765;Lnet/minecraft/class_4184;FLnet/minecraft/class_4604;)V"); + + "Lnet/minecraft/class_765;Lnet/minecraft/class_4184;FLnet/minecraft/class_4604;)V"); for (MethodNode method : node.methods) { if (("renderParticles".equals(method.name) || "render".equals(method.name)) && desc.equals(method.desc)) { @@ -404,7 +404,9 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.compat.images.mixins.json"); } - if (isPresent("architectury", ">=7.0.52")) { + if (isPresent("architectury", ">=9.0.6")) { + Mixins.addConfiguration("optifabric.compat.architectury-AB.new4er-mixins.json"); + } else if (isPresent("architectury", ">=7.0.52")) { Mixins.addConfiguration("optifabric.compat.architectury-AB.newererer-mixins.json"); } else if (isPresent("architectury", ">=3.7")) { Mixins.addConfiguration("optifabric.compat.architectury-AB.newerer-mixins.json"); diff --git a/src/main/resources/optifabric.compat.architectury-AB.new4er-mixins.json b/src/main/resources/optifabric.compat.architectury-AB.new4er-mixins.json new file mode 100644 index 00000000..0482316d --- /dev/null +++ b/src/main/resources/optifabric.compat.architectury-AB.new4er-mixins.json @@ -0,0 +1,8 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.architectury.mixin", + "plugin": "me.modmuss50.optifabric.compat.InterceptingMixinPlugin", + "mixins": [ + "GameRendererNew4erMixin" + ] +} \ No newline at end of file From 559a16695666d2a0b453419a4ed2bdab7138e307 Mon Sep 17 00:00:00 2001 From: Chocohead Date: Fri, 14 Jul 2023 00:08:09 +0100 Subject: [PATCH 13/13] Bump version The hard work of @XXMA16 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 80ff143c..0421b49e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ loader_version=0.12.5 fabric_version=0.42.0+1.16 fabric_asm_version=v2.3 -mod_version = 1.13.24 +mod_version = 1.13.25 maven_group = me.modmuss50 archives_base_name = optifabric