Ordered blaze transformations

- Fix parts of blaze burners not rendering correctly on rotated
contraptions
- AbstractContraptionEntity#doLocalTransforms -> applyLocalTransforms
and change PoseStack[] argument to PoseStack
This commit is contained in:
PepperCode1 2022-09-09 12:10:34 -07:00
parent dfe13d4ad7
commit 32b0b2a334
7 changed files with 113 additions and 85 deletions

View file

@ -831,7 +831,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public abstract void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks); public abstract void applyLocalTransforms(PoseStack matrixStack, float partialTicks);
public static class ContraptionRotationState { public static class ContraptionRotationState {
public static final ContraptionRotationState NONE = new ContraptionRotationState(); public static final ContraptionRotationState NONE = new ContraptionRotationState();

View file

@ -226,15 +226,14 @@ public class ControlledContraptionEntity extends AbstractContraptionEntity {
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks) { public void applyLocalTransforms(PoseStack matrixStack, float partialTicks) {
float angle = getAngle(partialTicks); float angle = getAngle(partialTicks);
Axis axis = getRotationAxis(); Axis axis = getRotationAxis();
for (PoseStack stack : matrixStacks) TransformStack.cast(matrixStack)
TransformStack.cast(stack) .nudge(getId())
.nudge(getId()) .centre()
.centre() .rotate(angle, axis)
.rotate(angle, axis) .unCentre();
.unCentre();
} }
} }

View file

@ -514,52 +514,48 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks) { public void applyLocalTransforms(PoseStack matrixStack, float partialTicks) {
float angleInitialYaw = getInitialYaw(); float angleInitialYaw = getInitialYaw();
float angleYaw = getViewYRot(partialTicks); float angleYaw = getViewYRot(partialTicks);
float anglePitch = getViewXRot(partialTicks); float anglePitch = getViewXRot(partialTicks);
for (PoseStack stack : matrixStacks) matrixStack.translate(-.5f, 0, -.5f);
stack.translate(-.5f, 0, -.5f);
Entity ridingEntity = getVehicle(); Entity ridingEntity = getVehicle();
if (ridingEntity instanceof AbstractMinecart) if (ridingEntity instanceof AbstractMinecart)
repositionOnCart(partialTicks, matrixStacks, ridingEntity); repositionOnCart(matrixStack, partialTicks, ridingEntity);
else if (ridingEntity instanceof AbstractContraptionEntity) { else if (ridingEntity instanceof AbstractContraptionEntity) {
if (ridingEntity.getVehicle() instanceof AbstractMinecart) if (ridingEntity.getVehicle() instanceof AbstractMinecart)
repositionOnCart(partialTicks, matrixStacks, ridingEntity.getVehicle()); repositionOnCart(matrixStack, partialTicks, ridingEntity.getVehicle());
else else
repositionOnContraption(partialTicks, matrixStacks, ridingEntity); repositionOnContraption(matrixStack, partialTicks, ridingEntity);
} }
for (PoseStack stack : matrixStacks) TransformStack.cast(matrixStack)
TransformStack.cast(stack) .nudge(getId())
.nudge(getId()) .centre()
.centre() .rotateY(angleYaw)
.rotateY(angleYaw) .rotateZ(anglePitch)
.rotateZ(anglePitch) .rotateY(angleInitialYaw)
.rotateY(angleInitialYaw) .unCentre();
.unCentre();
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private void repositionOnContraption(float partialTicks, PoseStack[] matrixStacks, Entity ridingEntity) { private void repositionOnContraption(PoseStack matrixStack, float partialTicks, Entity ridingEntity) {
Vec3 pos = getContraptionOffset(partialTicks, ridingEntity); Vec3 pos = getContraptionOffset(partialTicks, ridingEntity);
for (PoseStack stack : matrixStacks) matrixStack.translate(pos.x, pos.y, pos.z);
stack.translate(pos.x, pos.y, pos.z);
} }
// Minecarts do not always render at their exact location, so the contraption // Minecarts do not always render at their exact location, so the contraption
// has to adjust aswell // has to adjust aswell
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private void repositionOnCart(float partialTicks, PoseStack[] matrixStacks, Entity ridingEntity) { private void repositionOnCart(PoseStack matrixStack, float partialTicks, Entity ridingEntity) {
Vec3 cartPos = getCartOffset(partialTicks, ridingEntity); Vec3 cartPos = getCartOffset(partialTicks, ridingEntity);
if (cartPos == Vec3.ZERO) if (cartPos == Vec3.ZERO)
return; return;
for (PoseStack stack : matrixStacks) matrixStack.translate(cartPos.x, cartPos.y, cartPos.z);
stack.translate(cartPos.x, cartPos.y, cartPos.z);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)

View file

@ -176,7 +176,7 @@ public class GantryContraptionEntity extends AbstractContraptionEntity {
} }
@Override @Override
public void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks) { } public void applyLocalTransforms(PoseStack matrixStack, float partialTicks) { }
public void updateClientMotion() { public void updateClientMotion() {
float modifier = movementAxis.getAxisDirection() float modifier = movementAxis.getAxisDirection()

View file

@ -34,7 +34,7 @@ public class ContraptionMatrices {
this.viewProjection.pushPose(); this.viewProjection.pushPose();
transform(this.viewProjection, viewProjection); transform(this.viewProjection, viewProjection);
model.pushPose(); model.pushPose();
entity.doLocalTransforms(partialTicks, new PoseStack[] { model }); entity.applyLocalTransforms(model, partialTicks);
modelViewProjection.pushPose(); modelViewProjection.pushPose();
transform(modelViewProjection, viewProjection); transform(modelViewProjection, viewProjection);

View file

@ -33,52 +33,67 @@ public class BlazeBurnerRenderer extends SafeTileEntityRenderer<BlazeBurnerTileE
public BlazeBurnerRenderer(BlockEntityRendererProvider.Context context) {} public BlazeBurnerRenderer(BlockEntityRendererProvider.Context context) {}
@Override @Override
protected void renderSafe(BlazeBurnerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, protected void renderSafe(BlazeBurnerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource bufferSource,
int light, int overlay) { int light, int overlay) {
HeatLevel heatLevel = te.getHeatLevelFromBlock(); HeatLevel heatLevel = te.getHeatLevelFromBlock();
if (heatLevel == HeatLevel.NONE) if (heatLevel == HeatLevel.NONE)
return; return;
float horizontalAngle = AngleHelper.rad(te.headAngle.getValue(partialTicks));
Level level = te.getLevel(); Level level = te.getLevel();
int hashCode = te.hashCode();
float animation = te.headAnimation.getValue(partialTicks) * .175f;
BlockState blockState = te.getBlockState(); BlockState blockState = te.getBlockState();
float animation = te.headAnimation.getValue(partialTicks) * .175f;
float horizontalAngle = AngleHelper.rad(te.headAngle.getValue(partialTicks));
boolean canDrawFlame = heatLevel.isAtLeast(HeatLevel.FADING);
boolean drawGoggles = te.goggles; boolean drawGoggles = te.goggles;
boolean drawHat = te.hat; boolean drawHat = te.hat;
int hashCode = te.hashCode();
renderShared(level, buffer, null, ms, blockState, horizontalAngle, animation, drawGoggles, drawHat, hashCode); renderShared(ms, null, bufferSource,
level, blockState, heatLevel, animation, horizontalAngle,
canDrawFlame, drawGoggles, drawHat, hashCode);
} }
public static void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld, public static void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffer, LerpedFloat headAngle, boolean conductor) { ContraptionMatrices matrices, MultiBufferSource bufferSource, LerpedFloat headAngle, boolean conductor) {
BlockState state = context.state; BlockState state = context.state;
if (BlazeBurnerBlock.getHeatLevelOf(state) == HeatLevel.KINDLED) HeatLevel heatLevel = BlazeBurnerBlock.getHeatLevelOf(state);
state = state.setValue(BlazeBurnerBlock.HEAT_LEVEL, HeatLevel.FADING); if (heatLevel == HeatLevel.NONE)
float value = AngleHelper.rad(headAngle.getValue(AnimationTickHolder.getPartialTicks(context.world))); return;
renderShared(context.world, buffer, matrices.getModel(), matrices.getViewProjection(), state, value, 0,
context.tileData.contains("Goggles"), conductor, context.hashCode()); if (!heatLevel.isAtLeast(HeatLevel.FADING)) {
heatLevel = HeatLevel.FADING;
}
Level level = context.world;
float horizontalAngle = AngleHelper.rad(headAngle.getValue(AnimationTickHolder.getPartialTicks(level)));
boolean drawGoggles = context.tileData.contains("Goggles");
boolean drawHat = conductor || context.tileData.contains("TrainHat");
int hashCode = context.hashCode();
renderShared(matrices.getViewProjection(), matrices.getModel(), bufferSource,
level, state, heatLevel, 0, horizontalAngle,
false, drawGoggles, drawHat, hashCode);
} }
private static void renderShared(Level level, MultiBufferSource buffer, @Nullable PoseStack modelTransform, private static void renderShared(PoseStack ms, @Nullable PoseStack modelTransform, MultiBufferSource bufferSource,
PoseStack ms, BlockState blockState, float horizontalAngle, float animation, boolean drawGoggles, Level level, BlockState blockState, HeatLevel heatLevel, float animation, float horizontalAngle,
boolean drawHat, int hashCode) { boolean canDrawFlame, boolean drawGoggles, boolean drawHat, int hashCode) {
boolean blockAbove = animation > 0.125f; boolean blockAbove = animation > 0.125f;
HeatLevel heatLevel = BlazeBurnerBlock.getHeatLevelOf(blockState);
float time = AnimationTickHolder.getRenderTime(level); float time = AnimationTickHolder.getRenderTime(level);
float renderTick = time + (hashCode % 13) * 16f; float renderTick = time + (hashCode % 13) * 16f;
float offsetMult = heatLevel.isAtLeast(HeatLevel.FADING) ? 64 : 16; float offsetMult = heatLevel.isAtLeast(HeatLevel.FADING) ? 64 : 16;
float offset = Mth.sin((float) ((renderTick / 16f) % (2 * Math.PI))) / offsetMult; float offset = Mth.sin((float) ((renderTick / 16f) % (2 * Math.PI))) / offsetMult;
float offset1 = Mth.sin((float) ((renderTick / 16f + Math.PI) % (2 * Math.PI))) / offsetMult; float offset1 = Mth.sin((float) ((renderTick / 16f + Math.PI) % (2 * Math.PI))) / offsetMult;
float offset2 = Mth.sin((float) ((renderTick / 16f + Math.PI / 2) % (2 * Math.PI))) / offsetMult; float offset2 = Mth.sin((float) ((renderTick / 16f + Math.PI / 2) % (2 * Math.PI))) / offsetMult;
float headY = offset - (animation * .75f);
VertexConsumer solid = buffer.getBuffer(RenderType.solid()); VertexConsumer solid = bufferSource.getBuffer(RenderType.solid());
VertexConsumer cutout = buffer.getBuffer(RenderType.cutoutMipped()); VertexConsumer cutout = bufferSource.getBuffer(RenderType.cutoutMipped());
ms.pushPose(); ms.pushPose();
if (modelTransform == null && heatLevel.isAtLeast(HeatLevel.FADING) && blockAbove) { if (canDrawFlame && blockAbove) {
SpriteShiftEntry spriteShift = SpriteShiftEntry spriteShift =
heatLevel == HeatLevel.SEETHING ? AllSpriteShifts.SUPER_BURNER_FLAME : AllSpriteShifts.BURNER_FLAME; heatLevel == HeatLevel.SEETHING ? AllSpriteShifts.SUPER_BURNER_FLAME : AllSpriteShifts.BURNER_FLAME;
@ -102,68 +117,87 @@ public class BlazeBurnerRenderer extends SafeTileEntityRenderer<BlazeBurnerTileE
uScroll = uScroll - Math.floor(uScroll); uScroll = uScroll - Math.floor(uScroll);
uScroll = uScroll * spriteWidth / 2; uScroll = uScroll * spriteWidth / 2;
draw(CachedBufferer.partial(AllBlockPartials.BLAZE_BURNER_FLAME, blockState) SuperByteBuffer flameBuffer = CachedBufferer.partial(AllBlockPartials.BLAZE_BURNER_FLAME, blockState);
.shiftUVScrolling(spriteShift, (float) uScroll, (float) vScroll), horizontalAngle, modelTransform, ms, if (modelTransform != null)
cutout); flameBuffer.transform(modelTransform);
flameBuffer.shiftUVScrolling(spriteShift, (float) uScroll, (float) vScroll);
draw(flameBuffer, horizontalAngle, ms, cutout);
} }
PartialModel blazeModel = modelTransform != null ? AllBlockPartials.BLAZE_IDLE : AllBlockPartials.BLAZE_INERT; PartialModel blazeModel;
if (heatLevel.isAtLeast(HeatLevel.SEETHING)) if (heatLevel.isAtLeast(HeatLevel.SEETHING)) {
blazeModel = blockAbove ? AllBlockPartials.BLAZE_SUPER_ACTIVE : AllBlockPartials.BLAZE_SUPER; blazeModel = blockAbove ? AllBlockPartials.BLAZE_SUPER_ACTIVE : AllBlockPartials.BLAZE_SUPER;
else if (heatLevel.isAtLeast(HeatLevel.FADING)) } else if (heatLevel.isAtLeast(HeatLevel.FADING)) {
blazeModel = blockAbove && heatLevel.isAtLeast(HeatLevel.KINDLED) ? AllBlockPartials.BLAZE_ACTIVE blazeModel = blockAbove && heatLevel.isAtLeast(HeatLevel.KINDLED) ? AllBlockPartials.BLAZE_ACTIVE
: AllBlockPartials.BLAZE_IDLE; : AllBlockPartials.BLAZE_IDLE;
} else {
blazeModel = AllBlockPartials.BLAZE_INERT;
}
float headY = offset - (animation * .75f); SuperByteBuffer blazeBuffer = CachedBufferer.partial(blazeModel, blockState);
if (modelTransform != null)
blazeBuffer.transform(modelTransform);
blazeBuffer.translate(0, headY, 0);
draw(blazeBuffer, horizontalAngle, ms, solid);
draw(CachedBufferer.partial(blazeModel, blockState) if (drawGoggles) {
.translate(0, headY, 0), horizontalAngle, modelTransform, ms, solid); PartialModel gogglesModel = blazeModel == AllBlockPartials.BLAZE_INERT
? AllBlockPartials.BLAZE_GOGGLES_SMALL : AllBlockPartials.BLAZE_GOGGLES;
if (drawGoggles) SuperByteBuffer gogglesBuffer = CachedBufferer.partial(gogglesModel, blockState);
draw(CachedBufferer.partial(blazeModel == AllBlockPartials.BLAZE_INERT if (modelTransform != null)
? AllBlockPartials.BLAZE_GOGGLES_SMALL : AllBlockPartials.BLAZE_GOGGLES, blockState) gogglesBuffer.transform(modelTransform);
.translate(0, headY + 8 / 16f, 0), horizontalAngle, modelTransform, ms, solid); gogglesBuffer.translate(0, headY + 8 / 16f, 0);
draw(gogglesBuffer, horizontalAngle, ms, solid);
}
if (drawHat) { if (drawHat) {
SuperByteBuffer partial = CachedBufferer.partial(AllBlockPartials.TRAIN_HAT, blockState) SuperByteBuffer hatBuffer = CachedBufferer.partial(AllBlockPartials.TRAIN_HAT, blockState);
.translate(0, headY, 0); if (modelTransform != null)
hatBuffer.transform(modelTransform);
hatBuffer.translate(0, headY, 0);
if (blazeModel == AllBlockPartials.BLAZE_INERT) { if (blazeModel == AllBlockPartials.BLAZE_INERT) {
partial.translateY(0.5f) hatBuffer.translateY(0.5f)
.centre() .centre()
.scale(0.75f) .scale(0.75f)
.unCentre(); .unCentre();
} else { } else {
partial.translateY(0.75f); hatBuffer.translateY(0.75f);
} }
if (modelTransform != null) hatBuffer
partial.transform(modelTransform);
partial
.rotateCentered(Direction.UP, horizontalAngle + Mth.PI) .rotateCentered(Direction.UP, horizontalAngle + Mth.PI)
.translate(0.5f, 0, 0.5f) .translate(0.5f, 0, 0.5f)
.light(LightTexture.FULL_BRIGHT) .light(LightTexture.FULL_BRIGHT)
.renderInto(ms, solid); .renderInto(ms, solid);
} }
if (heatLevel.isAtLeast(HeatLevel.FADING) || modelTransform != null) { if (heatLevel.isAtLeast(HeatLevel.FADING)) {
PartialModel rods = heatLevel == HeatLevel.SEETHING ? AllBlockPartials.BLAZE_BURNER_SUPER_RODS PartialModel rodsModel = heatLevel == HeatLevel.SEETHING ? AllBlockPartials.BLAZE_BURNER_SUPER_RODS
: AllBlockPartials.BLAZE_BURNER_RODS; : AllBlockPartials.BLAZE_BURNER_RODS;
PartialModel rods2 = heatLevel == HeatLevel.SEETHING ? AllBlockPartials.BLAZE_BURNER_SUPER_RODS_2 PartialModel rodsModel2 = heatLevel == HeatLevel.SEETHING ? AllBlockPartials.BLAZE_BURNER_SUPER_RODS_2
: AllBlockPartials.BLAZE_BURNER_RODS_2; : AllBlockPartials.BLAZE_BURNER_RODS_2;
draw(CachedBufferer.partial(rods, blockState)
.translate(0, offset1 + animation + .125f, 0), 0, modelTransform, ms, solid); SuperByteBuffer rodsBuffer = CachedBufferer.partial(rodsModel, blockState);
draw(CachedBufferer.partial(rods2, blockState) if (modelTransform != null)
.translate(0, offset2 + animation - 3 / 16f, 0), 0, modelTransform, ms, solid); rodsBuffer.transform(modelTransform);
rodsBuffer.translate(0, offset1 + animation + .125f, 0)
.light(LightTexture.FULL_BRIGHT)
.renderInto(ms, solid);
SuperByteBuffer rodsBuffer2 = CachedBufferer.partial(rodsModel2, blockState);
if (modelTransform != null)
rodsBuffer2.transform(modelTransform);
rodsBuffer2.translate(0, offset2 + animation - 3 / 16f, 0)
.light(LightTexture.FULL_BRIGHT)
.renderInto(ms, solid);
} }
ms.popPose(); ms.popPose();
} }
private static void draw(SuperByteBuffer blazeBuffer, float horizontalAngle, @Nullable PoseStack modelTransform, private static void draw(SuperByteBuffer buffer, float horizontalAngle, PoseStack ms, VertexConsumer vc) {
PoseStack ms, VertexConsumer vb) { buffer.rotateCentered(Direction.UP, horizontalAngle)
if (modelTransform != null)
blazeBuffer.transform(modelTransform);
blazeBuffer.rotateCentered(Direction.UP, horizontalAngle)
.light(LightTexture.FULL_BRIGHT) .light(LightTexture.FULL_BRIGHT)
.renderInto(ms, vb); .renderInto(ms, vc);
} }
} }

View file

@ -8,16 +8,15 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
public abstract class SafeTileEntityRenderer<T extends BlockEntity> implements BlockEntityRenderer<T> { public abstract class SafeTileEntityRenderer<T extends BlockEntity> implements BlockEntityRenderer<T> {
@Override @Override
public final void render(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, public final void render(T te, float partialTicks, PoseStack ms, MultiBufferSource bufferSource, int light,
int overlay) { int overlay) {
if (isInvalid(te)) if (isInvalid(te))
return; return;
renderSafe(te, partialTicks, ms, buffer, light, overlay); renderSafe(te, partialTicks, ms, bufferSource, light, overlay);
} }
protected abstract void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, protected abstract void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource bufferSource, int light,
int overlay); int overlay);
public boolean isInvalid(T te) { public boolean isInvalid(T te) {