minecraft-src/net/minecraft/client/model/AnimationUtils.java
2025-07-04 02:00:41 +03:00

78 lines
3.2 KiB
Java

package net.minecraft.client.model;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.HumanoidArm;
@Environment(EnvType.CLIENT)
public class AnimationUtils {
public static void animateCrossbowHold(ModelPart rightArm, ModelPart leftArm, ModelPart head, boolean rightHanded) {
ModelPart modelPart = rightHanded ? rightArm : leftArm;
ModelPart modelPart2 = rightHanded ? leftArm : rightArm;
modelPart.yRot = (rightHanded ? -0.3F : 0.3F) + head.yRot;
modelPart2.yRot = (rightHanded ? 0.6F : -0.6F) + head.yRot;
modelPart.xRot = (float) (-Math.PI / 2) + head.xRot + 0.1F;
modelPart2.xRot = -1.5F + head.xRot;
}
public static void animateCrossbowCharge(ModelPart modelPart, ModelPart modelPart2, float f, int i, boolean bl) {
ModelPart modelPart3 = bl ? modelPart : modelPart2;
ModelPart modelPart4 = bl ? modelPart2 : modelPart;
modelPart3.yRot = bl ? -0.8F : 0.8F;
modelPart3.xRot = -0.97079635F;
modelPart4.xRot = modelPart3.xRot;
float g = Mth.clamp((float)i, 0.0F, f);
float h = g / f;
modelPart4.yRot = Mth.lerp(h, 0.4F, 0.85F) * (bl ? 1 : -1);
modelPart4.xRot = Mth.lerp(h, modelPart4.xRot, (float) (-Math.PI / 2));
}
public static void swingWeaponDown(ModelPart modelPart, ModelPart modelPart2, HumanoidArm humanoidArm, float f, float g) {
float h = Mth.sin(f * (float) Math.PI);
float i = Mth.sin((1.0F - (1.0F - f) * (1.0F - f)) * (float) Math.PI);
modelPart.zRot = 0.0F;
modelPart2.zRot = 0.0F;
modelPart.yRot = (float) (Math.PI / 20);
modelPart2.yRot = (float) (-Math.PI / 20);
if (humanoidArm == HumanoidArm.RIGHT) {
modelPart.xRot = -1.8849558F + Mth.cos(g * 0.09F) * 0.15F;
modelPart2.xRot = -0.0F + Mth.cos(g * 0.19F) * 0.5F;
modelPart.xRot += h * 2.2F - i * 0.4F;
modelPart2.xRot += h * 1.2F - i * 0.4F;
} else {
modelPart.xRot = -0.0F + Mth.cos(g * 0.19F) * 0.5F;
modelPart2.xRot = -1.8849558F + Mth.cos(g * 0.09F) * 0.15F;
modelPart.xRot += h * 1.2F - i * 0.4F;
modelPart2.xRot += h * 2.2F - i * 0.4F;
}
bobArms(modelPart, modelPart2, g);
}
public static void bobModelPart(ModelPart modelPart, float ageInTicks, float multiplier) {
modelPart.zRot = modelPart.zRot + multiplier * (Mth.cos(ageInTicks * 0.09F) * 0.05F + 0.05F);
modelPart.xRot = modelPart.xRot + multiplier * (Mth.sin(ageInTicks * 0.067F) * 0.05F);
}
public static void bobArms(ModelPart rightArm, ModelPart leftArm, float ageInTicks) {
bobModelPart(rightArm, ageInTicks, 1.0F);
bobModelPart(leftArm, ageInTicks, -1.0F);
}
public static void animateZombieArms(ModelPart leftArm, ModelPart rightArm, boolean isAggressive, float attackTime, float ageInTicks) {
float f = Mth.sin(attackTime * (float) Math.PI);
float g = Mth.sin((1.0F - (1.0F - attackTime) * (1.0F - attackTime)) * (float) Math.PI);
rightArm.zRot = 0.0F;
leftArm.zRot = 0.0F;
rightArm.yRot = -(0.1F - f * 0.6F);
leftArm.yRot = 0.1F - f * 0.6F;
float h = (float) -Math.PI / (isAggressive ? 1.5F : 2.25F);
rightArm.xRot = h;
leftArm.xRot = h;
rightArm.xRot += f * 1.2F - g * 0.4F;
leftArm.xRot += f * 1.2F - g * 0.4F;
bobArms(rightArm, leftArm, ageInTicks);
}
}