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.client.model.geom.PartPose; import net.minecraft.client.model.geom.builders.CubeDeformation; import net.minecraft.client.model.geom.builders.CubeListBuilder; import net.minecraft.client.model.geom.builders.MeshDefinition; import net.minecraft.client.model.geom.builders.PartDefinition; import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.monster.piglin.AbstractPiglin; import net.minecraft.world.entity.monster.piglin.Piglin; import net.minecraft.world.entity.monster.piglin.PiglinArmPose; @Environment(EnvType.CLIENT) public class PiglinModel extends PlayerModel { public final ModelPart rightEar = this.head.getChild("right_ear"); private final ModelPart leftEar = this.head.getChild("left_ear"); private final PartPose bodyDefault = this.body.storePose(); private final PartPose headDefault = this.head.storePose(); private final PartPose leftArmDefault = this.leftArm.storePose(); private final PartPose rightArmDefault = this.rightArm.storePose(); public PiglinModel(ModelPart modelPart) { super(modelPart, false); } public static MeshDefinition createMesh(CubeDeformation cubeDeformation) { MeshDefinition meshDefinition = PlayerModel.createMesh(cubeDeformation, false); PartDefinition partDefinition = meshDefinition.getRoot(); partDefinition.addOrReplaceChild( "body", CubeListBuilder.create().texOffs(16, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, cubeDeformation), PartPose.ZERO ); addHead(cubeDeformation, meshDefinition); partDefinition.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.ZERO); return meshDefinition; } public static void addHead(CubeDeformation cubeDeformation, MeshDefinition mesh) { PartDefinition partDefinition = mesh.getRoot(); PartDefinition partDefinition2 = partDefinition.addOrReplaceChild( "head", CubeListBuilder.create() .texOffs(0, 0) .addBox(-5.0F, -8.0F, -4.0F, 10.0F, 8.0F, 8.0F, cubeDeformation) .texOffs(31, 1) .addBox(-2.0F, -4.0F, -5.0F, 4.0F, 4.0F, 1.0F, cubeDeformation) .texOffs(2, 4) .addBox(2.0F, -2.0F, -5.0F, 1.0F, 2.0F, 1.0F, cubeDeformation) .texOffs(2, 0) .addBox(-3.0F, -2.0F, -5.0F, 1.0F, 2.0F, 1.0F, cubeDeformation), PartPose.ZERO ); partDefinition2.addOrReplaceChild( "left_ear", CubeListBuilder.create().texOffs(51, 6).addBox(0.0F, 0.0F, -2.0F, 1.0F, 5.0F, 4.0F, cubeDeformation), PartPose.offsetAndRotation(4.5F, -6.0F, 0.0F, 0.0F, 0.0F, (float) (-Math.PI / 6)) ); partDefinition2.addOrReplaceChild( "right_ear", CubeListBuilder.create().texOffs(39, 6).addBox(-1.0F, 0.0F, -2.0F, 1.0F, 5.0F, 4.0F, cubeDeformation), PartPose.offsetAndRotation(-4.5F, -6.0F, 0.0F, 0.0F, 0.0F, (float) (Math.PI / 6)) ); } /** * Sets this entity's model rotation angles */ public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.body.loadPose(this.bodyDefault); this.head.loadPose(this.headDefault); this.leftArm.loadPose(this.leftArmDefault); this.rightArm.loadPose(this.rightArmDefault); super.setupAnim(entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch); float f = (float) (Math.PI / 6); float g = ageInTicks * 0.1F + limbSwing * 0.5F; float h = 0.08F + limbSwingAmount * 0.4F; this.leftEar.zRot = (float) (-Math.PI / 6) - Mth.cos(g * 1.2F) * h; this.rightEar.zRot = (float) (Math.PI / 6) + Mth.cos(g) * h; if (entity instanceof AbstractPiglin abstractPiglin) { PiglinArmPose piglinArmPose = abstractPiglin.getArmPose(); if (piglinArmPose == PiglinArmPose.DANCING) { float i = ageInTicks / 60.0F; this.rightEar.zRot = (float) (Math.PI / 6) + (float) (Math.PI / 180.0) * Mth.sin(i * 30.0F) * 10.0F; this.leftEar.zRot = (float) (-Math.PI / 6) - (float) (Math.PI / 180.0) * Mth.cos(i * 30.0F) * 10.0F; this.head.x = Mth.sin(i * 10.0F); this.head.y = Mth.sin(i * 40.0F) + 0.4F; this.rightArm.zRot = (float) (Math.PI / 180.0) * (70.0F + Mth.cos(i * 40.0F) * 10.0F); this.leftArm.zRot = this.rightArm.zRot * -1.0F; this.rightArm.y = Mth.sin(i * 40.0F) * 0.5F + 1.5F; this.leftArm.y = Mth.sin(i * 40.0F) * 0.5F + 1.5F; this.body.y = Mth.sin(i * 40.0F) * 0.35F; } else if (piglinArmPose == PiglinArmPose.ATTACKING_WITH_MELEE_WEAPON && this.attackTime == 0.0F) { this.holdWeaponHigh(entity); } else if (piglinArmPose == PiglinArmPose.CROSSBOW_HOLD) { AnimationUtils.animateCrossbowHold(this.rightArm, this.leftArm, this.head, !entity.isLeftHanded()); } else if (piglinArmPose == PiglinArmPose.CROSSBOW_CHARGE) { AnimationUtils.animateCrossbowCharge(this.rightArm, this.leftArm, entity, !entity.isLeftHanded()); } else if (piglinArmPose == PiglinArmPose.ADMIRING_ITEM) { this.head.xRot = 0.5F; this.head.yRot = 0.0F; if (entity.isLeftHanded()) { this.rightArm.yRot = -0.5F; this.rightArm.xRot = -0.9F; } else { this.leftArm.yRot = 0.5F; this.leftArm.xRot = -0.9F; } } } else if (entity.getType() == EntityType.ZOMBIFIED_PIGLIN) { AnimationUtils.animateZombieArms(this.leftArm, this.rightArm, entity.isAggressive(), this.attackTime, ageInTicks); } this.leftPants.copyFrom(this.leftLeg); this.rightPants.copyFrom(this.rightLeg); this.leftSleeve.copyFrom(this.leftArm); this.rightSleeve.copyFrom(this.rightArm); this.jacket.copyFrom(this.body); this.hat.copyFrom(this.head); } protected void setupAttackAnimation(T livingEntity, float ageInTicks) { if (this.attackTime > 0.0F && livingEntity instanceof Piglin && ((Piglin)livingEntity).getArmPose() == PiglinArmPose.ATTACKING_WITH_MELEE_WEAPON) { AnimationUtils.swingWeaponDown(this.rightArm, this.leftArm, livingEntity, this.attackTime, ageInTicks); } else { super.setupAttackAnimation(livingEntity, ageInTicks); } } private void holdWeaponHigh(T mob) { if (mob.isLeftHanded()) { this.leftArm.xRot = -1.8F; } else { this.rightArm.xRot = -1.8F; } } }