Merge remote-tracking branch 'origin/chromatic-projector' into mc1.16/chromatic-projector

This commit is contained in:
JozsefA 2021-06-07 18:24:25 -07:00
commit 1ce141850b
5 changed files with 34 additions and 52 deletions

View File

@ -15,7 +15,6 @@ import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.MatrixStacker;
import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -39,8 +38,8 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer<Por
BlockState blockState = te.getBlockState(); BlockState blockState = te.getBlockState();
float progress = te.getExtensionDistance(partialTicks); float progress = te.getExtensionDistance(partialTicks);
IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid());
render(blockState, progress, te.isConnected(), sbb -> sbb.light(light) render(blockState, te.isConnected(), progress, null, sbb -> sbb.light(light)
.renderInto(ms, vb), ms); .renderInto(ms, vb));
} }
public static void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld, public static void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
@ -57,39 +56,36 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer<Por
lit = te.isConnected(); lit = te.isConnected();
} }
render(blockState, progress, lit, sbb -> sbb.transform(matrices.contraptionStack) render(blockState, lit, progress, matrices.contraptionStack, sbb -> sbb.light(matrices.entityMatrix,
.disableDiffuseTransform()
.light(matrices.entityMatrix,
ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld))
.renderInto(matrices.entityStack, vb), matrices.contraptionStack); .renderInto(matrices.entityStack, vb));
} }
private static void render(BlockState blockState, float progress, boolean lit, private static void render(BlockState blockState, boolean lit, float progress,
Consumer<SuperByteBuffer> drawCallback, MatrixStack ms) { MatrixStack local, Consumer<SuperByteBuffer> drawCallback) {
ms.push();
SuperByteBuffer middle = PartialBufferer.get(getMiddleForState(blockState, lit), blockState); SuperByteBuffer middle = PartialBufferer.get(getMiddleForState(blockState, lit), blockState);
SuperByteBuffer top = PartialBufferer.get(getTopForState(blockState), blockState); SuperByteBuffer top = PartialBufferer.get(getTopForState(blockState), blockState);
if (local != null) {
middle.transform(local);
top.transform(local);
}
Direction facing = blockState.get(PortableStorageInterfaceBlock.FACING); Direction facing = blockState.get(PortableStorageInterfaceBlock.FACING);
MatrixStacker.of(ms) rotateToFacing(middle, facing);
rotateToFacing(top, facing);
middle.translate(0, progress * 0.5f + 0.375f, 0);
top.translate(0, progress, 0);
drawCallback.accept(middle);
drawCallback.accept(top);
}
private static void rotateToFacing(SuperByteBuffer buffer, Direction facing) {
buffer.matrixStacker()
.centre() .centre()
.rotateY(AngleHelper.horizontalAngle(facing)) .rotateY(AngleHelper.horizontalAngle(facing))
.rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90)
.unCentre(); .unCentre();
ms.translate(0, progress / 2f, 0);
ms.push();
ms.translate(0, 6 / 16f, 0);
drawCallback.accept(middle);
ms.pop();
ms.translate(0, progress / 2f, 0);
drawCallback.accept(top);
ms.pop();
} }
protected static PortableStorageInterfaceTileEntity getTargetPSI(MovementContext context) { protected static PortableStorageInterfaceTileEntity getTargetPSI(MovementContext context) {

View File

@ -56,11 +56,9 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light) { protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light) {
BlockState blockState = te.getBlockState(); BlockState blockState = te.getBlockState();
SuperByteBuffer superBuffer;
PartialModel partial; PartialModel partial;
float speed = te.getSpeed(); float speed = te.getSpeed();
boolean rotate = false;
ms.push();
if (SawBlock.isHorizontal(blockState)) { if (SawBlock.isHorizontal(blockState)) {
if (speed > 0) { if (speed > 0) {
@ -80,16 +78,17 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
} }
if (!blockState.get(SawBlock.AXIS_ALONG_FIRST_COORDINATE)) if (!blockState.get(SawBlock.AXIS_ALONG_FIRST_COORDINATE))
MatrixStacker.of(ms) rotate = true;
.centre()
.rotateY(90)
.unCentre();
} }
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) { protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
@ -198,7 +197,6 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
superBuffer superBuffer
.transform(m) .transform(m)
.disableDiffuseTransform()
.light(matrices.entityMatrix, .light(matrices.entityMatrix,
ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld))
.renderInto(matrices.entityStack, buffer.getBuffer(RenderType.getCutoutMipped())); .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.getCutoutMipped()));

View File

@ -160,7 +160,7 @@ public class ContraptionRenderDispatcher {
if (contraption == null) { if (contraption == null) {
PlacementSimulationWorld renderWorld = setupRenderWorld(world, c); PlacementSimulationWorld renderWorld = setupRenderWorld(world, c);
contraption = new RenderedContraption(renderWorld, c); contraption = new RenderedContraption(c, renderWorld);
RENDERERS.put(entityId, contraption); RENDERERS.put(entityId, contraption);
} }

View File

@ -57,7 +57,7 @@ public class RenderedContraption extends ContraptionWorldHolder {
private Matrix4f model; private Matrix4f model;
private AxisAlignedBB lightBox; private AxisAlignedBB lightBox;
public RenderedContraption(PlacementSimulationWorld renderWorld, Contraption contraption) { public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) {
super(contraption, renderWorld); super(contraption, renderWorld);
this.lighter = contraption.makeLighter(); this.lighter = contraption.makeLighter();
this.materialManager = new ContraptionMaterialManager(CreateContexts.CWORLD); this.materialManager = new ContraptionMaterialManager(CreateContexts.CWORLD);

View File

@ -37,7 +37,6 @@ public class SuperByteBuffer {
// Vertex Coloring // Vertex Coloring
private boolean shouldColor; private boolean shouldColor;
private int r, g, b, a; private int r, g, b, a;
private boolean disableDiffuseTransform;
// Vertex Lighting // Vertex Lighting
private boolean useWorldLight; private boolean useWorldLight;
@ -120,12 +119,7 @@ public class SuperByteBuffer {
int colorB = Math.min(255, (int) (((float) this.b) * instanceDiffuse)); int colorB = Math.min(255, (int) (((float) this.b) * instanceDiffuse));
builder.color(colorR, colorG, colorB, this.a); builder.color(colorR, colorG, colorB, this.a);
} else { } else {
float diffuseMult; float diffuseMult = instanceDiffuse / staticDiffuse;
if (disableDiffuseTransform) {
diffuseMult = 1.0f;
} else {
diffuseMult = instanceDiffuse / staticDiffuse;
}
int colorR = Math.min(255, (int) (((float) Byte.toUnsignedInt(r)) * diffuseMult)); int colorR = Math.min(255, (int) (((float) Byte.toUnsignedInt(r)) * diffuseMult));
int colorG = Math.min(255, (int) (((float) Byte.toUnsignedInt(g)) * diffuseMult)); int colorG = Math.min(255, (int) (((float) Byte.toUnsignedInt(g)) * diffuseMult));
int colorB = Math.min(255, (int) (((float) Byte.toUnsignedInt(b)) * diffuseMult)); int colorB = Math.min(255, (int) (((float) Byte.toUnsignedInt(b)) * diffuseMult));
@ -179,7 +173,6 @@ public class SuperByteBuffer {
g = 0; g = 0;
b = 0; b = 0;
a = 0; a = 0;
disableDiffuseTransform = false;
useWorldLight = false; useWorldLight = false;
hybridLight = false; hybridLight = false;
packedLightCoords = 0; packedLightCoords = 0;
@ -248,11 +241,6 @@ public class SuperByteBuffer {
return this; return this;
} }
public SuperByteBuffer disableDiffuseTransform() {
disableDiffuseTransform = true;
return this;
}
public SuperByteBuffer shiftUV(SpriteShiftEntry entry) { public SuperByteBuffer shiftUV(SpriteShiftEntry entry) {
this.spriteShiftFunc = (builder, u, v) -> { this.spriteShiftFunc = (builder, u, v) -> {
float targetU = entry.getTarget() float targetU = entry.getTarget()