Improve hot air balloon animations and fix formatting

This commit is contained in:
Sollace 2024-03-28 13:48:12 +00:00
parent 3ff7466a54
commit 101a560a01
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -29,12 +29,8 @@ public class AirBalloonEntityModel extends EntityModel<AirBalloonEntity> {
if (isBurner || isBalloon) {
ModelPart part = root.getChild(isBalloon ? "canopy" : "burner");
ropes = List.of(
part.getChild("rope_a"),
part.getChild("rope_b"),
part.getChild("rope_c"),
part.getChild("rope_d")
);
ropes = List.of(part.getChild("rope_a"), part.getChild("rope_b"), part.getChild("rope_c"),
part.getChild("rope_d"));
} else {
ropes = List.of();
}
@ -64,8 +60,8 @@ public class AirBalloonEntityModel extends EntityModel<AirBalloonEntity> {
ModelPartData burner = root.addChild("burner", ModelPartBuilder.create().uv(8, 0).cuboid(-6, -47, -6, 11, 15, 11, Dilation.NONE), ModelTransform.pivot(0, 24, 0));
burner.addChild("rope_d", ModelPartBuilder.create().cuboid(-2, -68, 0, 2, 68, 2, Dilation.NONE), ModelTransform.of(-5, -46, -6, 0.7854F, 0, -0.7854F));
burner.addChild("rope_c", ModelPartBuilder.create().cuboid(-2, -68, 0, 2, 68, 2, Dilation.NONE), ModelTransform.of(-4, -44, 3, -0.7854F, 0, -0.7854F));
burner.addChild("rope_b", ModelPartBuilder.create().cuboid(-2, -68, 0, 2, 68, 2, Dilation.NONE), ModelTransform.of( 5, -46, 1, -0.7854F, 0, 0.7854F));
burner.addChild("rope_a", ModelPartBuilder.create().cuboid(-2, -68, 0, 2, 68, 2, Dilation.NONE), ModelTransform.of( 5, -45, -6, 0.7854F, 0, 0.7854F));
burner.addChild("rope_b", ModelPartBuilder.create().cuboid(-2, -68, 0, 2, 68, 2, Dilation.NONE), ModelTransform.of(5, -46, 1, -0.7854F, 0, 0.7854F));
burner.addChild("rope_a", ModelPartBuilder.create().cuboid(-2, -68, 0, 2, 68, 2, Dilation.NONE), ModelTransform.of(5, -45, -6, 0.7854F, 0, 0.7854F));
return TexturedModelData.of(modelData, 64, 128);
}
@ -81,18 +77,36 @@ public class AirBalloonEntityModel extends EntityModel<AirBalloonEntity> {
}
@Override
public void setAngles(AirBalloonEntity entity, float tickDelta, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
public void setAngles(AirBalloonEntity entity, float tickDelta, float limbSwingAmount, float ageInTicks,
float netHeadYaw, float headPitch) {
inflation = entity.getInflation(tickDelta);
root.roll = MathHelper.sin((float)(entity.getX() - entity.prevX));
root.pitch = MathHelper.sin((float)(entity.getZ() - entity.prevZ));
if (isBurner || isBalloon) {
root.roll = MathHelper.clamp((float) (entity.getX() - entity.lastRenderX), -0.5F, 0.5F);
root.pitch = MathHelper.clamp((float) (entity.getZ() - entity.lastRenderZ), -0.5F, 0.5F);
if (entity.isLeashed()) {
root.roll *= -1;
root.pitch *= -1;
}
} else {
root.pitch = 0;
root.roll = 0;
}
for (ModelPart rope : ropes) {
rope.resetTransform();
}
if (isBurner) {
boolean lifted = inflation > 0.8F;
root.pivotY = 32 * (1 - inflation);
root.pivotX = inflation * MathHelper.sin(limbSwingAmount + entity.age / 5F) / 4F;
ropes.forEach(rope -> rope.visible = lifted);
ropes.forEach(rope -> {
rope.visible = lifted;
rope.pitch *= 0.125;
rope.roll *= 0.125;
});
}
if (isBalloon) {
root.pivotY = 0;
root.pivotX = inflation * MathHelper.cos(limbSwingAmount + entity.age / 5F) / 4F;
@ -102,6 +116,30 @@ public class AirBalloonEntityModel extends EntityModel<AirBalloonEntity> {
ropes.forEach(ModelPart::resetTransform);
}
}
for (int i = 0; i < ropes.size(); i++) {
ModelPart rope = ropes.get(i);
float rollRatio = root.roll / rope.roll;
float pitchRatio = root.pitch / rope.pitch;
rope.pivotY -= 5F * rollRatio;
rope.pivotY -= 5F * pitchRatio;
if (i == 0 || i == 3) {
rope.pivotZ -= 5 * pitchRatio;
}
if (i == 2 || i == 1) {
rope.pivotZ += 5 * pitchRatio;
}
if (i == 2 || i == 3) {
rope.pivotX -= 5 * rollRatio;
}
if (i == 0 || i == 1) {
rope.pivotX += 5 * rollRatio;
}
}
}
@Override