From dac9010f20fd89452cc6f08e9bc453d50eb66ef4 Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Fri, 14 May 2021 17:23:10 -0700 Subject: [PATCH] Optimize lighting checks Also - Set null layer after rendering contraption --- .../structureMovement/render/RenderedContraption.java | 7 +++++-- .../utility/worldWrappers/PlacementSimulationWorld.java | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index 6dd2d59c0..d847b9cd8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -175,20 +175,22 @@ public class RenderedContraption { for (Template.BlockInfo info : c.getBlocks() .values()) - renderWorld.setBlockState(info.pos, info.state); + // Skip individual lighting updates to prevent lag with large contraptions + renderWorld.setBlockState(info.pos, info.state, 128); + renderWorld.updateLightSources(); renderWorld.lighter.tick(Integer.MAX_VALUE, false, false); return renderWorld; } private static BufferBuilder buildStructure(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { - ForgeHooksClient.setRenderLayer(layer); MatrixStack ms = new MatrixStack(); Random random = new Random(); BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + ForgeHooksClient.setRenderLayer(layer); BlockModelRenderer.enableCache(); for (Template.BlockInfo info : c.getBlocks() .values()) { @@ -208,6 +210,7 @@ public class RenderedContraption { ms.pop(); } BlockModelRenderer.disableCache(); + ForgeHooksClient.setRenderLayer(null); builder.finishDrawing(); return builder; diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index b6c768810..733b8fd60 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -73,7 +73,9 @@ public class PlacementSimulationWorld extends WrappedWorld implements IFlywheelW lighter.updateSectionStatus(sectionPos, false); } - lighter.checkBlock(pos); + if ((flags & 128) == 0) { + lighter.checkBlock(pos); + } return true; }