Do a bit of cleanup

This commit is contained in:
Sollace 2022-10-06 20:41:56 +02:00
parent 046d70008d
commit d9ec01a479
4 changed files with 40 additions and 27 deletions

View file

@ -23,7 +23,10 @@ import net.minecraft.util.math.Vec3f;
public class PlayerPoser {
public static final PlayerPoser INSTANCE = new PlayerPoser();
public void applyPosing(MatrixStack matrices, PlayerEntity player, BipedEntityModel<?> model) {
private static final float HEAD_NOD_DURATION = 15F;
private static final float HEAD_NOD_GAP = HEAD_NOD_DURATION / 3F;
public void applyPosing(MatrixStack matrices, PlayerEntity player, BipedEntityModel<?> model, Context context) {
Pony pony = Pony.of(player);
float progress = pony.getAnimationProgress(MinecraftClient.getInstance().getTickDelta());
Animation animation = pony.getAnimation();
@ -34,34 +37,25 @@ public class PlayerPoser {
ModelPart head = model.getHead();
if (glasses.hasCustomName() && "Cool Shades".equals(glasses.getName().getString())) {
float duration = 15F;
float gap = duration / 3F;
float prog = (player.age % duration);
if (prog <= gap) {
prog = 0;
} else if (prog > (duration - gap)) {
prog = 1;
} else {
prog = (prog - gap) / (duration - 2 * gap);
}
prog *= Math.PI;
float bop = (float)Math.sin(prog) * 3F;
final float bop = AnimationUtil.beat(player.age, HEAD_NOD_DURATION, HEAD_NOD_GAP) * 3F;
head.pitch += bop / 10F;
if (isPony) {
model.leftArm.roll -= bop / 50F;
model.rightArm.roll += bop / 50F;
float beat30 = bop / 30F;
model.leftLeg.roll -= bop / 30F;
model.leftLeg.pitch -= bop / 20F;
model.rightLeg.roll += bop / 30F;
model.rightLeg.pitch += bop / 20F;
if (isPony) {
float beat50 = bop / 50F;
float beat20 = bop / 20F;
model.leftArm.roll -= beat50;
model.rightArm.roll += beat50;
model.leftLeg.roll -= beat30;
model.leftLeg.pitch -= beat20;
model.rightLeg.roll += beat30;
model.rightLeg.pitch += beat20;
} else {
model.leftArm.roll -= bop / 30F;
model.rightArm.roll += bop / 30F;
model.leftArm.roll -= beat30;
model.rightArm.roll += beat30;
}
}
@ -251,4 +245,10 @@ public class PlayerPoser {
return sound;
}
}
public enum Context {
FIRST_PERSON_LEFT,
FIRST_PERSON_RIGHT,
THIRD_PERSON
}
}

View file

@ -37,7 +37,7 @@ abstract class MixinLivingEntityRenderer<T extends LivingEntity, M extends Entit
int light,
CallbackInfo into) {
if (entity instanceof PlayerEntity player) {
PlayerPoser.INSTANCE.applyPosing(matrices, player, (BipedEntityModel<?>)getModel());
PlayerPoser.INSTANCE.applyPosing(matrices, player, (BipedEntityModel<?>)getModel(), PlayerPoser.Context.THIRD_PERSON);
}
if (entity instanceof MobEntity mob) {
AnimalPoser.INSTANCE.applyPosing(matrices, mob, getModel());

View file

@ -51,6 +51,6 @@ abstract class MixinPlayerEntityRenderer extends LivingEntityRenderer<AbstractCl
target = "Lnet/minecraft/client/render/entity/model/PlayerEntityModel;setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
shift = Shift.AFTER))
private void onPoseArm(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, ModelPart arm, ModelPart sleeve, CallbackInfo info) {
PlayerPoser.INSTANCE.applyPosing(matrices, player, getModel());
PlayerPoser.INSTANCE.applyPosing(matrices, player, getModel(), arm == getModel().leftArm ? PlayerPoser.Context.FIRST_PERSON_LEFT : PlayerPoser.Context.FIRST_PERSON_RIGHT);
}
}

View file

@ -16,4 +16,17 @@ public interface AnimationUtil {
static float seeSitSaw(float progress, float clipRatio) {
return Math.min(1, seesaw(progress) * clipRatio);
}
/**
* Generates a beat at regular intervals
*/
static float beat(float progress, float duration, float gap) {
progress %= duration;
if (progress <= gap || progress > (duration - gap)) {
return 0;
}
return (float)Math.sin(((progress - gap) / (duration - 2 * gap)) * Math.PI);
}
}