From 3c84087f151f81964bad0048e9b503c0c10c1e17 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Mon, 7 Jun 2021 16:14:51 -0700 Subject: [PATCH] Fix saw and PSI diffuse - Fix saw and portable storage/fluid interface diffuse lighting - Remove "disableDiffuseTransform" option from SuperByteBuffer - Switch argument order in RenderedContraption constructor to be consistent with superclass (ContraptionWorldHolder) --- .../PortableStorageInterfaceRenderer.java | 46 +++++++++---------- .../components/saw/SawRenderer.java | 22 ++++----- .../render/ContraptionRenderDispatcher.java | 2 +- .../render/RenderedContraption.java | 2 +- .../foundation/render/SuperByteBuffer.java | 14 +----- 5 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java index c6700f0f3..287b2314f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java @@ -15,7 +15,6 @@ import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockState; @@ -39,8 +38,8 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer sbb.light(light) - .renderInto(ms, vb), ms); + render(blockState, te.isConnected(), progress, null, sbb -> sbb.light(light) + .renderInto(ms, vb)); } public static void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld, @@ -57,39 +56,36 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer sbb.transform(matrices.contraptionStack) - .disableDiffuseTransform() - .light(matrices.entityMatrix, + render(blockState, lit, progress, matrices.contraptionStack, sbb -> sbb.light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, vb), matrices.contraptionStack); + .renderInto(matrices.entityStack, vb)); } - private static void render(BlockState blockState, float progress, boolean lit, - Consumer drawCallback, MatrixStack ms) { - ms.push(); - + private static void render(BlockState blockState, boolean lit, float progress, + MatrixStack local, Consumer drawCallback) { SuperByteBuffer middle = PartialBufferer.get(getMiddleForState(blockState, lit), blockState); SuperByteBuffer top = PartialBufferer.get(getTopForState(blockState), blockState); + if (local != null) { + middle.transform(local); + top.transform(local); + } Direction facing = blockState.get(PortableStorageInterfaceBlock.FACING); - MatrixStacker.of(ms) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) - .unCentre(); - - ms.translate(0, progress / 2f, 0); - ms.push(); - ms.translate(0, 6 / 16f, 0); + rotateToFacing(middle, facing); + rotateToFacing(top, facing); + middle.translate(0, progress * 0.5f + 0.375f, 0); + top.translate(0, progress, 0); drawCallback.accept(middle); - - ms.pop(); - ms.translate(0, progress / 2f, 0); - drawCallback.accept(top); + } - ms.pop(); + private static void rotateToFacing(SuperByteBuffer buffer, Direction facing) { + buffer.matrixStacker() + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) + .unCentre(); } protected static PortableStorageInterfaceTileEntity getTargetPSI(MovementContext context) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 688796acd..7d4532965 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -56,11 +56,9 @@ public class SawRenderer extends SafeTileEntityRenderer { protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light) { BlockState blockState = te.getBlockState(); - SuperByteBuffer superBuffer; PartialModel partial; float speed = te.getSpeed(); - - ms.push(); + boolean rotate = false; if (SawBlock.isHorizontal(blockState)) { if (speed > 0) { @@ -80,16 +78,17 @@ public class SawRenderer extends SafeTileEntityRenderer { } if (!blockState.get(SawBlock.AXIS_ALONG_FIRST_COORDINATE)) - MatrixStacker.of(ms) - .centre() - .rotateY(90) - .unCentre(); + rotate = true; } - superBuffer = PartialBufferer.getFacing(partial, blockState); - superBuffer.light(light) - .renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped())); - ms.pop(); + SuperByteBuffer superBuffer = PartialBufferer.getFacing(partial, blockState); + if (rotate) { + superBuffer.rotateCentered(Direction.UP, AngleHelper.rad(90)); + } + superBuffer + .color(0xFFFFFF) + .light(light) + .renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped())); } protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { @@ -198,7 +197,6 @@ public class SawRenderer extends SafeTileEntityRenderer { superBuffer .transform(m) - .disableDiffuseTransform() .light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.getCutoutMipped())); 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 7038cd6f3..ce4963c3e 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 @@ -160,7 +160,7 @@ public class ContraptionRenderDispatcher { if (contraption == null) { PlacementSimulationWorld renderWorld = setupRenderWorld(world, c); - contraption = new RenderedContraption(renderWorld, c); + contraption = new RenderedContraption(c, renderWorld); RENDERERS.put(entityId, contraption); } 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 6ee05def0..84ce22b80 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 @@ -57,7 +57,7 @@ public class RenderedContraption extends ContraptionWorldHolder { private Matrix4f model; private AxisAlignedBB lightBox; - public RenderedContraption(PlacementSimulationWorld renderWorld, Contraption contraption) { + public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { super(contraption, renderWorld); this.lighter = contraption.makeLighter(); this.materialManager = new ContraptionMaterialManager(CreateContexts.CWORLD); diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index 3f7c941a8..395169341 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -37,7 +37,6 @@ public class SuperByteBuffer { // Vertex Coloring private boolean shouldColor; private int r, g, b, a; - private boolean disableDiffuseTransform; // Vertex Lighting private boolean useWorldLight; @@ -120,12 +119,7 @@ public class SuperByteBuffer { int colorB = Math.min(255, (int) (((float) this.b) * instanceDiffuse)); builder.color(colorR, colorG, colorB, this.a); } else { - float diffuseMult; - if (disableDiffuseTransform) { - diffuseMult = 1.0f; - } else { - diffuseMult = instanceDiffuse / staticDiffuse; - } + float diffuseMult = instanceDiffuse / staticDiffuse; int colorR = Math.min(255, (int) (((float) Byte.toUnsignedInt(r)) * diffuseMult)); int colorG = Math.min(255, (int) (((float) Byte.toUnsignedInt(g)) * diffuseMult)); int colorB = Math.min(255, (int) (((float) Byte.toUnsignedInt(b)) * diffuseMult)); @@ -179,7 +173,6 @@ public class SuperByteBuffer { g = 0; b = 0; a = 0; - disableDiffuseTransform = false; useWorldLight = false; hybridLight = false; packedLightCoords = 0; @@ -248,11 +241,6 @@ public class SuperByteBuffer { return this; } - public SuperByteBuffer disableDiffuseTransform() { - disableDiffuseTransform = true; - return this; - } - public SuperByteBuffer shiftUV(SpriteShiftEntry entry) { this.spriteShiftFunc = (builder, u, v) -> { float targetU = entry.getTarget()