diff --git a/build.gradle b/build.gradle index a59c6f8c..9ba81565 100644 --- a/build.gradle +++ b/build.gradle @@ -71,6 +71,9 @@ 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', '', '' + method 'net/minecraft/client/gui/screen/Screen', '(Lnet/minecraft/class_332;IIF)V', 'renderWithTooltip', 'method_47413' } } diff --git a/gradle.properties b/gradle.properties index bfd10724..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.21 +mod_version = 1.13.25 maven_group = me.modmuss50 archives_base_name = optifabric 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/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/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/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/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/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..b256eb7f --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/mod/DrawContextSetup.java @@ -0,0 +1,42 @@ +package me.modmuss50.optifabric.mod; + +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.*; + +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 -> { + 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) { + // 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 = drawTextWithShadow.owner; + // change method + } else if (insn.getOpcode() == Opcodes.INVOKEVIRTUAL) { + ((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; + } + } + }); + } + } +} diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 50a39018..e0ce21b1 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -63,7 +63,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)) { @@ -130,6 +130,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"); @@ -209,6 +212,10 @@ protected boolean isPresent() { } else { Mixins.addConfiguration("optifabric.compat.qslscreenext.old-mixins.json"); } + } else 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")) { @@ -255,7 +262,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"); } @@ -399,7 +406,11 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.compat.images.mixins.json"); } - if (isPresent("architectury", ">=3.7")) { + 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"); } else if (isPresent("architectury", ">=2.0")) { assert isPresent("minecraft", ">=1.17-beta.1"); @@ -507,7 +518,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/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;" 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..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,8 +1,13 @@ package me.modmuss50.optifabric.patcher.fixes; -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,27 +20,32 @@ import me.modmuss50.optifabric.util.RemappingUtils; 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 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_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"); + 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 @@ -49,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) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5c33b768..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"], + "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": { 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 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 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 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/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 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