From d824304f12eb81ee45fe922a4232426f69ea29e3 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 00:13:39 -0800 Subject: [PATCH] tile entities on contraptions account for self lighting --- .../ContraptionRenderer.java | 3 +- .../render/ContraptionRenderDispatcher.java | 9 ++++++ .../render/RenderedContraption.java | 1 + .../render/TileEntityRenderHelper.java | 30 +++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index af13ab7b1..f8b0c8843 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import java.util.List; import java.util.Random; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.*; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import org.apache.commons.lang3.tuple.Pair; @@ -75,7 +76,7 @@ public class ContraptionRenderer { protected static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { if (FastRenderDispatcher.available()) { - TileEntityRenderHelper.renderTileEntities(world, c.specialRenderedTileEntities, ms, msLocal, buffer); + ContraptionRenderDispatcher.renderTileEntities(world, c, ms, msLocal, buffer); } else { TileEntityRenderHelper.renderTileEntities(world, c.maybeInstancedTileEntities, ms, msLocal, buffer); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 0c7441cbd..c82a818bd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -6,10 +6,12 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; import com.simibubi.create.foundation.render.AllProgramSpecs; +import com.simibubi.create.foundation.render.TileEntityRenderHelper; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -61,6 +63,13 @@ public class ContraptionRenderDispatcher { } } + public static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, + IRenderTypeBuffer buffer) { + RenderedContraption renderer = getRenderer(world, c); + + TileEntityRenderHelper.renderTileEntities(world, renderer.renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer); + } + private static void updateTransform(C c, AbstractContraptionEntityRenderer entityRenderer) { MatrixStack stack = entityRenderer.makeTransformMatrix(c, AnimationTickHolder.getPartialTicks()); 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 bc0f33e48..a45f5a75e 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 @@ -130,6 +130,7 @@ public class RenderedContraption { } void setup(ContraptionProgram shader) { + if (model == null) return; shader.bind(model, lighter.lightVolume.getTextureVolume()); lighter.lightVolume.use(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java index 641cfadd0..7cb280de4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java @@ -5,16 +5,16 @@ import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.Vector4f; -import net.minecraft.client.renderer.WorldRenderer; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; import net.minecraft.world.World; +import net.minecraftforge.client.model.pipeline.LightUtil; import java.util.Iterator; @@ -22,6 +22,12 @@ public class TileEntityRenderHelper { public static void renderTileEntities(World world, Iterable customRenderTEs, MatrixStack ms, MatrixStack localTransform, IRenderTypeBuffer buffer) { + + renderTileEntities(world, null, customRenderTEs, ms, localTransform, buffer); + } + + public static void renderTileEntities(World world, PlacementSimulationWorld renderWorld, Iterable customRenderTEs, MatrixStack ms, + MatrixStack localTransform, IRenderTypeBuffer buffer) { float pt = AnimationTickHolder.getPartialTicks(); Matrix4f matrix = localTransform.peek() .getModel(); @@ -45,8 +51,20 @@ public class TileEntityRenderHelper { Vector4f vec = new Vector4f(pos.getX() + .5f, pos.getY() + .5f, pos.getZ() + .5f, 1); vec.transform(matrix); BlockPos lightPos = new BlockPos(vec.getX(), vec.getY(), vec.getZ()); - renderer.render(tileEntity, pt, ms, buffer, WorldRenderer.getLightmapCoordinates(world, lightPos), - OverlayTexture.DEFAULT_UV); + int worldLight = WorldRenderer.getLightmapCoordinates(world, lightPos); + + if (renderWorld != null) { + int contraptionBlockLight = renderWorld.getLightLevel(LightType.BLOCK, pos); + + int worldBlockLight = LightTexture.getBlockLightCoordinates(worldLight); + + if (contraptionBlockLight > worldBlockLight) { + worldLight = (worldLight & 0xFFFF0000) | (contraptionBlockLight << 4); + } + } + + renderer.render(tileEntity, pt, ms, buffer, worldLight, + OverlayTexture.DEFAULT_UV); ms.pop(); } catch (Exception e) {