| 1 | package net.minecraft.client.model.monster.warden;
|
| 2 |
|
| 3 | import java.util.Set;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.animation.KeyframeAnimation;
|
| 7 | import net.minecraft.client.animation.definitions.WardenAnimation;
|
| 8 | import net.minecraft.client.model.EntityModel;
|
| 9 | import net.minecraft.client.model.geom.ModelPart;
|
| 10 | import net.minecraft.client.model.geom.PartPose;
|
| 11 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 12 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 13 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 14 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 15 | import net.minecraft.client.renderer.entity.state.WardenRenderState;
|
| 16 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 17 | import net.minecraft.util.Mth;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class WardenModel extends EntityModel<WardenRenderState> {
|
| 21 | private static final float DEFAULT_ARM_X_Y = 13.0F;
|
| 22 | private static final float DEFAULT_ARM_Z = 1.0F;
|
| 23 | protected final ModelPart bone;
|
| 24 | protected final ModelPart body;
|
| 25 | protected final ModelPart head;
|
| 26 | protected final ModelPart rightTendril;
|
| 27 | protected final ModelPart leftTendril;
|
| 28 | protected final ModelPart leftLeg;
|
| 29 | protected final ModelPart leftArm;
|
| 30 | protected final ModelPart leftRibcage;
|
| 31 | protected final ModelPart rightArm;
|
| 32 | protected final ModelPart rightLeg;
|
| 33 | protected final ModelPart rightRibcage;
|
| 34 | private final KeyframeAnimation attackAnimation;
|
| 35 | private final KeyframeAnimation sonicBoomAnimation;
|
| 36 | private final KeyframeAnimation diggingAnimation;
|
| 37 | private final KeyframeAnimation emergeAnimation;
|
| 38 | private final KeyframeAnimation roarAnimation;
|
| 39 | private final KeyframeAnimation sniffAnimation;
|
| 40 |
|
| 41 | public WardenModel(final ModelPart root) {
|
| 42 | super(root, RenderTypes::entityCutout);
|
| 43 | this.bone = root.getChild("bone");
|
| 44 | this.body = this.bone.getChild("body");
|
| 45 | this.head = this.body.getChild("head");
|
| 46 | this.rightLeg = this.bone.getChild("right_leg");
|
| 47 | this.leftLeg = this.bone.getChild("left_leg");
|
| 48 | this.rightArm = this.body.getChild("right_arm");
|
| 49 | this.leftArm = this.body.getChild("left_arm");
|
| 50 | this.rightTendril = this.head.getChild("right_tendril");
|
| 51 | this.leftTendril = this.head.getChild("left_tendril");
|
| 52 | this.rightRibcage = this.body.getChild("right_ribcage");
|
| 53 | this.leftRibcage = this.body.getChild("left_ribcage");
|
| 54 | this.attackAnimation = WardenAnimation.WARDEN_ATTACK.bake(root);
|
| 55 | this.sonicBoomAnimation = WardenAnimation.WARDEN_SONIC_BOOM.bake(root);
|
| 56 | this.diggingAnimation = WardenAnimation.WARDEN_DIG.bake(root);
|
| 57 | this.emergeAnimation = WardenAnimation.WARDEN_EMERGE.bake(root);
|
| 58 | this.roarAnimation = WardenAnimation.WARDEN_ROAR.bake(root);
|
| 59 | this.sniffAnimation = WardenAnimation.WARDEN_SNIFF.bake(root);
|
| 60 | }
|
| 61 |
|
| 62 | public static LayerDefinition createBodyLayer() {
|
| 63 | MeshDefinition mesh = new MeshDefinition();
|
| 64 | PartDefinition root = mesh.getRoot();
|
| 65 | PartDefinition bone = root.addOrReplaceChild("bone", CubeListBuilder.create(), PartPose.offset(0.0F, 24.0F, 0.0F));
|
| 66 | PartDefinition body = bone.addOrReplaceChild(
|
| 67 | "body", CubeListBuilder.create().texOffs(0, 0).addBox(-9.0F, -13.0F, -4.0F, 18.0F, 21.0F, 11.0F), PartPose.offset(0.0F, -21.0F, 0.0F)
|
| 68 | );
|
| 69 | body.addOrReplaceChild(
|
| 70 | "right_ribcage", CubeListBuilder.create().texOffs(90, 11).addBox(-2.0F, -11.0F, -0.1F, 9.0F, 21.0F, 0.0F), PartPose.offset(-7.0F, -2.0F, -4.0F)
|
| 71 | );
|
| 72 | body.addOrReplaceChild(
|
| 73 | "left_ribcage",
|
| 74 | CubeListBuilder.create().texOffs(90, 11).mirror().addBox(-7.0F, -11.0F, -0.1F, 9.0F, 21.0F, 0.0F).mirror(false),
|
| 75 | PartPose.offset(7.0F, -2.0F, -4.0F)
|
| 76 | );
|
| 77 | PartDefinition head = body.addOrReplaceChild(
|
| 78 | "head", CubeListBuilder.create().texOffs(0, 32).addBox(-8.0F, -16.0F, -5.0F, 16.0F, 16.0F, 10.0F), PartPose.offset(0.0F, -13.0F, 0.0F)
|
| 79 | );
|
| 80 | head.addOrReplaceChild(
|
| 81 | "right_tendril", CubeListBuilder.create().texOffs(52, 32).addBox(-16.0F, -13.0F, 0.0F, 16.0F, 16.0F, 0.0F), PartPose.offset(-8.0F, -12.0F, 0.0F)
|
| 82 | );
|
| 83 | head.addOrReplaceChild(
|
| 84 | "left_tendril", CubeListBuilder.create().texOffs(58, 0).addBox(0.0F, -13.0F, 0.0F, 16.0F, 16.0F, 0.0F), PartPose.offset(8.0F, -12.0F, 0.0F)
|
| 85 | );
|
| 86 | body.addOrReplaceChild(
|
| 87 | "right_arm", CubeListBuilder.create().texOffs(44, 50).addBox(-4.0F, 0.0F, -4.0F, 8.0F, 28.0F, 8.0F), PartPose.offset(-13.0F, -13.0F, 1.0F)
|
| 88 | );
|
| 89 | body.addOrReplaceChild(
|
| 90 | "left_arm", CubeListBuilder.create().texOffs(0, 58).addBox(-4.0F, 0.0F, -4.0F, 8.0F, 28.0F, 8.0F), PartPose.offset(13.0F, -13.0F, 1.0F)
|
| 91 | );
|
| 92 | bone.addOrReplaceChild(
|
| 93 | "right_leg", CubeListBuilder.create().texOffs(76, 48).addBox(-3.1F, 0.0F, -3.0F, 6.0F, 13.0F, 6.0F), PartPose.offset(-5.9F, -13.0F, 0.0F)
|
| 94 | );
|
| 95 | bone.addOrReplaceChild(
|
| 96 | "left_leg", CubeListBuilder.create().texOffs(76, 76).addBox(-2.9F, 0.0F, -3.0F, 6.0F, 13.0F, 6.0F), PartPose.offset(5.9F, -13.0F, 0.0F)
|
| 97 | );
|
| 98 | return LayerDefinition.create(mesh, 128, 128);
|
| 99 | }
|
| 100 |
|
| 101 | public static LayerDefinition createTendrilsLayer() {
|
| 102 | return createBodyLayer().apply(mesh -> {
|
| 103 | mesh.getRoot().retainExactParts(Set.of("left_tendril", "right_tendril"));
|
| 104 | return mesh;
|
| 105 | });
|
| 106 | }
|
| 107 |
|
| 108 | public static LayerDefinition createHeartLayer() {
|
| 109 | return createBodyLayer().apply(mesh -> {
|
| 110 | mesh.getRoot().retainExactParts(Set.of("body"));
|
| 111 | return mesh;
|
| 112 | });
|
| 113 | }
|
| 114 |
|
| 115 | public static LayerDefinition createBioluminescentLayer() {
|
| 116 | return createBodyLayer().apply(mesh -> {
|
| 117 | mesh.getRoot().retainExactParts(Set.of("head", "left_arm", "right_arm", "left_leg", "right_leg"));
|
| 118 | return mesh;
|
| 119 | });
|
| 120 | }
|
| 121 |
|
| 122 | public static LayerDefinition createPulsatingSpotsLayer() {
|
| 123 | return createBodyLayer().apply(mesh -> {
|
| 124 | mesh.getRoot().retainExactParts(Set.of("body", "head", "left_arm", "right_arm", "left_leg", "right_leg"));
|
| 125 | return mesh;
|
| 126 | });
|
| 127 | }
|
| 128 |
|
| 129 | public void setupAnim(final WardenRenderState state) {
|
| 130 | super.setupAnim(state);
|
| 131 | this.animateHeadLookTarget(state.yRot, state.xRot);
|
| 132 | this.animateWalk(state.walkAnimationPos, state.walkAnimationSpeed);
|
| 133 | this.animateIdlePose(state.ageInTicks);
|
| 134 | this.animateTendrils(state, state.ageInTicks);
|
| 135 | this.attackAnimation.apply(state.attackAnimationState, state.ageInTicks);
|
| 136 | this.sonicBoomAnimation.apply(state.sonicBoomAnimationState, state.ageInTicks);
|
| 137 | this.diggingAnimation.apply(state.diggingAnimationState, state.ageInTicks);
|
| 138 | this.emergeAnimation.apply(state.emergeAnimationState, state.ageInTicks);
|
| 139 | this.roarAnimation.apply(state.roarAnimationState, state.ageInTicks);
|
| 140 | this.sniffAnimation.apply(state.sniffAnimationState, state.ageInTicks);
|
| 141 | }
|
| 142 |
|
| 143 | private void animateHeadLookTarget(final float yRot, final float xRot) {
|
| 144 | this.head.xRot = xRot * (float) (Math.PI / 180.0);
|
| 145 | this.head.yRot = yRot * (float) (Math.PI / 180.0);
|
| 146 | }
|
| 147 |
|
| 148 | private void animateIdlePose(final float ageInTicks) {
|
| 149 | float scaledAge = ageInTicks * 0.1F;
|
| 150 | float wobbleCosine = Mth.cos(scaledAge);
|
| 151 | float wobbleSine = Mth.sin(scaledAge);
|
| 152 | this.head.zRot += 0.06F * wobbleCosine;
|
| 153 | this.head.xRot += 0.06F * wobbleSine;
|
| 154 | this.body.zRot += 0.025F * wobbleSine;
|
| 155 | this.body.xRot += 0.025F * wobbleCosine;
|
| 156 | }
|
| 157 |
|
| 158 | private void animateWalk(final float animationPos, final float animationSpeed) {
|
| 159 | float speedModifier = Math.min(0.5F, 3.0F * animationSpeed);
|
| 160 | float adjustedPos = animationPos * 0.8662F;
|
| 161 | float adjustedPosCosine = Mth.cos(adjustedPos);
|
| 162 | float adjustedPosSine = Mth.sin(adjustedPos);
|
| 163 | float speedModifierWithMin = Math.min(0.35F, speedModifier);
|
| 164 | this.head.zRot += 0.3F * adjustedPosSine * speedModifier;
|
| 165 | this.head.xRot = this.head.xRot + 1.2F * Mth.cos(adjustedPos + (float) (Math.PI / 2)) * speedModifierWithMin;
|
| 166 | this.body.zRot = 0.1F * adjustedPosSine * speedModifier;
|
| 167 | this.body.xRot = 1.0F * adjustedPosCosine * speedModifierWithMin;
|
| 168 | this.leftLeg.xRot = 1.0F * adjustedPosCosine * speedModifier;
|
| 169 | this.rightLeg.xRot = 1.0F * Mth.cos(adjustedPos + (float) Math.PI) * speedModifier;
|
| 170 | this.leftArm.xRot = -(0.8F * adjustedPosCosine * speedModifier);
|
| 171 | this.leftArm.zRot = 0.0F;
|
| 172 | this.rightArm.xRot = -(0.8F * adjustedPosSine * speedModifier);
|
| 173 | this.rightArm.zRot = 0.0F;
|
| 174 | this.resetArmPoses();
|
| 175 | }
|
| 176 |
|
| 177 | private void resetArmPoses() {
|
| 178 | this.leftArm.yRot = 0.0F;
|
| 179 | this.leftArm.z = 1.0F;
|
| 180 | this.leftArm.x = 13.0F;
|
| 181 | this.leftArm.y = -13.0F;
|
| 182 | this.rightArm.yRot = 0.0F;
|
| 183 | this.rightArm.z = 1.0F;
|
| 184 | this.rightArm.x = -13.0F;
|
| 185 | this.rightArm.y = -13.0F;
|
| 186 | }
|
| 187 |
|
| 188 | private void animateTendrils(final WardenRenderState state, final float ageInTicks) {
|
| 189 | float tendrilXRot = state.tendrilAnimation * (float)(Math.cos(ageInTicks * 2.25) * Math.PI * 0.1F);
|
| 190 | this.leftTendril.xRot = tendrilXRot;
|
| 191 | this.rightTendril.xRot = -tendrilXRot;
|
| 192 | }
|
| 193 | }
|
| 194 |
|