| 1 | package net.minecraft.client.model.monster.ravager;
|
| 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.RavagerRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class RavagerModel extends EntityModel<RavagerRenderState> {
|
| 17 | private final ModelPart head;
|
| 18 | private final ModelPart mouth;
|
| 19 | private final ModelPart rightHindLeg;
|
| 20 | private final ModelPart leftHindLeg;
|
| 21 | private final ModelPart rightFrontLeg;
|
| 22 | private final ModelPart leftFrontLeg;
|
| 23 | private final ModelPart neck;
|
| 24 |
|
| 25 | public RavagerModel(final ModelPart root) {
|
| 26 | super(root);
|
| 27 | this.neck = root.getChild("neck");
|
| 28 | this.head = this.neck.getChild("head");
|
| 29 | this.mouth = this.head.getChild("mouth");
|
| 30 | this.rightHindLeg = root.getChild("right_hind_leg");
|
| 31 | this.leftHindLeg = root.getChild("left_hind_leg");
|
| 32 | this.rightFrontLeg = root.getChild("right_front_leg");
|
| 33 | this.leftFrontLeg = root.getChild("left_front_leg");
|
| 34 | }
|
| 35 |
|
| 36 | public static LayerDefinition createBodyLayer() {
|
| 37 | MeshDefinition mesh = new MeshDefinition();
|
| 38 | PartDefinition root = mesh.getRoot();
|
| 39 | int legSize = 16;
|
| 40 | PartDefinition neck = root.addOrReplaceChild(
|
| 41 | "neck", CubeListBuilder.create().texOffs(68, 73).addBox(-5.0F, -1.0F, -18.0F, 10.0F, 10.0F, 18.0F), PartPose.offset(0.0F, -7.0F, 5.5F)
|
| 42 | );
|
| 43 | PartDefinition head = neck.addOrReplaceChild(
|
| 44 | "head",
|
| 45 | CubeListBuilder.create().texOffs(0, 0).addBox(-8.0F, -20.0F, -14.0F, 16.0F, 20.0F, 16.0F).texOffs(0, 0).addBox(-2.0F, -6.0F, -18.0F, 4.0F, 8.0F, 4.0F),
|
| 46 | PartPose.offset(0.0F, 16.0F, -17.0F)
|
| 47 | );
|
| 48 | head.addOrReplaceChild(
|
| 49 | "right_horn",
|
| 50 | CubeListBuilder.create().texOffs(74, 55).addBox(0.0F, -14.0F, -2.0F, 2.0F, 14.0F, 4.0F),
|
| 51 | PartPose.offsetAndRotation(-10.0F, -14.0F, -8.0F, 1.0995574F, 0.0F, 0.0F)
|
| 52 | );
|
| 53 | head.addOrReplaceChild(
|
| 54 | "left_horn",
|
| 55 | CubeListBuilder.create().texOffs(74, 55).mirror().addBox(0.0F, -14.0F, -2.0F, 2.0F, 14.0F, 4.0F),
|
| 56 | PartPose.offsetAndRotation(8.0F, -14.0F, -8.0F, 1.0995574F, 0.0F, 0.0F)
|
| 57 | );
|
| 58 | head.addOrReplaceChild("mouth", CubeListBuilder.create().texOffs(0, 36).addBox(-8.0F, 0.0F, -16.0F, 16.0F, 3.0F, 16.0F), PartPose.offset(0.0F, -2.0F, 2.0F));
|
| 59 | root.addOrReplaceChild(
|
| 60 | "body",
|
| 61 | CubeListBuilder.create().texOffs(0, 55).addBox(-7.0F, -10.0F, -7.0F, 14.0F, 16.0F, 20.0F).texOffs(0, 91).addBox(-6.0F, 6.0F, -7.0F, 12.0F, 13.0F, 18.0F),
|
| 62 | PartPose.offsetAndRotation(0.0F, 1.0F, 2.0F, (float) (Math.PI / 2), 0.0F, 0.0F)
|
| 63 | );
|
| 64 | root.addOrReplaceChild(
|
| 65 | "right_hind_leg", CubeListBuilder.create().texOffs(96, 0).addBox(-4.0F, 0.0F, -4.0F, 8.0F, 37.0F, 8.0F), PartPose.offset(-8.0F, -13.0F, 18.0F)
|
| 66 | );
|
| 67 | root.addOrReplaceChild(
|
| 68 | "left_hind_leg", CubeListBuilder.create().texOffs(96, 0).mirror().addBox(-4.0F, 0.0F, -4.0F, 8.0F, 37.0F, 8.0F), PartPose.offset(8.0F, -13.0F, 18.0F)
|
| 69 | );
|
| 70 | root.addOrReplaceChild(
|
| 71 | "right_front_leg", CubeListBuilder.create().texOffs(64, 0).addBox(-4.0F, 0.0F, -4.0F, 8.0F, 37.0F, 8.0F), PartPose.offset(-8.0F, -13.0F, -5.0F)
|
| 72 | );
|
| 73 | root.addOrReplaceChild(
|
| 74 | "left_front_leg", CubeListBuilder.create().texOffs(64, 0).mirror().addBox(-4.0F, 0.0F, -4.0F, 8.0F, 37.0F, 8.0F), PartPose.offset(8.0F, -13.0F, -5.0F)
|
| 75 | );
|
| 76 | return LayerDefinition.create(mesh, 128, 128);
|
| 77 | }
|
| 78 |
|
| 79 | public void setupAnim(final RavagerRenderState state) {
|
| 80 | super.setupAnim(state);
|
| 81 | float stunnedTick = state.stunnedTicksRemaining;
|
| 82 | float attackTick = state.attackTicksRemaining;
|
| 83 | int attackTime = 10;
|
| 84 | if (attackTick > 0.0F) {
|
| 85 | float headAnim = Mth.triangleWave(attackTick, 10.0F);
|
| 86 | float scaled = (1.0F + headAnim) * 0.5F;
|
| 87 | float headPos = scaled * scaled * scaled * 12.0F;
|
| 88 | float yOffset = headPos * Mth.sin(this.neck.xRot);
|
| 89 | this.neck.z = -6.5F + headPos;
|
| 90 | this.neck.y = -7.0F - yOffset;
|
| 91 | if (attackTick > 5.0F) {
|
| 92 | this.mouth.xRot = Mth.sin((-4.0F + attackTick) / 4.0F) * (float) Math.PI * 0.4F;
|
| 93 | } else {
|
| 94 | this.mouth.xRot = (float) (Math.PI / 20) * Mth.sin((float) Math.PI * attackTick / 10.0F);
|
| 95 | }
|
| 96 | } else {
|
| 97 | float headPos = -1.0F;
|
| 98 | float yOffset = -1.0F * Mth.sin(this.neck.xRot);
|
| 99 | this.neck.x = 0.0F;
|
| 100 | this.neck.y = -7.0F - yOffset;
|
| 101 | this.neck.z = 5.5F;
|
| 102 | boolean isStunned = stunnedTick > 0.0F;
|
| 103 | this.neck.xRot = isStunned ? 0.21991149F : 0.0F;
|
| 104 | this.mouth.xRot = (float) Math.PI * (isStunned ? 0.05F : 0.01F);
|
| 105 | if (isStunned) {
|
| 106 | double speed = stunnedTick / 40.0;
|
| 107 | this.neck.x = (float)Math.sin(speed * 10.0) * 3.0F;
|
| 108 | } else if (state.roarAnimation > 0.0) {
|
| 109 | float mouthAnim = Mth.sin(state.roarAnimation * (float) Math.PI * 0.25F);
|
| 110 | this.mouth.xRot = (float) (Math.PI / 2) * mouthAnim;
|
| 111 | }
|
| 112 | }
|
| 113 |
|
| 114 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 115 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 116 | float animationPos = state.walkAnimationPos;
|
| 117 | float legRot = 0.4F * state.walkAnimationSpeed;
|
| 118 | this.rightHindLeg.xRot = Mth.cos(animationPos * 0.6662F) * legRot;
|
| 119 | this.leftHindLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * legRot;
|
| 120 | this.rightFrontLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * legRot;
|
| 121 | this.leftFrontLeg.xRot = Mth.cos(animationPos * 0.6662F) * legRot;
|
| 122 | }
|
| 123 | }
|
| 124 |
|