diff --git a/src/main/java/com/jozufozu/flywheel/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/CancelTileEntityRenderMixin.java deleted file mode 100644 index 21b6bc0ac..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/CancelTileEntityRenderMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.jozufozu.flywheel.mixin; - -import java.util.List; - -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 com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; - -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; -import net.minecraft.world.level.block.entity.BlockEntity; - -@Mixin(ChunkRenderDispatcher.CompiledChunk.class) -public class CancelTileEntityRenderMixin { - - /** - * JUSTIFICATION: when instanced rendering is enabled, many tile entities no longer need - * to be processed by the normal game renderer. This method is only called to retrieve the - * list of tile entities to render. By filtering the output here, we prevent the game from - * doing unnecessary light lookups and frustum checks. - */ - @Inject(at = @At("RETURN"), method = "getRenderableBlockEntities", cancellable = true) - private void noRenderInstancedTiles(CallbackInfoReturnable> cir) { - if (Backend.getInstance() - .canUseInstancing()) { - List tiles = cir.getReturnValue(); - - InstancedRenderRegistry r = InstancedRenderRegistry.getInstance(); - tiles.removeIf(r::shouldSkipRender); - } - } -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java new file mode 100644 index 000000000..e7f1dfaf6 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java @@ -0,0 +1,30 @@ +package com.jozufozu.flywheel.mixin; + +import java.util.Set; + +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.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; + +import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask") +public class ChunkRebuildHooksMixin { + + @Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true) + private void filterBlockEntity(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set set, E be, CallbackInfo ci) { + + if (Backend.getInstance().canUseInstancing() && Backend.isFlywheelWorld(be.getLevel()) && InstancedRenderRegistry.getInstance() + .shouldSkipRender(be)) { + ci.cancel(); + } + } +} diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index d08e53e85..472139c7f 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -6,7 +6,7 @@ "refmap": "flywheel.refmap.json", "client": [ "CancelEntityRenderMixin", - "CancelTileEntityRenderMixin", + "ChunkRebuildHooksMixin", "FixFabulousDepthMixin", "RenderHooksMixin", "ShaderCloseMixin",