| 1 | package net.minecraft.client.model.animal.golem;
|
| 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.CubeDeformation;
|
| 9 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 10 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 12 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 13 | import net.minecraft.client.renderer.entity.state.IronGolemRenderState;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class IronGolemModel extends EntityModel<IronGolemRenderState> {
|
| 18 | private final ModelPart head;
|
| 19 | private final ModelPart rightArm;
|
| 20 | private final ModelPart leftArm;
|
| 21 | private final ModelPart rightLeg;
|
| 22 | private final ModelPart leftLeg;
|
| 23 |
|
| 24 | public IronGolemModel(final ModelPart root) {
|
| 25 | super(root);
|
| 26 | this.head = root.getChild("head");
|
| 27 | this.rightArm = root.getChild("right_arm");
|
| 28 | this.leftArm = root.getChild("left_arm");
|
| 29 | this.rightLeg = root.getChild("right_leg");
|
| 30 | this.leftLeg = root.getChild("left_leg");
|
| 31 | }
|
| 32 |
|
| 33 | public static LayerDefinition createBodyLayer() {
|
| 34 | MeshDefinition mesh = new MeshDefinition();
|
| 35 | PartDefinition root = mesh.getRoot();
|
| 36 | root.addOrReplaceChild(
|
| 37 | "head",
|
| 38 | CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -12.0F, -5.5F, 8.0F, 10.0F, 8.0F).texOffs(24, 0).addBox(-1.0F, -5.0F, -7.5F, 2.0F, 4.0F, 2.0F),
|
| 39 | PartPose.offset(0.0F, -7.0F, -2.0F)
|
| 40 | );
|
| 41 | root.addOrReplaceChild(
|
| 42 | "body",
|
| 43 | CubeListBuilder.create()
|
| 44 | .texOffs(0, 40)
|
| 45 | .addBox(-9.0F, -2.0F, -6.0F, 18.0F, 12.0F, 11.0F)
|
| 46 | .texOffs(0, 70)
|
| 47 | .addBox(-4.5F, 10.0F, -3.0F, 9.0F, 5.0F, 6.0F, new CubeDeformation(0.5F)),
|
| 48 | PartPose.offset(0.0F, -7.0F, 0.0F)
|
| 49 | );
|
| 50 | root.addOrReplaceChild(
|
| 51 | "right_arm", CubeListBuilder.create().texOffs(60, 21).addBox(-13.0F, -2.5F, -3.0F, 4.0F, 30.0F, 6.0F), PartPose.offset(0.0F, -7.0F, 0.0F)
|
| 52 | );
|
| 53 | root.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(60, 58).addBox(9.0F, -2.5F, -3.0F, 4.0F, 30.0F, 6.0F), PartPose.offset(0.0F, -7.0F, 0.0F));
|
| 54 | root.addOrReplaceChild(
|
| 55 | "right_leg", CubeListBuilder.create().texOffs(37, 0).addBox(-3.5F, -3.0F, -3.0F, 6.0F, 16.0F, 5.0F), PartPose.offset(-4.0F, 11.0F, 0.0F)
|
| 56 | );
|
| 57 | root.addOrReplaceChild(
|
| 58 | "left_leg", CubeListBuilder.create().texOffs(60, 0).mirror().addBox(-3.5F, -3.0F, -3.0F, 6.0F, 16.0F, 5.0F), PartPose.offset(5.0F, 11.0F, 0.0F)
|
| 59 | );
|
| 60 | return LayerDefinition.create(mesh, 128, 128);
|
| 61 | }
|
| 62 |
|
| 63 | public void setupAnim(final IronGolemRenderState state) {
|
| 64 | super.setupAnim(state);
|
| 65 | float attackTick = state.attackTicksRemaining;
|
| 66 | float animationSpeed = state.walkAnimationSpeed;
|
| 67 | float animationPos = state.walkAnimationPos;
|
| 68 | if (attackTick > 0.0F) {
|
| 69 | this.rightArm.xRot = -2.0F + 1.5F * Mth.triangleWave(attackTick, 10.0F);
|
| 70 | this.leftArm.xRot = -2.0F + 1.5F * Mth.triangleWave(attackTick, 10.0F);
|
| 71 | } else {
|
| 72 | int offerFlowerTick = state.offerFlowerTick;
|
| 73 | if (offerFlowerTick > 0) {
|
| 74 | this.rightArm.xRot = -0.8F + 0.025F * Mth.triangleWave(offerFlowerTick, 70.0F);
|
| 75 | this.leftArm.xRot = 0.0F;
|
| 76 | } else {
|
| 77 | this.rightArm.xRot = (-0.2F + 1.5F * Mth.triangleWave(animationPos, 13.0F)) * animationSpeed;
|
| 78 | this.leftArm.xRot = (-0.2F - 1.5F * Mth.triangleWave(animationPos, 13.0F)) * animationSpeed;
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 83 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 84 | this.rightLeg.xRot = -1.5F * Mth.triangleWave(animationPos, 13.0F) * animationSpeed;
|
| 85 | this.leftLeg.xRot = 1.5F * Mth.triangleWave(animationPos, 13.0F) * animationSpeed;
|
| 86 | this.rightLeg.yRot = 0.0F;
|
| 87 | this.leftLeg.yRot = 0.0F;
|
| 88 | }
|
| 89 |
|
| 90 | public ModelPart getFlowerHoldingArm() {
|
| 91 | return this.rightArm;
|
| 92 | }
|
| 93 | }
|
| 94 |
|