mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-26 21:07:58 +01:00
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:
parent
dfe13d4ad7
commit
32b0b2a334
7 changed files with 113 additions and 85 deletions
|
@ -831,7 +831,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
|
|||
}
|
||||
|
||||
@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 final ContraptionRotationState NONE = new ContraptionRotationState();
|
||||
|
|
|
@ -226,15 +226,14 @@ public class ControlledContraptionEntity extends AbstractContraptionEntity {
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks) {
|
||||
public void applyLocalTransforms(PoseStack matrixStack, float partialTicks) {
|
||||
float angle = getAngle(partialTicks);
|
||||
Axis axis = getRotationAxis();
|
||||
|
||||
for (PoseStack stack : matrixStacks)
|
||||
TransformStack.cast(stack)
|
||||
.nudge(getId())
|
||||
.centre()
|
||||
.rotate(angle, axis)
|
||||
.unCentre();
|
||||
TransformStack.cast(matrixStack)
|
||||
.nudge(getId())
|
||||
.centre()
|
||||
.rotate(angle, axis)
|
||||
.unCentre();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -514,52 +514,48 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks) {
|
||||
public void applyLocalTransforms(PoseStack matrixStack, float partialTicks) {
|
||||
float angleInitialYaw = getInitialYaw();
|
||||
float angleYaw = getViewYRot(partialTicks);
|
||||
float anglePitch = getViewXRot(partialTicks);
|
||||
|
||||
for (PoseStack stack : matrixStacks)
|
||||
stack.translate(-.5f, 0, -.5f);
|
||||
matrixStack.translate(-.5f, 0, -.5f);
|
||||
|
||||
Entity ridingEntity = getVehicle();
|
||||
if (ridingEntity instanceof AbstractMinecart)
|
||||
repositionOnCart(partialTicks, matrixStacks, ridingEntity);
|
||||
repositionOnCart(matrixStack, partialTicks, ridingEntity);
|
||||
else if (ridingEntity instanceof AbstractContraptionEntity) {
|
||||
if (ridingEntity.getVehicle() instanceof AbstractMinecart)
|
||||
repositionOnCart(partialTicks, matrixStacks, ridingEntity.getVehicle());
|
||||
repositionOnCart(matrixStack, partialTicks, ridingEntity.getVehicle());
|
||||
else
|
||||
repositionOnContraption(partialTicks, matrixStacks, ridingEntity);
|
||||
repositionOnContraption(matrixStack, partialTicks, ridingEntity);
|
||||
}
|
||||
|
||||
for (PoseStack stack : matrixStacks)
|
||||
TransformStack.cast(stack)
|
||||
.nudge(getId())
|
||||
.centre()
|
||||
.rotateY(angleYaw)
|
||||
.rotateZ(anglePitch)
|
||||
.rotateY(angleInitialYaw)
|
||||
.unCentre();
|
||||
TransformStack.cast(matrixStack)
|
||||
.nudge(getId())
|
||||
.centre()
|
||||
.rotateY(angleYaw)
|
||||
.rotateZ(anglePitch)
|
||||
.rotateY(angleInitialYaw)
|
||||
.unCentre();
|
||||
}
|
||||
|
||||
@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);
|
||||
for (PoseStack stack : matrixStacks)
|
||||
stack.translate(pos.x, pos.y, pos.z);
|
||||
matrixStack.translate(pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// Minecarts do not always render at their exact location, so the contraption
|
||||
// has to adjust aswell
|
||||
@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);
|
||||
|
||||
if (cartPos == Vec3.ZERO)
|
||||
return;
|
||||
|
||||
for (PoseStack stack : matrixStacks)
|
||||
stack.translate(cartPos.x, cartPos.y, cartPos.z);
|
||||
matrixStack.translate(cartPos.x, cartPos.y, cartPos.z);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
|
@ -176,7 +176,7 @@ public class GantryContraptionEntity extends AbstractContraptionEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks) { }
|
||||
public void applyLocalTransforms(PoseStack matrixStack, float partialTicks) { }
|
||||
|
||||
public void updateClientMotion() {
|
||||
float modifier = movementAxis.getAxisDirection()
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ContraptionMatrices {
|
|||
this.viewProjection.pushPose();
|
||||
transform(this.viewProjection, viewProjection);
|
||||
model.pushPose();
|
||||
entity.doLocalTransforms(partialTicks, new PoseStack[] { model });
|
||||
entity.applyLocalTransforms(model, partialTicks);
|
||||
|
||||
modelViewProjection.pushPose();
|
||||
transform(modelViewProjection, viewProjection);
|
||||
|
|
|
@ -33,52 +33,67 @@ public class BlazeBurnerRenderer extends SafeTileEntityRenderer<BlazeBurnerTileE
|
|||
public BlazeBurnerRenderer(BlockEntityRendererProvider.Context context) {}
|
||||
|
||||
@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) {
|
||||
HeatLevel heatLevel = te.getHeatLevelFromBlock();
|
||||
if (heatLevel == HeatLevel.NONE)
|
||||
return;
|
||||
|
||||
float horizontalAngle = AngleHelper.rad(te.headAngle.getValue(partialTicks));
|
||||
Level level = te.getLevel();
|
||||
int hashCode = te.hashCode();
|
||||
float animation = te.headAnimation.getValue(partialTicks) * .175f;
|
||||
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 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,
|
||||
ContraptionMatrices matrices, MultiBufferSource buffer, LerpedFloat headAngle, boolean conductor) {
|
||||
ContraptionMatrices matrices, MultiBufferSource bufferSource, LerpedFloat headAngle, boolean conductor) {
|
||||
BlockState state = context.state;
|
||||
if (BlazeBurnerBlock.getHeatLevelOf(state) == HeatLevel.KINDLED)
|
||||
state = state.setValue(BlazeBurnerBlock.HEAT_LEVEL, HeatLevel.FADING);
|
||||
float value = AngleHelper.rad(headAngle.getValue(AnimationTickHolder.getPartialTicks(context.world)));
|
||||
renderShared(context.world, buffer, matrices.getModel(), matrices.getViewProjection(), state, value, 0,
|
||||
context.tileData.contains("Goggles"), conductor, context.hashCode());
|
||||
HeatLevel heatLevel = BlazeBurnerBlock.getHeatLevelOf(state);
|
||||
if (heatLevel == HeatLevel.NONE)
|
||||
return;
|
||||
|
||||
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,
|
||||
PoseStack ms, BlockState blockState, float horizontalAngle, float animation, boolean drawGoggles,
|
||||
boolean drawHat, int hashCode) {
|
||||
private static void renderShared(PoseStack ms, @Nullable PoseStack modelTransform, MultiBufferSource bufferSource,
|
||||
Level level, BlockState blockState, HeatLevel heatLevel, float animation, float horizontalAngle,
|
||||
boolean canDrawFlame, boolean drawGoggles, boolean drawHat, int hashCode) {
|
||||
|
||||
boolean blockAbove = animation > 0.125f;
|
||||
HeatLevel heatLevel = BlazeBurnerBlock.getHeatLevelOf(blockState);
|
||||
float time = AnimationTickHolder.getRenderTime(level);
|
||||
float renderTick = time + (hashCode % 13) * 16f;
|
||||
float offsetMult = heatLevel.isAtLeast(HeatLevel.FADING) ? 64 : 16;
|
||||
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 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 cutout = buffer.getBuffer(RenderType.cutoutMipped());
|
||||
VertexConsumer solid = bufferSource.getBuffer(RenderType.solid());
|
||||
VertexConsumer cutout = bufferSource.getBuffer(RenderType.cutoutMipped());
|
||||
|
||||
ms.pushPose();
|
||||
|
||||
if (modelTransform == null && heatLevel.isAtLeast(HeatLevel.FADING) && blockAbove) {
|
||||
if (canDrawFlame && blockAbove) {
|
||||
SpriteShiftEntry spriteShift =
|
||||
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 * spriteWidth / 2;
|
||||
|
||||
draw(CachedBufferer.partial(AllBlockPartials.BLAZE_BURNER_FLAME, blockState)
|
||||
.shiftUVScrolling(spriteShift, (float) uScroll, (float) vScroll), horizontalAngle, modelTransform, ms,
|
||||
cutout);
|
||||
SuperByteBuffer flameBuffer = CachedBufferer.partial(AllBlockPartials.BLAZE_BURNER_FLAME, blockState);
|
||||
if (modelTransform != null)
|
||||
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;
|
||||
if (heatLevel.isAtLeast(HeatLevel.SEETHING))
|
||||
PartialModel blazeModel;
|
||||
if (heatLevel.isAtLeast(HeatLevel.SEETHING)) {
|
||||
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
|
||||
: 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)
|
||||
.translate(0, headY, 0), horizontalAngle, modelTransform, ms, solid);
|
||||
if (drawGoggles) {
|
||||
PartialModel gogglesModel = blazeModel == AllBlockPartials.BLAZE_INERT
|
||||
? AllBlockPartials.BLAZE_GOGGLES_SMALL : AllBlockPartials.BLAZE_GOGGLES;
|
||||
|
||||
if (drawGoggles)
|
||||
draw(CachedBufferer.partial(blazeModel == AllBlockPartials.BLAZE_INERT
|
||||
? AllBlockPartials.BLAZE_GOGGLES_SMALL : AllBlockPartials.BLAZE_GOGGLES, blockState)
|
||||
.translate(0, headY + 8 / 16f, 0), horizontalAngle, modelTransform, ms, solid);
|
||||
SuperByteBuffer gogglesBuffer = CachedBufferer.partial(gogglesModel, blockState);
|
||||
if (modelTransform != null)
|
||||
gogglesBuffer.transform(modelTransform);
|
||||
gogglesBuffer.translate(0, headY + 8 / 16f, 0);
|
||||
draw(gogglesBuffer, horizontalAngle, ms, solid);
|
||||
}
|
||||
|
||||
if (drawHat) {
|
||||
SuperByteBuffer partial = CachedBufferer.partial(AllBlockPartials.TRAIN_HAT, blockState)
|
||||
.translate(0, headY, 0);
|
||||
SuperByteBuffer hatBuffer = CachedBufferer.partial(AllBlockPartials.TRAIN_HAT, blockState);
|
||||
if (modelTransform != null)
|
||||
hatBuffer.transform(modelTransform);
|
||||
hatBuffer.translate(0, headY, 0);
|
||||
if (blazeModel == AllBlockPartials.BLAZE_INERT) {
|
||||
partial.translateY(0.5f)
|
||||
hatBuffer.translateY(0.5f)
|
||||
.centre()
|
||||
.scale(0.75f)
|
||||
.unCentre();
|
||||
} else {
|
||||
partial.translateY(0.75f);
|
||||
hatBuffer.translateY(0.75f);
|
||||
}
|
||||
if (modelTransform != null)
|
||||
partial.transform(modelTransform);
|
||||
partial
|
||||
hatBuffer
|
||||
.rotateCentered(Direction.UP, horizontalAngle + Mth.PI)
|
||||
.translate(0.5f, 0, 0.5f)
|
||||
.light(LightTexture.FULL_BRIGHT)
|
||||
.renderInto(ms, solid);
|
||||
}
|
||||
|
||||
if (heatLevel.isAtLeast(HeatLevel.FADING) || modelTransform != null) {
|
||||
PartialModel rods = heatLevel == HeatLevel.SEETHING ? AllBlockPartials.BLAZE_BURNER_SUPER_RODS
|
||||
if (heatLevel.isAtLeast(HeatLevel.FADING)) {
|
||||
PartialModel rodsModel = heatLevel == HeatLevel.SEETHING ? AllBlockPartials.BLAZE_BURNER_SUPER_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;
|
||||
draw(CachedBufferer.partial(rods, blockState)
|
||||
.translate(0, offset1 + animation + .125f, 0), 0, modelTransform, ms, solid);
|
||||
draw(CachedBufferer.partial(rods2, blockState)
|
||||
.translate(0, offset2 + animation - 3 / 16f, 0), 0, modelTransform, ms, solid);
|
||||
|
||||
SuperByteBuffer rodsBuffer = CachedBufferer.partial(rodsModel, blockState);
|
||||
if (modelTransform != null)
|
||||
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();
|
||||
}
|
||||
|
||||
private static void draw(SuperByteBuffer blazeBuffer, float horizontalAngle, @Nullable PoseStack modelTransform,
|
||||
PoseStack ms, VertexConsumer vb) {
|
||||
if (modelTransform != null)
|
||||
blazeBuffer.transform(modelTransform);
|
||||
blazeBuffer.rotateCentered(Direction.UP, horizontalAngle)
|
||||
private static void draw(SuperByteBuffer buffer, float horizontalAngle, PoseStack ms, VertexConsumer vc) {
|
||||
buffer.rotateCentered(Direction.UP, horizontalAngle)
|
||||
.light(LightTexture.FULL_BRIGHT)
|
||||
.renderInto(ms, vb);
|
||||
.renderInto(ms, vc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,16 +8,15 @@ import net.minecraft.world.level.block.Blocks;
|
|||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
public abstract class SafeTileEntityRenderer<T extends BlockEntity> implements BlockEntityRenderer<T> {
|
||||
|
||||
@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) {
|
||||
if (isInvalid(te))
|
||||
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);
|
||||
|
||||
public boolean isInvalid(T te) {
|
||||
|
|
Loading…
Reference in a new issue