| 1 | package net.minecraft.client.model.monster.piglin;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.AnimationUtils;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.renderer.entity.state.PiglinRenderState;
|
| 8 | import net.minecraft.util.Mth;
|
| 9 | import net.minecraft.world.entity.HumanoidArm;
|
| 10 | import net.minecraft.world.entity.monster.piglin.PiglinArmPose;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public abstract class PiglinModel extends AbstractPiglinModel<PiglinRenderState> {
|
| 14 | public PiglinModel(final ModelPart root) {
|
| 15 | super(root);
|
| 16 | }
|
| 17 |
|
| 18 | public void setupAnim(final PiglinRenderState state) {
|
| 19 | super.setupAnim(state);
|
| 20 | float defaultAngle = (float) (Math.PI / 6);
|
| 21 | float swingAnimation = state.swingAnimation;
|
| 22 | PiglinArmPose pose = state.armPose;
|
| 23 | if (pose == PiglinArmPose.DANCING) {
|
| 24 | float dancePos = state.ageInTicks / 60.0F;
|
| 25 | this.rightEar.zRot = (float) (Math.PI / 6) + (float) (Math.PI / 180.0) * Mth.sin(dancePos * 30.0F) * 10.0F;
|
| 26 | this.leftEar.zRot = (float) (-Math.PI / 6) - (float) (Math.PI / 180.0) * Mth.cos(dancePos * 30.0F) * 10.0F;
|
| 27 | this.head.x = this.head.x + Mth.sin(dancePos * 10.0F);
|
| 28 | this.head.y = this.head.y + (Mth.sin(dancePos * 40.0F) + 0.4F);
|
| 29 | this.rightArm.zRot = (float) (Math.PI / 180.0) * (70.0F + Mth.cos(dancePos * 40.0F) * 10.0F);
|
| 30 | this.leftArm.zRot = this.rightArm.zRot * -1.0F;
|
| 31 | this.rightArm.y = this.rightArm.y + (Mth.sin(dancePos * 40.0F) * 0.5F - 0.5F);
|
| 32 | this.leftArm.y = this.leftArm.y + (Mth.sin(dancePos * 40.0F) * 0.5F + 0.5F);
|
| 33 | this.body.y = this.body.y + Mth.sin(dancePos * 40.0F) * 0.35F;
|
| 34 | } else if (pose == PiglinArmPose.ATTACKING_WITH_MELEE_WEAPON && swingAnimation == 0.0F) {
|
| 35 | this.holdWeaponHigh(state);
|
| 36 | } else if (pose == PiglinArmPose.CROSSBOW_HOLD) {
|
| 37 | AnimationUtils.animateCrossbowHold(this.rightArm, this.leftArm, this.head, state.mainArm == HumanoidArm.RIGHT);
|
| 38 | } else if (pose == PiglinArmPose.CROSSBOW_CHARGE) {
|
| 39 | AnimationUtils.animateCrossbowCharge(this.rightArm, this.leftArm, state.maxCrossbowChageDuration, state.ticksUsingItem, state.mainArm == HumanoidArm.RIGHT);
|
| 40 | } else if (pose == PiglinArmPose.ADMIRING_ITEM) {
|
| 41 | this.head.xRot = 0.5F;
|
| 42 | this.head.yRot = 0.0F;
|
| 43 | if (state.mainArm == HumanoidArm.LEFT) {
|
| 44 | this.rightArm.yRot = -0.5F;
|
| 45 | this.rightArm.xRot = -0.9F;
|
| 46 | } else {
|
| 47 | this.leftArm.yRot = 0.5F;
|
| 48 | this.leftArm.xRot = -0.9F;
|
| 49 | }
|
| 50 | }
|
| 51 | }
|
| 52 |
|
| 53 | protected void setupAttackAnimation(final PiglinRenderState state) {
|
| 54 | float swingAnimation = state.swingAnimation;
|
| 55 | if (swingAnimation > 0.0F && state.armPose == PiglinArmPose.ATTACKING_WITH_MELEE_WEAPON) {
|
| 56 | AnimationUtils.swingWeaponDown(this.rightArm, this.leftArm, state.mainArm, swingAnimation, state.ageInTicks);
|
| 57 | } else {
|
| 58 | super.setupAttackAnimation(state);
|
| 59 | }
|
| 60 | }
|
| 61 |
|
| 62 | private void holdWeaponHigh(final PiglinRenderState state) {
|
| 63 | if (state.mainArm == HumanoidArm.LEFT) {
|
| 64 | this.leftArm.xRot = -1.8F;
|
| 65 | } else {
|
| 66 | this.rightArm.xRot = -1.8F;
|
| 67 | }
|
| 68 | }
|
| 69 | }
|
| 70 |
|