| 1 | package net.minecraft.client.model.animal.parrot;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.EntityModel;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.model.geom.PartPose;
|
| 8 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 9 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 10 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 12 | import net.minecraft.client.renderer.entity.state.ParrotRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 | import net.minecraft.world.entity.animal.parrot.Parrot;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class ParrotModel extends EntityModel<ParrotRenderState> {
|
| 18 | private static final String FEATHER = "feather";
|
| 19 | private final ModelPart body;
|
| 20 | private final ModelPart tail;
|
| 21 | private final ModelPart leftWing;
|
| 22 | private final ModelPart rightWing;
|
| 23 | private final ModelPart head;
|
| 24 | private final ModelPart leftLeg;
|
| 25 | private final ModelPart rightLeg;
|
| 26 |
|
| 27 | public ParrotModel(final ModelPart root) {
|
| 28 | super(root);
|
| 29 | this.body = root.getChild("body");
|
| 30 | this.tail = root.getChild("tail");
|
| 31 | this.leftWing = root.getChild("left_wing");
|
| 32 | this.rightWing = root.getChild("right_wing");
|
| 33 | this.head = root.getChild("head");
|
| 34 | this.leftLeg = root.getChild("left_leg");
|
| 35 | this.rightLeg = root.getChild("right_leg");
|
| 36 | }
|
| 37 |
|
| 38 | public static LayerDefinition createBodyLayer() {
|
| 39 | MeshDefinition mesh = new MeshDefinition();
|
| 40 | PartDefinition root = mesh.getRoot();
|
| 41 | root.addOrReplaceChild(
|
| 42 | "body",
|
| 43 | CubeListBuilder.create().texOffs(2, 8).addBox(-1.5F, 0.0F, -1.5F, 3.0F, 6.0F, 3.0F),
|
| 44 | PartPose.offsetAndRotation(0.0F, 16.5F, -3.0F, 0.4937F, 0.0F, 0.0F)
|
| 45 | );
|
| 46 | root.addOrReplaceChild(
|
| 47 | "tail",
|
| 48 | CubeListBuilder.create().texOffs(22, 1).addBox(-1.5F, -1.0F, -1.0F, 3.0F, 4.0F, 1.0F),
|
| 49 | PartPose.offsetAndRotation(0.0F, 21.07F, 1.16F, 1.015F, 0.0F, 0.0F)
|
| 50 | );
|
| 51 | root.addOrReplaceChild(
|
| 52 | "left_wing",
|
| 53 | CubeListBuilder.create().texOffs(19, 8).addBox(-0.5F, 0.0F, -1.5F, 1.0F, 5.0F, 3.0F),
|
| 54 | PartPose.offsetAndRotation(1.5F, 16.94F, -2.76F, -0.6981F, (float) -Math.PI, 0.0F)
|
| 55 | );
|
| 56 | root.addOrReplaceChild(
|
| 57 | "right_wing",
|
| 58 | CubeListBuilder.create().texOffs(19, 8).addBox(-0.5F, 0.0F, -1.5F, 1.0F, 5.0F, 3.0F),
|
| 59 | PartPose.offsetAndRotation(-1.5F, 16.94F, -2.76F, -0.6981F, (float) -Math.PI, 0.0F)
|
| 60 | );
|
| 61 | PartDefinition head = root.addOrReplaceChild(
|
| 62 | "head", CubeListBuilder.create().texOffs(2, 2).addBox(-1.0F, -1.5F, -1.0F, 2.0F, 3.0F, 2.0F), PartPose.offset(0.0F, 15.69F, -2.76F)
|
| 63 | );
|
| 64 | head.addOrReplaceChild("head2", CubeListBuilder.create().texOffs(10, 0).addBox(-1.0F, -0.5F, -2.0F, 2.0F, 1.0F, 4.0F), PartPose.offset(0.0F, -2.0F, -1.0F));
|
| 65 | head.addOrReplaceChild("beak1", CubeListBuilder.create().texOffs(11, 7).addBox(-0.5F, -1.0F, -0.5F, 1.0F, 2.0F, 1.0F), PartPose.offset(0.0F, -0.5F, -1.5F));
|
| 66 | head.addOrReplaceChild("beak2", CubeListBuilder.create().texOffs(16, 7).addBox(-0.5F, 0.0F, -0.5F, 1.0F, 2.0F, 1.0F), PartPose.offset(0.0F, -1.75F, -2.45F));
|
| 67 | head.addOrReplaceChild(
|
| 68 | "feather",
|
| 69 | CubeListBuilder.create().texOffs(2, 18).addBox(0.0F, -4.0F, -2.0F, 0.0F, 5.0F, 4.0F),
|
| 70 | PartPose.offsetAndRotation(0.0F, -2.15F, 0.15F, -0.2214F, 0.0F, 0.0F)
|
| 71 | );
|
| 72 | CubeListBuilder leg = CubeListBuilder.create().texOffs(14, 18).addBox(-0.5F, 0.0F, -0.5F, 1.0F, 2.0F, 1.0F);
|
| 73 | root.addOrReplaceChild("left_leg", leg, PartPose.offsetAndRotation(1.0F, 22.0F, -1.05F, -0.0299F, 0.0F, 0.0F));
|
| 74 | root.addOrReplaceChild("right_leg", leg, PartPose.offsetAndRotation(-1.0F, 22.0F, -1.05F, -0.0299F, 0.0F, 0.0F));
|
| 75 | return LayerDefinition.create(mesh, 32, 32);
|
| 76 | }
|
| 77 |
|
| 78 | public void setupAnim(final ParrotRenderState state) {
|
| 79 | super.setupAnim(state);
|
| 80 | this.prepare(state.pose);
|
| 81 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 82 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 83 | switch (state.pose) {
|
| 84 | case STANDING:
|
| 85 | this.leftLeg.xRot = this.leftLeg.xRot + Mth.cos(state.walkAnimationPos * 0.6662F) * 1.4F * state.walkAnimationSpeed;
|
| 86 | this.rightLeg.xRot = this.rightLeg.xRot + Mth.cos(state.walkAnimationPos * 0.6662F + (float) Math.PI) * 1.4F * state.walkAnimationSpeed;
|
| 87 | case FLYING:
|
| 88 | case ON_SHOULDER:
|
| 89 | default:
|
| 90 | float bobbingBody = state.flapAngle * 0.3F;
|
| 91 | this.head.y += bobbingBody;
|
| 92 | this.tail.xRot = this.tail.xRot + Mth.cos(state.walkAnimationPos * 0.6662F) * 0.3F * state.walkAnimationSpeed;
|
| 93 | this.tail.y += bobbingBody;
|
| 94 | this.body.y += bobbingBody;
|
| 95 | this.leftWing.zRot = -0.0873F - state.flapAngle;
|
| 96 | this.leftWing.y += bobbingBody;
|
| 97 | this.rightWing.zRot = 0.0873F + state.flapAngle;
|
| 98 | this.rightWing.y += bobbingBody;
|
| 99 | this.leftLeg.y += bobbingBody;
|
| 100 | this.rightLeg.y += bobbingBody;
|
| 101 | case SITTING:
|
| 102 | break;
|
| 103 | case PARTY:
|
| 104 | float xPos = Mth.cos(state.ageInTicks);
|
| 105 | float yPos = Mth.sin(state.ageInTicks);
|
| 106 | this.head.x += xPos;
|
| 107 | this.head.y += yPos;
|
| 108 | this.head.xRot = 0.0F;
|
| 109 | this.head.yRot = 0.0F;
|
| 110 | this.head.zRot = Mth.sin(state.ageInTicks) * 0.4F;
|
| 111 | this.body.x += xPos;
|
| 112 | this.body.y += yPos;
|
| 113 | this.leftWing.zRot = -0.0873F - state.flapAngle;
|
| 114 | this.leftWing.x += xPos;
|
| 115 | this.leftWing.y += yPos;
|
| 116 | this.rightWing.zRot = 0.0873F + state.flapAngle;
|
| 117 | this.rightWing.x += xPos;
|
| 118 | this.rightWing.y += yPos;
|
| 119 | this.tail.x += xPos;
|
| 120 | this.tail.y += yPos;
|
| 121 | }
|
| 122 | }
|
| 123 |
|
| 124 | private void prepare(final ParrotModel.Pose pose) {
|
| 125 | switch (pose) {
|
| 126 | case FLYING:
|
| 127 | this.leftLeg.xRot += (float) (Math.PI * 2.0 / 9.0);
|
| 128 | this.rightLeg.xRot += (float) (Math.PI * 2.0 / 9.0);
|
| 129 | case STANDING:
|
| 130 | case ON_SHOULDER:
|
| 131 | default:
|
| 132 | break;
|
| 133 | case SITTING:
|
| 134 | float sittingYOffset = 1.9F;
|
| 135 | this.head.y += 1.9F;
|
| 136 | this.tail.xRot += (float) (Math.PI / 6);
|
| 137 | this.tail.y += 1.9F;
|
| 138 | this.body.y += 1.9F;
|
| 139 | this.leftWing.zRot = -0.0873F;
|
| 140 | this.leftWing.y += 1.9F;
|
| 141 | this.rightWing.zRot = 0.0873F;
|
| 142 | this.rightWing.y += 1.9F;
|
| 143 | this.leftLeg.y += 1.9F;
|
| 144 | this.rightLeg.y += 1.9F;
|
| 145 | this.leftLeg.xRot += (float) (Math.PI / 2);
|
| 146 | this.rightLeg.xRot += (float) (Math.PI / 2);
|
| 147 | break;
|
| 148 | case PARTY:
|
| 149 | this.leftLeg.zRot = (float) (-Math.PI / 9);
|
| 150 | this.rightLeg.zRot = (float) (Math.PI / 9);
|
| 151 | }
|
| 152 | }
|
| 153 |
|
| 154 | public static ParrotModel.Pose getPose(final Parrot entity) {
|
| 155 | if (entity.isPartyParrot()) {
|
| 156 | return ParrotModel.Pose.PARTY;
|
| 157 | } else if (entity.isInSittingPose()) {
|
| 158 | return ParrotModel.Pose.SITTING;
|
| 159 | } else {
|
| 160 | return entity.isFlying() ? ParrotModel.Pose.FLYING : ParrotModel.Pose.STANDING;
|
| 161 | }
|
| 162 | }
|
| 163 |
|
| 164 | @Environment(EnvType.CLIENT)
|
| 165 | public enum Pose {
|
| 166 | FLYING,
|
| 167 | STANDING,
|
| 168 | SITTING,
|
| 169 | PARTY,
|
| 170 | ON_SHOULDER;
|
| 171 | }
|
| 172 | }
|
| 173 |
|