From f3d22444d38dc9a0d407d94c3d652b231ae5c30a Mon Sep 17 00:00:00 2001 From: ToadDev <748280+Toad-Dev@users.noreply.github.com> Date: Thu, 10 Jun 2021 00:59:21 -0700 Subject: [PATCH] Fix: Stop water and chests being drawn over monitors Somewhere along the line the gl state was being mangled and I'm still not sure where! I moved the monitor blocks from the cutout render layer to the default solid layer, which obviates the depth blocker. I don't think the transparent front of the monitor blocks was ever visible so this should be fine. Then the terminal quads are moved slightly outward to prevent z-fighting with the now present block front. Finally I noticed some chests were not rendering correctly around monitors, so I paired an endDrawing() call with our sneaky hack of calling startDrawing() to force the rendering state. This fixed the chests. Hopefully we haven't messed up the render state in more ways :) --- .../proxy/ComputerCraftProxyClient.java | 4 --- .../render/TileEntityMonitorRenderer.java | 25 ++++++++----------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index fa7c0a8f1..d59206009 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -77,10 +77,6 @@ public final class ComputerCraftProxyClient implements ClientModInitializer BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.TURTLE_NORMAL, RenderLayer.getTranslucent() ); BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.TURTLE_ADVANCED, RenderLayer.getTranslucent() ); - // Monitors' textures have transparent fronts and so count as cutouts. - BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.MONITOR_NORMAL, RenderLayer.getCutout() ); - BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.MONITOR_ADVANCED, RenderLayer.getCutout() ); - // Setup TESRs BlockEntityRendererRegistry.INSTANCE.register( ComputerCraftRegistry.ModTiles.MONITOR_NORMAL, TileEntityMonitorRenderer::new ); BlockEntityRendererRegistry.INSTANCE.register( ComputerCraftRegistry.ModTiles.MONITOR_ADVANCED, TileEntityMonitorRenderer::new ); diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 5390b812a..3e797aa7b 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -59,10 +59,7 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer // Render from the origin monitor ClientMonitor originTerminal = monitor.getClientMonitor(); - if( originTerminal == null ) - { - return; - } + if( originTerminal == null ) return; TileMonitor origin = originTerminal.getOrigin(); BlockPos monitorPos = monitor.getPos(); @@ -96,7 +93,7 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( pitch ) ); transform.translate( -0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN, origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0, - 0.5 ); + 0.501 ); double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER); double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER); @@ -112,8 +109,7 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer transform.push(); transform.scale( (float) xScale, (float) -yScale, 1.0f ); - Matrix4f matrix = transform.peek() - .getModel(); + Matrix4f matrix = transform.peek().getModel(); // Sneaky hack here: we get a buffer now in order to flush existing ones and set up the appropriate // render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick @@ -127,6 +123,8 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer // reasonable. FixedWidthFontRenderer.drawCursor( matrix, buffer, 0, 0, terminal, !originTerminal.isColour() ); + FixedWidthFontRenderer.TYPE.endDrawing(); + transform.pop(); } else @@ -140,13 +138,12 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer (float) -(ySize + MARGIN * 2) ); } - FixedWidthFontRenderer.drawBlocker( transform.peek() - .getModel(), - renderer, - (float) -TileMonitor.RENDER_MARGIN, - (float) TileMonitor.RENDER_MARGIN, - (float) (xSize + 2 * TileMonitor.RENDER_MARGIN), - (float) -(ySize + TileMonitor.RENDER_MARGIN * 2) ); +// FixedWidthFontRenderer.drawBlocker( transform.peek().getModel(), +// renderer, +// (float) -TileMonitor.RENDER_MARGIN, +// (float) TileMonitor.RENDER_MARGIN, +// (float) (xSize + 2 * TileMonitor.RENDER_MARGIN), +// (float) -(ySize + TileMonitor.RENDER_MARGIN * 2) ); transform.pop(); }