From c5476025ecaf60f117bcc2a23be56cc51e8d5c39 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Wed, 8 Apr 2020 17:00:58 +0200 Subject: [PATCH] Fix terrain not rendering with OF shaders enabled (fixes #122) This was caused by us setting `needsTerrainUpdate` to false during the shadow pass in order to break out of the ForceChunkLoading loop (cause OF doesn't update chunks during the shadow pass). However, this inadvertently caused the chunk updates to be skipped during the normal pass as well if there didn't happen to be another reasons for updating. To fix this, we simply move the shadow pass check into the ForceChunkLoading mixin and skip the entire loop during the shadow pass. --- .../mixin/MixinShaderRenderGlobal.java | 71 ------------------- .../render/mixin/Mixin_ForceChunkLoading.java | 11 ++- .../mixins.compat.shaders.replaymod.json | 1 - 3 files changed, 9 insertions(+), 74 deletions(-) delete mode 100644 src/main/java/com/replaymod/compat/shaders/mixin/MixinShaderRenderGlobal.java diff --git a/src/main/java/com/replaymod/compat/shaders/mixin/MixinShaderRenderGlobal.java b/src/main/java/com/replaymod/compat/shaders/mixin/MixinShaderRenderGlobal.java deleted file mode 100644 index 62f34abf..00000000 --- a/src/main/java/com/replaymod/compat/shaders/mixin/MixinShaderRenderGlobal.java +++ /dev/null @@ -1,71 +0,0 @@ -//#if MC>=10800 -package com.replaymod.compat.shaders.mixin; - -import com.replaymod.compat.shaders.ShaderReflection; -import com.replaymod.render.hooks.EntityRendererHandler; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.Frustum; -import net.minecraft.client.render.WorldRenderer; -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.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -//#if MC>=11500 -//#else -//$$ import net.minecraft.client.render.VisibleRegion; -//#endif - -//#if MC>=11400 -import net.minecraft.client.render.Camera; -//#else -//$$ import net.minecraft.entity.Entity; -//#endif - -@Mixin(WorldRenderer.class) -public abstract class MixinShaderRenderGlobal { - - private final MinecraftClient mc = MinecraftClient.getInstance(); - - @Shadow - public boolean needsTerrainUpdate; - - @Inject(method = "setupTerrain", at = @At("HEAD"), cancellable = true) - public void replayModCompat_setupTerrain( - //#if MC>=11400 - Camera viewEntity, - //#else - //$$ Entity viewEntity, - //#if MC>=11400 - //$$ float partialTicks, - //#else - //$$ double partialTicks, - //#endif - //#endif - //#if MC>=11500 - Frustum camera, - boolean skipUpdate, - //#else - //$$ VisibleRegion camera, - //#endif - int frameCount, - boolean playerSpectator, - CallbackInfo ci - ) { - if (((EntityRendererHandler.IEntityRenderer) mc.gameRenderer).replayModRender_getHandler() == null) return; - if (ShaderReflection.shaders_isShadowPass == null) return; - - // when called by the shadow pass, displayListEntitiesDirty can't be set to false, as no chunk updates - // are being processed. As it's being set to true by ChunkLoadingRenderGlobal#updateChunks, we have to - // set it to false manually to exit the loop imposed by MixinRenderGlobal#replayModRender_setupTerrain. - try { - if ((boolean) ShaderReflection.shaders_isShadowPass.get(null) == true) { - this.needsTerrainUpdate = false; - } - } catch (IllegalAccessException ignore) {} - - } - -} -//#endif diff --git a/src/main/java/com/replaymod/render/mixin/Mixin_ForceChunkLoading.java b/src/main/java/com/replaymod/render/mixin/Mixin_ForceChunkLoading.java index 332a88fa..d2e9293b 100644 --- a/src/main/java/com/replaymod/render/mixin/Mixin_ForceChunkLoading.java +++ b/src/main/java/com/replaymod/render/mixin/Mixin_ForceChunkLoading.java @@ -1,6 +1,7 @@ package com.replaymod.render.mixin; //#if MC>=10800 +import com.replaymod.compat.shaders.ShaderReflection; import com.replaymod.render.hooks.ChunkLoadingRenderGlobal; import net.minecraft.client.render.Camera; import net.minecraft.client.render.Frustum; @@ -57,13 +58,16 @@ public abstract class Mixin_ForceChunkLoading { private boolean passThrough; @Inject(method = "setupTerrain", at = @At("HEAD"), cancellable = true) - private void forceAllChunks(Camera camera_1, Frustum frustum_1, boolean boolean_1, int int_1, boolean boolean_2, CallbackInfo ci) { + private void forceAllChunks(Camera camera_1, Frustum frustum_1, boolean boolean_1, int int_1, boolean boolean_2, CallbackInfo ci) throws IllegalAccessException { if (replayModRender_hook == null) { return; } if (passThrough) { return; } + if (ShaderReflection.shaders_isShadowPass != null && (boolean) ShaderReflection.shaders_isShadowPass.get(null)) { + return; + } ci.cancel(); passThrough = true; @@ -131,7 +135,10 @@ public abstract class Mixin_ForceChunkLoading { //$$ int frameCount, //$$ boolean playerSpectator, //$$ CallbackInfo ci - //$$ ) { + //$$ ) throws IllegalAccessException { + //$$ if (ShaderReflection.shaders_isShadowPass != null && (boolean) ShaderReflection.shaders_isShadowPass.get(null)) { + //$$ return; + //$$ } //$$ if (replayModRender_hook != null && !replayModRender_passThroughSetupTerrain) { //$$ replayModRender_passThroughSetupTerrain = true; //$$ diff --git a/src/main/resources/mixins.compat.shaders.replaymod.json b/src/main/resources/mixins.compat.shaders.replaymod.json index 133b1106..163e36b0 100644 --- a/src/main/resources/mixins.compat.shaders.replaymod.json +++ b/src/main/resources/mixins.compat.shaders.replaymod.json @@ -10,7 +10,6 @@ //#if MC>=10800 "MixinShaderEntityRenderer", "MixinShaderRenderChunk", - "MixinShaderRenderGlobal", //#else //$$ "MixinShaders", //#endif