| 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.HumanoidModel;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.model.geom.PartPose;
|
| 8 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 9 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 10 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 12 | import net.minecraft.client.model.player.PlayerModel;
|
| 13 | import net.minecraft.client.renderer.entity.ArmorModelSet;
|
| 14 | import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
|
| 15 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 16 | import net.minecraft.util.Mth;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public abstract class AbstractPiglinModel<S extends HumanoidRenderState> extends HumanoidModel<S> {
|
| 20 | protected static final float ADULT_EAR_ANGLE_IN_DEGREES = 30.0F;
|
| 21 | protected static final float BABY_EAR_ANGLE_IN_DEGREES = 5.0F;
|
| 22 | public final ModelPart rightEar = this.head.getChild("right_ear");
|
| 23 | public final ModelPart leftEar = this.head.getChild("left_ear");
|
| 24 |
|
| 25 | public AbstractPiglinModel(final ModelPart root) {
|
| 26 | super(root, RenderTypes::entityTranslucent);
|
| 27 | }
|
| 28 |
|
| 29 | public static ArmorModelSet<MeshDefinition> createArmorMeshSet(final CubeDeformation innerDeformation, final CubeDeformation outerDeformation) {
|
| 30 | return PlayerModel.createArmorMeshSet(innerDeformation, outerDeformation).map(AbstractPiglinModel::removeEars);
|
| 31 | }
|
| 32 |
|
| 33 | private static MeshDefinition removeEars(final MeshDefinition mesh) {
|
| 34 | PartDefinition root = mesh.getRoot();
|
| 35 | PartDefinition head = root.getChild("head");
|
| 36 | head.addOrReplaceChild("left_ear", CubeListBuilder.create(), PartPose.ZERO);
|
| 37 | head.addOrReplaceChild("right_ear", CubeListBuilder.create(), PartPose.ZERO);
|
| 38 | return mesh;
|
| 39 | }
|
| 40 |
|
| 41 | public static PartDefinition addHead(final CubeDeformation g, final MeshDefinition mesh) {
|
| 42 | PartDefinition root = mesh.getRoot();
|
| 43 | PartDefinition head = root.addOrReplaceChild(
|
| 44 | "head",
|
| 45 | CubeListBuilder.create()
|
| 46 | .texOffs(0, 0)
|
| 47 | .addBox(-5.0F, -8.0F, -4.0F, 10.0F, 8.0F, 8.0F, g)
|
| 48 | .texOffs(31, 1)
|
| 49 | .addBox(-2.0F, -4.0F, -5.0F, 4.0F, 4.0F, 1.0F, g)
|
| 50 | .texOffs(2, 4)
|
| 51 | .addBox(2.0F, -2.0F, -5.0F, 1.0F, 2.0F, 1.0F, g)
|
| 52 | .texOffs(2, 0)
|
| 53 | .addBox(-3.0F, -2.0F, -5.0F, 1.0F, 2.0F, 1.0F, g),
|
| 54 | PartPose.ZERO
|
| 55 | );
|
| 56 | head.addOrReplaceChild(
|
| 57 | "left_ear",
|
| 58 | CubeListBuilder.create().texOffs(51, 6).addBox(0.0F, 0.0F, -2.0F, 1.0F, 5.0F, 4.0F, g),
|
| 59 | PartPose.offsetAndRotation(4.5F, -6.0F, 0.0F, 0.0F, 0.0F, (float) (-Math.PI / 6))
|
| 60 | );
|
| 61 | head.addOrReplaceChild(
|
| 62 | "right_ear",
|
| 63 | CubeListBuilder.create().texOffs(39, 6).addBox(-1.0F, 0.0F, -2.0F, 1.0F, 5.0F, 4.0F, g),
|
| 64 | PartPose.offsetAndRotation(-4.5F, -6.0F, 0.0F, 0.0F, 0.0F, (float) (Math.PI / 6))
|
| 65 | );
|
| 66 | return head;
|
| 67 | }
|
| 68 |
|
| 69 | public static ArmorModelSet<MeshDefinition> createBabyArmorMeshSet(
|
| 70 | final CubeDeformation innerDeformation, final CubeDeformation outerDeformation, final PartPose armOffset
|
| 71 | ) {
|
| 72 | return PlayerModel.createBabyArmorMeshSet(innerDeformation, outerDeformation, armOffset).map(AbstractPiglinModel::removeEars);
|
| 73 | }
|
| 74 |
|
| 75 | @Override
|
| 76 | public void setupAnim(final S state) {
|
| 77 | super.setupAnim(state);
|
| 78 | float animationPos = state.walkAnimationPos;
|
| 79 | float animationSpeed = state.walkAnimationSpeed;
|
| 80 | float defaultAngle = this.getDefaultEarAngleInDegrees() * (float) (Math.PI / 180.0);
|
| 81 | float frequency = state.ageInTicks * 0.1F + animationPos * 0.5F;
|
| 82 | float amplitude = 0.08F + animationSpeed * 0.4F;
|
| 83 | this.leftEar.zRot = -defaultAngle - Mth.cos(frequency * 1.2F) * amplitude;
|
| 84 | this.rightEar.zRot = defaultAngle + Mth.cos(frequency) * amplitude;
|
| 85 | }
|
| 86 |
|
| 87 | protected abstract float getDefaultEarAngleInDegrees();
|
| 88 | }
|
| 89 |
|