From d9a13f3b8dec9396c239315db646781bba53d6cf Mon Sep 17 00:00:00 2001 From: Chocohead Date: Fri, 12 Jan 2024 00:12:28 +0000 Subject: [PATCH] Add support for 1.20.2 and 1.20.4 Slightly tentative, Fabric API's Block View API probably needs at least another mixin on `ChunkCacheOF` to fully support it Mod support beyond Fabric API is essentially untested --- gradle.properties | 2 +- .../fabricblockview/BlockViewMixinPlugin.java | 21 ++++++++ .../ChunkRendererRegionBuilderMixin.java | 33 +++++++++++++ .../mixin/WorldRendererNewMixin.java | 6 ++- .../mixin/GameRendererNew5erMixin.java | 49 +++++++++++++++++++ .../optifabric/mod/OptifabricSetup.java | 14 +++++- src/main/resources/fabric.mod.json | 2 +- ...c.compat.fabric-block-view-api.mixins.json | 8 +++ ...ompat.fabric-screen-api.new5er-mixins.json | 8 +++ 9 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 src/main/java/me/modmuss50/optifabric/compat/fabricblockview/BlockViewMixinPlugin.java create mode 100644 src/main/java/me/modmuss50/optifabric/compat/fabricblockview/mixin/ChunkRendererRegionBuilderMixin.java create mode 100644 src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew5erMixin.java create mode 100644 src/main/resources/optifabric.compat.fabric-block-view-api.mixins.json create mode 100644 src/main/resources/optifabric.compat.fabric-screen-api.new5er-mixins.json diff --git a/gradle.properties b/gradle.properties index f18b6c66..4014bfb6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ fabric_version=0.42.0+1.16 tiny_remapper_version=0.8.11 fabric_asm_version=v2.3 -mod_version = 1.14.2 +mod_version = 1.14.3 maven_group = me.modmuss50 archives_base_name = optifabric diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricblockview/BlockViewMixinPlugin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricblockview/BlockViewMixinPlugin.java new file mode 100644 index 00000000..1f729c96 --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricblockview/BlockViewMixinPlugin.java @@ -0,0 +1,21 @@ +package me.modmuss50.optifabric.compat.fabricblockview; + +import org.objectweb.asm.tree.ClassNode; + +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.asm.mixin.transformer.ClassInfo; + +import me.modmuss50.optifabric.compat.InterceptingMixinPlugin; +import me.modmuss50.optifabric.util.MixinUtils; + +public class BlockViewMixinPlugin extends InterceptingMixinPlugin { + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + if ("ChunkRendererRegionBuilderMixin".equals(mixinInfo.getName())) { + ClassInfo info = ClassInfo.forName(targetClassName); + MixinUtils.completeClassInfo(info, targetClass.methods); + } + + super.preApply(targetClassName, targetClass, mixinClassName, mixinInfo); + } +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricblockview/mixin/ChunkRendererRegionBuilderMixin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricblockview/mixin/ChunkRendererRegionBuilderMixin.java new file mode 100644 index 00000000..f599878e --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricblockview/mixin/ChunkRendererRegionBuilderMixin.java @@ -0,0 +1,33 @@ +package me.modmuss50.optifabric.compat.fabricblockview.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.class_6850; +import net.minecraft.class_6850.class_6851; +import net.minecraft.client.render.chunk.ChunkRendererRegion; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import me.modmuss50.optifabric.compat.InterceptingMixin; +import me.modmuss50.optifabric.compat.PlacatingSurrogate; +import me.modmuss50.optifabric.compat.Shim; + +@Mixin(class_6850.class) +@InterceptingMixin("net/fabricmc/fabric/mixin/blockview/client/ChunkRendererRegionBuilderMixin") +abstract class ChunkRendererRegionBuilderMixin { + @PlacatingSurrogate + private void createDataMap(World world, BlockPos startPos, BlockPos endPos, int chunkRadius, CallbackInfoReturnable call) { + } + + @Inject(at = @At("RETURN"), method = "createRegion", remap = false, locals = LocalCapture.CAPTURE_FAILHARD) + private void createOF(World world, BlockPos startPos, BlockPos endPos, int offset, boolean checkEmpty, CallbackInfoReturnable call, int startX, int startZ, int endX, int endZ, class_6851[][] chunks) { + createDataMap(world, startPos, endPos, offset, call, startX, endX, startZ, endZ, chunks); + } + + @Shim + private native void createDataMap(World world, BlockPos startPos, BlockPos endPos, int offset, CallbackInfoReturnable call, int startX, int startZ, int endX, int endZ, class_6851[][] chunks); +} \ No newline at end of file diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/WorldRendererNewMixin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/WorldRendererNewMixin.java index 0595f800..55ae041a 100644 --- a/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/WorldRendererNewMixin.java +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricrendering/mixin/WorldRendererNewMixin.java @@ -14,8 +14,10 @@ @InterceptingMixin("net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin") abstract class WorldRendererNewMixin { @Inject(method = "render(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", require = 2, - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/particle/ParticleManager;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/Frustum;)V")) + at = {@At(value = "INVOKE", + target = "Lnet/minecraft/client/particle/ParticleManager;renderParticles(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/Frustum;)V"), + @At(value = "INVOKE", + target = "Lnet/minecraft/client/particle/ParticleManager;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/Frustum;)V")}) private void onReallyRenderParticles(CallbackInfo call) { onRenderParticles(call); } diff --git a/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew5erMixin.java b/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew5erMixin.java new file mode 100644 index 00000000..afbaf6c0 --- /dev/null +++ b/src/main/java/me/modmuss50/optifabric/compat/fabricscreenapi/mixin/GameRendererNew5erMixin.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 GameRendererNew5erMixin { + @Shim + private native void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, MatrixStack matrixstack, DrawableHelper drawContext); + + @PlacatingSurrogate + private void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, 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, boolean loaded, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, float idk, DrawableHelper drawContext) { + onBeforeRenderScreen(tickDelta, startTime, tick, call, loaded, mouseX, mouseY, matrixstack, drawContext); + } + + @Shim + private native void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, MatrixStack matrixstack, DrawableHelper drawContext); + + @PlacatingSurrogate + private void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, 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, boolean loaded, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, float idk, DrawableHelper drawContext) { + onAfterRenderScreen(tickDelta, startTime, tick, call, loaded, 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 0235ce68..de43dfab 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -138,7 +138,13 @@ protected boolean isPresent() { Mixins.addConfiguration("optifabric.compat.fabric-rendering.extra-mixins.json"); } - if (isPresent("fabric-rendering-data-attachment-v1")) { + if (isPresent("fabric-block-view-api-v2")) { + Mixins.addConfiguration("optifabric.compat.fabric-block-view-api.mixins.json"); + + if (isPresent("fabric-rendering-data-attachment-v1")) { + Mixins.addConfiguration("optifabric.compat.fabric-rendering-data.mixins.json"); + } + } else if (isPresent("fabric-rendering-data-attachment-v1")) { Mixins.addConfiguration("optifabric.compat.fabric-rendering-data.mixins.json"); if (isPresent("fabric-rendering-data-attachment-v1", ">0.3.0")) { @@ -210,7 +216,11 @@ protected boolean isPresent() { } if (isPresent("fabric-screen-api-v1")) { - if (isPresent("minecraft", ">=1.20")) { + if (isPresent("fabric-screen-api-v1", ">=2.0.16")) { + //0.92.1 moved to use Mixin Extra so no longer an issue + } else if (isPresent("minecraft", ">=1.20.2")) { + Mixins.addConfiguration("optifabric.compat.fabric-screen-api.new5er-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"); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4d73bf81..4646ed97 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -36,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", "1.20", "1.20.1"], + "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", "1.20.2", "1.20.4"], "mm": ">=2.0" }, "conflicts": { diff --git a/src/main/resources/optifabric.compat.fabric-block-view-api.mixins.json b/src/main/resources/optifabric.compat.fabric-block-view-api.mixins.json new file mode 100644 index 00000000..7ab57928 --- /dev/null +++ b/src/main/resources/optifabric.compat.fabric-block-view-api.mixins.json @@ -0,0 +1,8 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.fabricblockview.mixin", + "plugin": "me.modmuss50.optifabric.compat.fabricblockview.BlockViewMixinPlugin", + "mixins": [ + "ChunkRendererRegionBuilderMixin" + ] +} \ No newline at end of file diff --git a/src/main/resources/optifabric.compat.fabric-screen-api.new5er-mixins.json b/src/main/resources/optifabric.compat.fabric-screen-api.new5er-mixins.json new file mode 100644 index 00000000..36d36e26 --- /dev/null +++ b/src/main/resources/optifabric.compat.fabric-screen-api.new5er-mixins.json @@ -0,0 +1,8 @@ +{ + "parent": "optifabric.mixins.json", + "package": "me.modmuss50.optifabric.compat.fabricscreenapi.mixin", + "plugin": "me.modmuss50.optifabric.compat.InterceptingMixinPlugin", + "mixins": [ + "GameRendererNew5erMixin" + ] +} \ No newline at end of file