From 21269e9dd5a55a9bafe80e30e54274682cb96e64 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 28 Jul 2021 18:13:47 -0700 Subject: [PATCH] Expose ClippingHelper in BeginFrameEvent --- .../com/jozufozu/flywheel/core/Clipping.java | 16 +++++++++++++++ .../flywheel/event/BeginFrameEvent.java | 9 ++++++++- .../mixin/GlobalClippingHelperMixin.java | 20 +++++++++++++++++++ .../flywheel/mixin/RenderHooksMixin.java | 3 ++- src/main/resources/flywheel.mixins.json | 3 ++- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/jozufozu/flywheel/core/Clipping.java create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/GlobalClippingHelperMixin.java diff --git a/src/main/java/com/jozufozu/flywheel/core/Clipping.java b/src/main/java/com/jozufozu/flywheel/core/Clipping.java new file mode 100644 index 000000000..9f28ef46e --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/Clipping.java @@ -0,0 +1,16 @@ +package com.jozufozu.flywheel.core; + +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.renderer.culling.ClippingHelper; + +/** + * Used to capture the ClippingHelper from WorldRenderer#renderLevel + */ +public class Clipping { + + /** + * Assigned in {@link com.jozufozu.flywheel.mixin.GlobalClippingHelperMixin this} mixin. + */ + public static ClippingHelper HELPER; +} diff --git a/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java b/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java index 042cc1acd..a4c508328 100644 --- a/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java +++ b/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java @@ -5,6 +5,7 @@ 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.culling.ClippingHelper; import net.minecraft.client.world.ClientWorld; import net.minecraftforge.eventbus.api.Event; @@ -14,13 +15,15 @@ public class BeginFrameEvent extends Event { private final ActiveRenderInfo info; private final GameRenderer gameRenderer; private final LightTexture lightTexture; + private final ClippingHelper clippingHelper; - public BeginFrameEvent(ClientWorld world, MatrixStack stack, ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture) { + public BeginFrameEvent(ClientWorld world, MatrixStack stack, ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture, ClippingHelper clippingHelper) { this.world = world; this.stack = stack; this.info = info; this.gameRenderer = gameRenderer; this.lightTexture = lightTexture; + this.clippingHelper = clippingHelper; } public ClientWorld getWorld() { @@ -42,4 +45,8 @@ public class BeginFrameEvent extends Event { public LightTexture getLightTexture() { return lightTexture; } + + public ClippingHelper getClippingHelper() { + return clippingHelper; + } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/GlobalClippingHelperMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/GlobalClippingHelperMixin.java new file mode 100644 index 000000000..39958bbc0 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/GlobalClippingHelperMixin.java @@ -0,0 +1,20 @@ +package com.jozufozu.flywheel.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.CallbackInfo; + +import com.jozufozu.flywheel.core.Clipping; + +import net.minecraft.client.renderer.culling.ClippingHelper; +import net.minecraft.util.math.vector.Matrix4f; + +@Mixin(ClippingHelper.class) +public class GlobalClippingHelperMixin { + + @Inject(at = @At("TAIL"), method = "") + private void init(Matrix4f p_i226026_1_, Matrix4f p_i226026_2_, CallbackInfo ci) { + Clipping.HELPER = (ClippingHelper) (Object) this; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java index 238e478b6..47002e44e 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java @@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.OptifineHandler; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; +import com.jozufozu.flywheel.core.Clipping; import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent; @@ -45,7 +46,7 @@ public class RenderHooksMixin { @Inject(at = @At(value = "INVOKE", target = "net.minecraft.client.renderer.WorldRenderer.compileChunksUntil(J)V"), method = "renderLevel") private void setupFrame(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f p_228426_9_, CallbackInfo ci) { - MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, stack, info, gameRenderer, lightTexture)); + MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, stack, info, gameRenderer, lightTexture, Clipping.HELPER)); } /** diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index 2c4db2153..1959046f5 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -18,7 +18,8 @@ "atlas.SheetDataAccessor", "light.LightUpdateMixin", "light.NetworkLightUpdateMixin", - "FastChunkProviderMixin" + "FastChunkProviderMixin", + "GlobalClippingHelperMixin" ], "injectors": { "defaultRequire": 0