| 1 | package net.minecraft.client.model.monster.illager;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.model.AnimationUtils;
|
| 7 | import net.minecraft.client.model.ArmedModel;
|
| 8 | import net.minecraft.client.model.EntityModel;
|
| 9 | import net.minecraft.client.model.HeadedModel;
|
| 10 | import net.minecraft.client.model.geom.ModelPart;
|
| 11 | import net.minecraft.client.model.geom.PartPose;
|
| 12 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 13 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 14 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 15 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 16 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 17 | import net.minecraft.client.renderer.entity.state.IllagerRenderState;
|
| 18 | import net.minecraft.util.Mth;
|
| 19 | import net.minecraft.world.entity.HumanoidArm;
|
| 20 | import net.minecraft.world.entity.monster.illager.AbstractIllager.IllagerArmPose;
|
| 21 |
|
| 22 | @Environment(EnvType.CLIENT)
|
| 23 | public class IllagerModel<S extends IllagerRenderState> extends EntityModel<S> implements ArmedModel<S>, HeadedModel {
|
| 24 | private final ModelPart head;
|
| 25 | private final ModelPart hat;
|
| 26 | private final ModelPart arms;
|
| 27 | private final ModelPart leftLeg;
|
| 28 | private final ModelPart rightLeg;
|
| 29 | private final ModelPart rightArm;
|
| 30 | private final ModelPart leftArm;
|
| 31 |
|
| 32 | public IllagerModel(final ModelPart root) {
|
| 33 | super(root);
|
| 34 | this.head = root.getChild("head");
|
| 35 | this.hat = this.head.getChild("hat");
|
| 36 | this.hat.visible = false;
|
| 37 | this.arms = root.getChild("arms");
|
| 38 | this.leftLeg = root.getChild("left_leg");
|
| 39 | this.rightLeg = root.getChild("right_leg");
|
| 40 | this.leftArm = root.getChild("left_arm");
|
| 41 | this.rightArm = root.getChild("right_arm");
|
| 42 | }
|
| 43 |
|
| 44 | public static LayerDefinition createBodyLayer() {
|
| 45 | MeshDefinition mesh = new MeshDefinition();
|
| 46 | PartDefinition root = mesh.getRoot();
|
| 47 | PartDefinition head = root.addOrReplaceChild(
|
| 48 | "head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -10.0F, -4.0F, 8.0F, 10.0F, 8.0F), PartPose.offset(0.0F, 0.0F, 0.0F)
|
| 49 | );
|
| 50 | head.addOrReplaceChild(
|
| 51 | "hat", CubeListBuilder.create().texOffs(32, 0).addBox(-4.0F, -10.0F, -4.0F, 8.0F, 12.0F, 8.0F, new CubeDeformation(0.45F)), PartPose.ZERO
|
| 52 | );
|
| 53 | head.addOrReplaceChild("nose", CubeListBuilder.create().texOffs(24, 0).addBox(-1.0F, -1.0F, -6.0F, 2.0F, 4.0F, 2.0F), PartPose.offset(0.0F, -2.0F, 0.0F));
|
| 54 | root.addOrReplaceChild(
|
| 55 | "body",
|
| 56 | CubeListBuilder.create()
|
| 57 | .texOffs(16, 20)
|
| 58 | .addBox(-4.0F, 0.0F, -3.0F, 8.0F, 12.0F, 6.0F)
|
| 59 | .texOffs(0, 38)
|
| 60 | .addBox(-4.0F, 0.0F, -3.0F, 8.0F, 20.0F, 6.0F, new CubeDeformation(0.5F)),
|
| 61 | PartPose.offset(0.0F, 0.0F, 0.0F)
|
| 62 | );
|
| 63 | PartDefinition arms = root.addOrReplaceChild(
|
| 64 | "arms",
|
| 65 | CubeListBuilder.create().texOffs(44, 22).addBox(-8.0F, -2.0F, -2.0F, 4.0F, 8.0F, 4.0F).texOffs(40, 38).addBox(-4.0F, 2.0F, -2.0F, 8.0F, 4.0F, 4.0F),
|
| 66 | PartPose.offsetAndRotation(0.0F, 3.0F, -1.0F, -0.75F, 0.0F, 0.0F)
|
| 67 | );
|
| 68 | arms.addOrReplaceChild("left_shoulder", CubeListBuilder.create().texOffs(44, 22).mirror().addBox(4.0F, -2.0F, -2.0F, 4.0F, 8.0F, 4.0F), PartPose.ZERO);
|
| 69 | root.addOrReplaceChild(
|
| 70 | "right_leg", CubeListBuilder.create().texOffs(0, 22).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(-2.0F, 12.0F, 0.0F)
|
| 71 | );
|
| 72 | root.addOrReplaceChild(
|
| 73 | "left_leg", CubeListBuilder.create().texOffs(0, 22).mirror().addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(2.0F, 12.0F, 0.0F)
|
| 74 | );
|
| 75 | root.addOrReplaceChild(
|
| 76 | "right_arm", CubeListBuilder.create().texOffs(40, 46).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(-5.0F, 2.0F, 0.0F)
|
| 77 | );
|
| 78 | root.addOrReplaceChild(
|
| 79 | "left_arm", CubeListBuilder.create().texOffs(40, 46).mirror().addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(5.0F, 2.0F, 0.0F)
|
| 80 | );
|
| 81 | return LayerDefinition.create(mesh, 64, 64);
|
| 82 | }
|
| 83 |
|
| 84 | public void setupAnim(final S state) {
|
| 85 | super.setupAnim(state);
|
| 86 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 87 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 88 | if (state.isRiding) {
|
| 89 | this.rightArm.xRot = (float) (-Math.PI / 5);
|
| 90 | this.rightArm.yRot = 0.0F;
|
| 91 | this.rightArm.zRot = 0.0F;
|
| 92 | this.leftArm.xRot = (float) (-Math.PI / 5);
|
| 93 | this.leftArm.yRot = 0.0F;
|
| 94 | this.leftArm.zRot = 0.0F;
|
| 95 | this.rightLeg.xRot = -1.4137167F;
|
| 96 | this.rightLeg.yRot = (float) (Math.PI / 10);
|
| 97 | this.rightLeg.zRot = 0.07853982F;
|
| 98 | this.leftLeg.xRot = -1.4137167F;
|
| 99 | this.leftLeg.yRot = (float) (-Math.PI / 10);
|
| 100 | this.leftLeg.zRot = -0.07853982F;
|
| 101 | } else {
|
| 102 | float animationSpeed = state.walkAnimationSpeed;
|
| 103 | float animationPos = state.walkAnimationPos;
|
| 104 | this.rightArm.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 2.0F * animationSpeed * 0.5F;
|
| 105 | this.rightArm.yRot = 0.0F;
|
| 106 | this.rightArm.zRot = 0.0F;
|
| 107 | this.leftArm.xRot = Mth.cos(animationPos * 0.6662F) * 2.0F * animationSpeed * 0.5F;
|
| 108 | this.leftArm.yRot = 0.0F;
|
| 109 | this.leftArm.zRot = 0.0F;
|
| 110 | this.rightLeg.xRot = Mth.cos(animationPos * 0.6662F) * 1.4F * animationSpeed * 0.5F;
|
| 111 | this.rightLeg.yRot = 0.0F;
|
| 112 | this.rightLeg.zRot = 0.0F;
|
| 113 | this.leftLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 1.4F * animationSpeed * 0.5F;
|
| 114 | this.leftLeg.yRot = 0.0F;
|
| 115 | this.leftLeg.zRot = 0.0F;
|
| 116 | }
|
| 117 |
|
| 118 | IllagerArmPose pose = state.armPose;
|
| 119 | if (pose == IllagerArmPose.ATTACKING) {
|
| 120 | if (state.getMainHandItemState().isEmpty()) {
|
| 121 | AnimationUtils.animateZombieArms(this.leftArm, this.rightArm, true, state);
|
| 122 | AnimationUtils.bobArms(this.rightArm, this.leftArm, state.ageInTicks);
|
| 123 | } else {
|
| 124 | AnimationUtils.swingWeaponDown(this.rightArm, this.leftArm, state.mainArm, state.swingAnimation, state.ageInTicks);
|
| 125 | }
|
| 126 | } else if (pose == IllagerArmPose.SPELLCASTING) {
|
| 127 | this.rightArm.z = 0.0F;
|
| 128 | this.rightArm.x = -5.0F;
|
| 129 | this.leftArm.z = 0.0F;
|
| 130 | this.leftArm.x = 5.0F;
|
| 131 | this.rightArm.xRot = Mth.cos(state.ageInTicks * 0.6662F) * 0.25F;
|
| 132 | this.leftArm.xRot = Mth.cos(state.ageInTicks * 0.6662F) * 0.25F;
|
| 133 | this.rightArm.zRot = (float) (Math.PI * 3.0 / 4.0);
|
| 134 | this.leftArm.zRot = (float) (-Math.PI * 3.0 / 4.0);
|
| 135 | this.rightArm.yRot = 0.0F;
|
| 136 | this.leftArm.yRot = 0.0F;
|
| 137 | } else if (pose == IllagerArmPose.BOW_AND_ARROW) {
|
| 138 | this.rightArm.yRot = -0.1F + this.head.yRot;
|
| 139 | this.rightArm.xRot = (float) (-Math.PI / 2) + this.head.xRot;
|
| 140 | this.leftArm.xRot = -0.9424779F + this.head.xRot;
|
| 141 | this.leftArm.yRot = this.head.yRot - 0.4F;
|
| 142 | this.leftArm.zRot = (float) (Math.PI / 2);
|
| 143 | } else if (pose == IllagerArmPose.CROSSBOW_HOLD) {
|
| 144 | AnimationUtils.animateCrossbowHold(this.rightArm, this.leftArm, this.head, true);
|
| 145 | } else if (pose == IllagerArmPose.CROSSBOW_CHARGE) {
|
| 146 | AnimationUtils.animateCrossbowCharge(this.rightArm, this.leftArm, state.maxCrossbowChargeDuration, state.ticksUsingItem, true);
|
| 147 | } else if (pose == IllagerArmPose.CELEBRATING) {
|
| 148 | this.rightArm.z = 0.0F;
|
| 149 | this.rightArm.x = -5.0F;
|
| 150 | this.rightArm.xRot = Mth.cos(state.ageInTicks * 0.6662F) * 0.05F;
|
| 151 | this.rightArm.zRot = 2.670354F;
|
| 152 | this.rightArm.yRot = 0.0F;
|
| 153 | this.leftArm.z = 0.0F;
|
| 154 | this.leftArm.x = 5.0F;
|
| 155 | this.leftArm.xRot = Mth.cos(state.ageInTicks * 0.6662F) * 0.05F;
|
| 156 | this.leftArm.zRot = (float) (-Math.PI * 3.0 / 4.0);
|
| 157 | this.leftArm.yRot = 0.0F;
|
| 158 | }
|
| 159 |
|
| 160 | boolean crossedArms = pose == IllagerArmPose.CROSSED;
|
| 161 | this.arms.visible = crossedArms;
|
| 162 | this.leftArm.visible = !crossedArms;
|
| 163 | this.rightArm.visible = !crossedArms;
|
| 164 | }
|
| 165 |
|
| 166 | private ModelPart getArm(final HumanoidArm arm) {
|
| 167 | return arm == HumanoidArm.LEFT ? this.leftArm : this.rightArm;
|
| 168 | }
|
| 169 |
|
| 170 | public ModelPart getHat() {
|
| 171 | return this.hat;
|
| 172 | }
|
| 173 |
|
| 174 | @Override
|
| 175 | public ModelPart getHead() {
|
| 176 | return this.head;
|
| 177 | }
|
| 178 |
|
| 179 | public void translateToHand(final IllagerRenderState state, final HumanoidArm arm, final PoseStack poseStack) {
|
| 180 | this.root.translateAndRotate(poseStack);
|
| 181 | this.getArm(arm).translateAndRotate(poseStack);
|
| 182 | }
|
| 183 | }
|
| 184 |
|