From df16efd0d6201af7abd7b94cc5a4e69f7d7ab9ac Mon Sep 17 00:00:00 2001 From: Martijn van den Brand Date: Sun, 14 Jul 2024 15:02:42 +0100 Subject: [PATCH] Update vertex consumer after `BLOCK_OUTLINE` event (#3940) --- .../mixin/client/rendering/WorldRendererMixin.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java index 55badbb66..3a90be1a6 100644 --- a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java +++ b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java @@ -25,6 +25,7 @@ import org.spongepowered.asm.mixin.Unique; 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.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.block.BlockState; @@ -123,13 +124,17 @@ public abstract class WorldRendererMixin { if (!WorldRenderEvents.BLOCK_OUTLINE.invoker().onBlockOutline(context, context)) { ci.cancel(); } - - // The immediate mode VertexConsumers use a shared buffer, so we have to make sure that the immediate mode VCP - // can accept block outline lines rendered to the existing vertexConsumer by the vanilla block overlay. - context.consumers().getBuffer(RenderLayer.getLines()); } } + @SuppressWarnings("ConstantConditions") + @ModifyVariable(method = "drawBlockOutline", at = @At("HEAD")) + private VertexConsumer resetBlockOutlineBuffer(VertexConsumer vertexConsumer) { + // The original VertexConsumer may have been ended during the block outlines event, so we + // have to re-request it to prevent a crash when the vanilla block overlay is submitted. + return context.consumers().getBuffer(RenderLayer.getLines()); + } + @Inject( method = "render", at = @At(