From a6377b5fe82ae1a9ac145379b7ba12100a9b1256 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Thu, 9 Sep 2021 14:06:17 -0700 Subject: [PATCH] Fix BeginFrameEvent not firing with sodium installed - Rendering is still broken, that fix must come from within sodium --- .../flywheel/mixin/BeginFrameMixin.java | 60 +++++++++++++++++++ .../flywheel/mixin/RenderHooksMixin.java | 9 ++- src/main/resources/flywheel.mixins.json | 17 +----- 3 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/BeginFrameMixin.java diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BeginFrameMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/BeginFrameMixin.java new file mode 100644 index 000000000..e7d6f89d6 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/BeginFrameMixin.java @@ -0,0 +1,60 @@ +package com.jozufozu.flywheel.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Group; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.jozufozu.flywheel.event.BeginFrameEvent; +import com.mojang.blaze3d.matrix.MatrixStack; + +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.culling.ClippingHelper; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.profiler.IProfiler; +import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.MinecraftForge; + +@OnlyIn(Dist.CLIENT) +@Mixin(WorldRenderer.class) +public class BeginFrameMixin { + + @Shadow + private ClientWorld level; + + @Unique + private boolean setup; + + @Group(name = "setupRender", min = 1) + @Inject(method = "renderLevel", + at = @At(value = "INVOKE", target = "net.minecraft.client.renderer.WorldRenderer.compileChunksUntil(J)V"), + locals = LocalCapture.CAPTURE_FAILSOFT) + private void setupRender(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, + ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, + CallbackInfo ci, // locals, only care about clippinghelper + IProfiler iprofiler, Vector3d vector3d, double d0, double d1, double d2, Matrix4f matrix4f, boolean flag, + ClippingHelper clippinghelper) { + MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, info, clippinghelper)); + + setup = true; + } + + @Group(name = "setupRender") + @Inject(at = @At("HEAD"), method = "setupRender") + private void setupRenderOptifineCompat(ActiveRenderInfo info, ClippingHelper clippingHelper, boolean p_228437_3_, int frameCount, boolean isSpectator, CallbackInfo ci) { + if (!setup) { + MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, info, clippingHelper)); + } + setup = false; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java index be51b342c..afdd2d1a8 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java @@ -4,9 +4,12 @@ import org.lwjgl.opengl.GL20; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Group; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.OptifineHandler; @@ -26,6 +29,7 @@ import net.minecraft.client.renderer.RenderTypeBuffers; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.culling.ClippingHelper; import net.minecraft.client.world.ClientWorld; +import net.minecraft.profiler.IProfiler; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.util.math.vector.Vector3d; @@ -44,11 +48,6 @@ public class RenderHooksMixin { @Final private RenderTypeBuffers renderBuffers; - @Inject(at = @At("HEAD"), method = "setupRender") - private void setupRender(ActiveRenderInfo info, ClippingHelper clippingHelper, boolean p_228437_3_, int frameCount, boolean isSpectator, CallbackInfo ci) { - MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, info, clippingHelper)); - } - /** * JUSTIFICATION: This method is called once per layer per frame. It allows us to perform * layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects. diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index 2c4db2153..13b737f6f 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -4,22 +4,7 @@ "package": "com.jozufozu.flywheel.mixin", "compatibilityLevel": "JAVA_8", "refmap": "flywheel.refmap.json", - "client": [ - "CancelEntityRenderMixin", - "CancelTileEntityRenderMixin", - "FixFabulousDepthMixin", - "FogColorTrackerMixin", - "RenderHooksMixin", - "ShaderCloseMixin", - "StoreProjectionMatrixMixin", - "TileRemoveMixin", - "TileWorldHookMixin", - "atlas.AtlasDataMixin", - "atlas.SheetDataAccessor", - "light.LightUpdateMixin", - "light.NetworkLightUpdateMixin", - "FastChunkProviderMixin" - ], + "client": ["BeginFrameMixin", "CancelEntityRenderMixin", "CancelTileEntityRenderMixin", "FastChunkProviderMixin", "FixFabulousDepthMixin", "FogColorTrackerMixin", "RenderHooksMixin", "ShaderCloseMixin", "StoreProjectionMatrixMixin", "TileRemoveMixin", "TileWorldHookMixin", "atlas.AtlasDataMixin", "atlas.SheetDataAccessor", "light.LightUpdateMixin", "light.NetworkLightUpdateMixin"], "injectors": { "defaultRequire": 0 }