| 1 | package net.minecraft.client.model;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 5 | import java.util.Map;
|
| 6 | import java.util.Set;
|
| 7 | import java.util.function.Function;
|
| 8 | import net.fabricmc.api.EnvType;
|
| 9 | import net.fabricmc.api.Environment;
|
| 10 | import net.minecraft.client.model.effects.SpearAnimations;
|
| 11 | import net.minecraft.client.model.geom.ModelPart;
|
| 12 | import net.minecraft.client.model.geom.PartPose;
|
| 13 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 14 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 15 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 16 | import net.minecraft.client.model.geom.builders.MeshTransformer;
|
| 17 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 18 | import net.minecraft.client.renderer.entity.ArmorModelSet;
|
| 19 | import net.minecraft.client.renderer.entity.state.ArmedEntityRenderState;
|
| 20 | import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
|
| 21 | import net.minecraft.client.renderer.rendertype.RenderType;
|
| 22 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 23 | import net.minecraft.resources.Identifier;
|
| 24 | import net.minecraft.util.Ease;
|
| 25 | import net.minecraft.util.Mth;
|
| 26 | import net.minecraft.world.InteractionHand;
|
| 27 | import net.minecraft.world.entity.EquipmentSlot;
|
| 28 | import net.minecraft.world.entity.HumanoidArm;
|
| 29 | import net.minecraft.world.entity.LivingEntity.SwingDescription;
|
| 30 | import net.minecraft.world.item.ItemStack;
|
| 31 |
|
| 32 | @Environment(EnvType.CLIENT)
|
| 33 | public class HumanoidModel<T extends HumanoidRenderState> extends EntityModel<T> implements ArmedModel<T>, HeadedModel {
|
| 34 | public static final MeshTransformer BABY_TRANSFORMER = new BabyModelTransform(true, 16.0F, 0.0F, 2.0F, 2.0F, 24.0F, Set.of("head"));
|
| 35 | public static final float OVERLAY_SCALE = 0.25F;
|
| 36 | public static final float HAT_OVERLAY_SCALE = 0.5F;
|
| 37 | public static final float LEGGINGS_OVERLAY_SCALE = -0.1F;
|
| 38 | private static final float DUCK_WALK_ROTATION = 0.005F;
|
| 39 | private static final float SPYGLASS_ARM_ROT_Y = (float) (Math.PI / 12);
|
| 40 | private static final float SPYGLASS_ARM_ROT_X = 1.9198622F;
|
| 41 | private static final float SPYGLASS_ARM_CROUCH_ROT_X = (float) (Math.PI / 12);
|
| 42 | private static final float HIGHEST_SHIELD_BLOCKING_ANGLE = (float) (-Math.PI * 4.0 / 9.0);
|
| 43 | private static final float LOWEST_SHIELD_BLOCKING_ANGLE = 0.43633232F;
|
| 44 | private static final float HORIZONTAL_SHIELD_MOVEMENT_LIMIT = (float) (Math.PI / 6);
|
| 45 | public static final float TOOT_HORN_XROT_BASE = 1.4835298F;
|
| 46 | public static final float TOOT_HORN_YROT_BASE = (float) (Math.PI / 6);
|
| 47 | protected static final Map<EquipmentSlot, Set<String>> ADULT_ARMOR_PARTS_PER_SLOT = Maps.newEnumMap(
|
| 48 | Map.of(
|
| 49 | EquipmentSlot.HEAD,
|
| 50 | Set.of("head"),
|
| 51 | EquipmentSlot.CHEST,
|
| 52 | Set.of("body", "left_arm", "right_arm"),
|
| 53 | EquipmentSlot.LEGS,
|
| 54 | Set.of("left_leg", "right_leg", "body"),
|
| 55 | EquipmentSlot.FEET,
|
| 56 | Set.of("left_leg", "right_leg")
|
| 57 | )
|
| 58 | );
|
| 59 | protected static final Map<EquipmentSlot, Set<String>> BABY_ARMOR_PARTS_PER_SLOT = Maps.newEnumMap(
|
| 60 | Map.of(
|
| 61 | EquipmentSlot.HEAD,
|
| 62 | Set.of("head"),
|
| 63 | EquipmentSlot.CHEST,
|
| 64 | Set.of("body", "left_arm", "right_arm"),
|
| 65 | EquipmentSlot.LEGS,
|
| 66 | Set.of("left_leg", "right_leg", "waist"),
|
| 67 | EquipmentSlot.FEET,
|
| 68 | Set.of("left_foot", "right_foot")
|
| 69 | )
|
| 70 | );
|
| 71 | public final ModelPart head;
|
| 72 | public final ModelPart hat;
|
| 73 | public final ModelPart body;
|
| 74 | public final ModelPart rightArm;
|
| 75 | public final ModelPart leftArm;
|
| 76 | public final ModelPart rightLeg;
|
| 77 | public final ModelPart leftLeg;
|
| 78 |
|
| 79 | public HumanoidModel(final ModelPart root) {
|
| 80 | this(root, RenderTypes::entityCutout);
|
| 81 | }
|
| 82 |
|
| 83 | public HumanoidModel(final ModelPart root, final Function<Identifier, RenderType> renderType) {
|
| 84 | super(root, renderType);
|
| 85 | this.head = root.getChild("head");
|
| 86 | this.hat = this.head.getChild("hat");
|
| 87 | this.body = root.getChild("body");
|
| 88 | this.rightArm = root.getChild("right_arm");
|
| 89 | this.leftArm = root.getChild("left_arm");
|
| 90 | this.rightLeg = root.getChild("right_leg");
|
| 91 | this.leftLeg = root.getChild("left_leg");
|
| 92 | }
|
| 93 |
|
| 94 | public static MeshDefinition createMesh(final CubeDeformation g, final float yOffset) {
|
| 95 | MeshDefinition mesh = new MeshDefinition();
|
| 96 | PartDefinition root = mesh.getRoot();
|
| 97 | PartDefinition head = root.addOrReplaceChild(
|
| 98 | "head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, g), PartPose.offset(0.0F, 0.0F + yOffset, 0.0F)
|
| 99 | );
|
| 100 | head.addOrReplaceChild("hat", CubeListBuilder.create().texOffs(32, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, g.extend(0.5F)), PartPose.ZERO);
|
| 101 | root.addOrReplaceChild(
|
| 102 | "body", CubeListBuilder.create().texOffs(16, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, g), PartPose.offset(0.0F, 0.0F + yOffset, 0.0F)
|
| 103 | );
|
| 104 | root.addOrReplaceChild(
|
| 105 | "right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, g), PartPose.offset(-5.0F, 2.0F + yOffset, 0.0F)
|
| 106 | );
|
| 107 | root.addOrReplaceChild(
|
| 108 | "left_arm", CubeListBuilder.create().texOffs(40, 16).mirror().addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, g), PartPose.offset(5.0F, 2.0F + yOffset, 0.0F)
|
| 109 | );
|
| 110 | root.addOrReplaceChild(
|
| 111 | "right_leg", CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, g), PartPose.offset(-1.9F, 12.0F + yOffset, 0.0F)
|
| 112 | );
|
| 113 | root.addOrReplaceChild(
|
| 114 | "left_leg", CubeListBuilder.create().texOffs(0, 16).mirror().addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, g), PartPose.offset(1.9F, 12.0F + yOffset, 0.0F)
|
| 115 | );
|
| 116 | return mesh;
|
| 117 | }
|
| 118 |
|
| 119 | public static ArmorModelSet<MeshDefinition> createArmorMeshSet(final CubeDeformation innerDeformation, final CubeDeformation outerDeformation) {
|
| 120 | return createArmorMeshSet(HumanoidModel::createBaseArmorMesh, ADULT_ARMOR_PARTS_PER_SLOT, innerDeformation, outerDeformation);
|
| 121 | }
|
| 122 |
|
| 123 | public static ArmorModelSet<MeshDefinition> createBabyArmorMeshSet(
|
| 124 | final CubeDeformation innerDeformation, final CubeDeformation outerDeformation, final PartPose armOffset
|
| 125 | ) {
|
| 126 | return createArmorMeshSet(cube -> createBabyArmorMesh(cube, armOffset), BABY_ARMOR_PARTS_PER_SLOT, innerDeformation, outerDeformation);
|
| 127 | }
|
| 128 |
|
| 129 | protected static ArmorModelSet<MeshDefinition> createArmorMeshSet(
|
| 130 | final Function<CubeDeformation, MeshDefinition> baseFactory,
|
| 131 | final Map<EquipmentSlot, Set<String>> partsPerSlot,
|
| 132 | final CubeDeformation innerDeformation,
|
| 133 | final CubeDeformation outerDeformation
|
| 134 | ) {
|
| 135 | MeshDefinition head = baseFactory.apply(outerDeformation);
|
| 136 | head.getRoot().retainPartsAndChildren(partsPerSlot.get(EquipmentSlot.HEAD));
|
| 137 | MeshDefinition chest = baseFactory.apply(outerDeformation);
|
| 138 | chest.getRoot().retainExactParts(partsPerSlot.get(EquipmentSlot.CHEST));
|
| 139 | MeshDefinition legs = baseFactory.apply(innerDeformation);
|
| 140 | legs.getRoot().retainExactParts(partsPerSlot.get(EquipmentSlot.LEGS));
|
| 141 | MeshDefinition feet = baseFactory.apply(outerDeformation);
|
| 142 | feet.getRoot().retainExactParts(partsPerSlot.get(EquipmentSlot.FEET));
|
| 143 | return new ArmorModelSet<>(head, chest, legs, feet);
|
| 144 | }
|
| 145 |
|
| 146 | private static MeshDefinition createBaseArmorMesh(final CubeDeformation g) {
|
| 147 | MeshDefinition mesh = createMesh(g, 0.0F);
|
| 148 | PartDefinition root = mesh.getRoot();
|
| 149 | root.addOrReplaceChild(
|
| 150 | "right_leg", CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, g.extend(-0.1F)), PartPose.offset(-1.9F, 12.0F, 0.0F)
|
| 151 | );
|
| 152 | root.addOrReplaceChild(
|
| 153 | "left_leg",
|
| 154 | CubeListBuilder.create().texOffs(0, 16).mirror().addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, g.extend(-0.1F)),
|
| 155 | PartPose.offset(1.9F, 12.0F, 0.0F)
|
| 156 | );
|
| 157 | return mesh;
|
| 158 | }
|
| 159 |
|
| 160 | private static MeshDefinition createBabyArmorMesh(final CubeDeformation g, final PartPose armOffset) {
|
| 161 | MeshDefinition mesh = new MeshDefinition();
|
| 162 | PartDefinition root = mesh.getRoot();
|
| 163 | PartDefinition head = root.addOrReplaceChild(
|
| 164 | "head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.5F, -7.0F, -4.5F, 9.0F, 8.0F, 8.0F, g), PartPose.offset(0.0F, 15.0F, 0.0F)
|
| 165 | );
|
| 166 | root.addOrReplaceChild("body", CubeListBuilder.create().texOffs(0, 17).addBox(-3.0F, -3.0F, -1.5F, 6.0F, 5.0F, 3.0F, g), PartPose.offset(0.0F, 18.0F, 0.0F));
|
| 167 | root.addOrReplaceChild(
|
| 168 | "waist", CubeListBuilder.create().texOffs(0, 36).addBox(-3.0F, -1.2F, -1.49F, 5.9F, 2.0F, 2.9F, g.extend(-0.1F)), PartPose.offset(0.0F, 19.0F, 0.0F)
|
| 169 | );
|
| 170 | root.addOrReplaceChild(
|
| 171 | "right_arm",
|
| 172 | CubeListBuilder.create().texOffs(30, 25).addBox(-1.0F, 0.0F, -1.53F, 2.0F, 5.0F, 3.0F, g),
|
| 173 | PartPose.offset(-3.5F - armOffset.x(), 15.5F + armOffset.y(), 0.0F + armOffset.z())
|
| 174 | );
|
| 175 | root.addOrReplaceChild(
|
| 176 | "left_arm",
|
| 177 | CubeListBuilder.create().texOffs(30, 17).addBox(-1.0F, 0.0F, -1.53F, 2.0F, 5.0F, 3.0F, g),
|
| 178 | PartPose.offset(3.5F + armOffset.x(), 15.5F + armOffset.y(), 0.0F + armOffset.z())
|
| 179 | );
|
| 180 | root.addOrReplaceChild(
|
| 181 | "inner_body", CubeListBuilder.create().texOffs(0, 17).addBox(-3.0F, -3.0F, -1.5F, 6.0F, 5.0F, 3.0F, g), PartPose.offset(0.0F, 18.0F, 0.0F)
|
| 182 | );
|
| 183 | PartDefinition rightLeg = root.addOrReplaceChild(
|
| 184 | "left_leg", CubeListBuilder.create().texOffs(18, 24).addBox(-2.0F, -0.2F, -2.0F, 3.0F, 4.0F, 3.0F, g.extend(-0.1F)), PartPose.offset(1.5F, 20.0F, 0.5F)
|
| 185 | );
|
| 186 | PartDefinition leftLeg = root.addOrReplaceChild(
|
| 187 | "right_leg", CubeListBuilder.create().texOffs(18, 17).addBox(-1.0F, -0.2F, -2.0F, 3.0F, 4.0F, 3.0F, g.extend(-0.1F)), PartPose.offset(-1.5F, 20.0F, 0.5F)
|
| 188 | );
|
| 189 | rightLeg.addOrReplaceChild(
|
| 190 | "right_foot", CubeListBuilder.create().texOffs(0, 25).addBox(-2.0F, 2.9F, -2.0F, 3.0F, 1.0F, 3.0F, g), PartPose.offset(0.0F, 0.0F, 0.0F)
|
| 191 | );
|
| 192 | leftLeg.addOrReplaceChild(
|
| 193 | "left_foot",
|
| 194 | CubeListBuilder.create().texOffs(0, 29).mirror().addBox(-1.0F, 2.9F, -2.0F, 3.0F, 1.0F, 3.0F, g).mirror(false),
|
| 195 | PartPose.offset(0.0F, 0.0F, 0.0F)
|
| 196 | );
|
| 197 | head.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.ZERO);
|
| 198 | return mesh;
|
| 199 | }
|
| 200 |
|
| 201 | public void setupAnim(final T state) {
|
| 202 | super.setupAnim(state);
|
| 203 | float swimAmount = state.swimAmount;
|
| 204 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 205 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 206 | if (state.isFallFlying) {
|
| 207 | this.head.xRot = (float) (-Math.PI / 4);
|
| 208 | }
|
| 209 |
|
| 210 | float animationPos = state.walkAnimationPos;
|
| 211 | float animationSpeed = state.walkAnimationSpeed;
|
| 212 | this.rightArm.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 2.0F * animationSpeed * 0.5F / state.speedValue;
|
| 213 | this.leftArm.xRot = Mth.cos(animationPos * 0.6662F) * 2.0F * animationSpeed * 0.5F / state.speedValue;
|
| 214 | this.rightLeg.xRot = Mth.cos(animationPos * 0.6662F) * 1.4F * animationSpeed / state.speedValue;
|
| 215 | this.leftLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 1.4F * animationSpeed / state.speedValue;
|
| 216 | this.rightLeg.yRot = 0.005F;
|
| 217 | this.leftLeg.yRot = -0.005F;
|
| 218 | this.rightLeg.zRot = 0.005F;
|
| 219 | this.leftLeg.zRot = -0.005F;
|
| 220 | if (state.isPassenger) {
|
| 221 | this.rightArm.xRot += (float) (-Math.PI / 5);
|
| 222 | this.leftArm.xRot += (float) (-Math.PI / 5);
|
| 223 | this.rightLeg.xRot = -1.4137167F;
|
| 224 | this.rightLeg.yRot = (float) (Math.PI / 10);
|
| 225 | this.rightLeg.zRot = 0.07853982F;
|
| 226 | this.leftLeg.xRot = -1.4137167F;
|
| 227 | this.leftLeg.yRot = (float) (-Math.PI / 10);
|
| 228 | this.leftLeg.zRot = -0.07853982F;
|
| 229 | }
|
| 230 |
|
| 231 | HumanoidArm prioritizeArm;
|
| 232 | if (state.isUsingItem) {
|
| 233 | prioritizeArm = state.useItemHand.asArm(state.mainArm);
|
| 234 | } else {
|
| 235 | HumanoidArm offHandArm = InteractionHand.OFF_HAND.asArm(state.mainArm);
|
| 236 | prioritizeArm = state.getArmPose(offHandArm).isTwoHanded() ? state.mainArm : offHandArm;
|
| 237 | }
|
| 238 |
|
| 239 | if (prioritizeArm == HumanoidArm.RIGHT) {
|
| 240 | this.poseRightArm(state);
|
| 241 | if (!state.rightArmPose.affectsOffhandPose()) {
|
| 242 | this.poseLeftArm(state);
|
| 243 | }
|
| 244 | } else {
|
| 245 | this.poseLeftArm(state);
|
| 246 | if (!state.leftArmPose.affectsOffhandPose()) {
|
| 247 | this.poseRightArm(state);
|
| 248 | }
|
| 249 | }
|
| 250 |
|
| 251 | this.setupAttackAnimation(state);
|
| 252 | if (state.isCrouching) {
|
| 253 | this.body.xRot = 0.5F;
|
| 254 | this.rightArm.xRot += 0.4F;
|
| 255 | this.leftArm.xRot += 0.4F;
|
| 256 | this.rightLeg.z += 4.0F;
|
| 257 | this.leftLeg.z += 4.0F;
|
| 258 | this.head.y += 4.2F;
|
| 259 | this.body.y += 3.2F;
|
| 260 | this.leftArm.y += 3.2F;
|
| 261 | this.rightArm.y += 3.2F;
|
| 262 | }
|
| 263 |
|
| 264 | if (state.rightArmPose != HumanoidModel.ArmPose.SPYGLASS) {
|
| 265 | AnimationUtils.bobModelPart(this.rightArm, state.ageInTicks, 1.0F);
|
| 266 | }
|
| 267 |
|
| 268 | if (state.leftArmPose != HumanoidModel.ArmPose.SPYGLASS) {
|
| 269 | AnimationUtils.bobModelPart(this.leftArm, state.ageInTicks, -1.0F);
|
| 270 | }
|
| 271 |
|
| 272 | if (swimAmount > 0.0F) {
|
| 273 | this.setupSwimAnimation(state, animationPos, swimAmount);
|
| 274 | }
|
| 275 | }
|
| 276 |
|
| 277 | protected void setupSwimAnimation(final T state, final float animationPos, final float swimAmount) {
|
| 278 | if (!state.isFallFlying) {
|
| 279 | this.head.xRot = Mth.rotLerpRad(swimAmount, this.head.xRot, (float) (-Math.PI / 4));
|
| 280 | }
|
| 281 |
|
| 282 | float swimPos = animationPos % 26.0F;
|
| 283 | HumanoidArm swingArm = state.currentSwing != null ? state.currentSwing.hand().asArm(state.mainArm) : null;
|
| 284 | float rightArmSwimAmount = state.rightArmPose != HumanoidModel.ArmPose.SPEAR && swingArm != HumanoidArm.RIGHT ? swimAmount : 0.0F;
|
| 285 | float leftArmSwimAmount = state.leftArmPose != HumanoidModel.ArmPose.SPEAR && swingArm != HumanoidArm.LEFT ? swimAmount : 0.0F;
|
| 286 | if (!state.isUsingItem) {
|
| 287 | if (swimPos < 14.0F) {
|
| 288 | this.leftArm.xRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.xRot, 0.0F);
|
| 289 | this.rightArm.xRot = Mth.lerp(rightArmSwimAmount, this.rightArm.xRot, 0.0F);
|
| 290 | this.leftArm.yRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.yRot, (float) Math.PI);
|
| 291 | this.rightArm.yRot = Mth.lerp(rightArmSwimAmount, this.rightArm.yRot, (float) Math.PI);
|
| 292 | this.leftArm.zRot = Mth.rotLerpRad(
|
| 293 | leftArmSwimAmount, this.leftArm.zRot, (float) Math.PI + 1.8707964F * this.quadraticArmUpdate(swimPos) / this.quadraticArmUpdate(14.0F)
|
| 294 | );
|
| 295 | this.rightArm.zRot = Mth.lerp(
|
| 296 | rightArmSwimAmount, this.rightArm.zRot, (float) Math.PI - 1.8707964F * this.quadraticArmUpdate(swimPos) / this.quadraticArmUpdate(14.0F)
|
| 297 | );
|
| 298 | } else if (swimPos >= 14.0F && swimPos < 22.0F) {
|
| 299 | float internalSwimPos = (swimPos - 14.0F) / 8.0F;
|
| 300 | this.leftArm.xRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.xRot, (float) (Math.PI / 2) * internalSwimPos);
|
| 301 | this.rightArm.xRot = Mth.lerp(rightArmSwimAmount, this.rightArm.xRot, (float) (Math.PI / 2) * internalSwimPos);
|
| 302 | this.leftArm.yRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.yRot, (float) Math.PI);
|
| 303 | this.rightArm.yRot = Mth.lerp(rightArmSwimAmount, this.rightArm.yRot, (float) Math.PI);
|
| 304 | this.leftArm.zRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.zRot, 5.012389F - 1.8707964F * internalSwimPos);
|
| 305 | this.rightArm.zRot = Mth.lerp(rightArmSwimAmount, this.rightArm.zRot, 1.2707963F + 1.8707964F * internalSwimPos);
|
| 306 | } else if (swimPos >= 22.0F && swimPos < 26.0F) {
|
| 307 | float internalSwimPos = (swimPos - 22.0F) / 4.0F;
|
| 308 | this.leftArm.xRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.xRot, (float) (Math.PI / 2) - (float) (Math.PI / 2) * internalSwimPos);
|
| 309 | this.rightArm.xRot = Mth.lerp(rightArmSwimAmount, this.rightArm.xRot, (float) (Math.PI / 2) - (float) (Math.PI / 2) * internalSwimPos);
|
| 310 | this.leftArm.yRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.yRot, (float) Math.PI);
|
| 311 | this.rightArm.yRot = Mth.lerp(rightArmSwimAmount, this.rightArm.yRot, (float) Math.PI);
|
| 312 | this.leftArm.zRot = Mth.rotLerpRad(leftArmSwimAmount, this.leftArm.zRot, (float) Math.PI);
|
| 313 | this.rightArm.zRot = Mth.lerp(rightArmSwimAmount, this.rightArm.zRot, (float) Math.PI);
|
| 314 | }
|
| 315 | }
|
| 316 |
|
| 317 | float amplitude = 0.3F;
|
| 318 | float slowdown = 0.33333334F;
|
| 319 | this.leftLeg.xRot = Mth.lerp(swimAmount, this.leftLeg.xRot, 0.3F * Mth.cos(animationPos * 0.33333334F + (float) Math.PI));
|
| 320 | this.rightLeg.xRot = Mth.lerp(swimAmount, this.rightLeg.xRot, 0.3F * Mth.cos(animationPos * 0.33333334F));
|
| 321 | }
|
| 322 |
|
| 323 | private void poseRightArm(final T state) {
|
| 324 | switch (state.rightArmPose) {
|
| 325 | case EMPTY:
|
| 326 | this.rightArm.yRot = 0.0F;
|
| 327 | break;
|
| 328 | case ITEM:
|
| 329 | this.rightArm.xRot = this.rightArm.xRot * 0.5F - (float) (Math.PI / 10);
|
| 330 | this.rightArm.yRot = 0.0F;
|
| 331 | break;
|
| 332 | case BLOCK:
|
| 333 | this.poseBlockingArm(this.rightArm, true);
|
| 334 | break;
|
| 335 | case BOW_AND_ARROW:
|
| 336 | this.rightArm.yRot = -0.1F + this.head.yRot;
|
| 337 | this.leftArm.yRot = 0.1F + this.head.yRot + 0.4F;
|
| 338 | this.rightArm.xRot = (float) (-Math.PI / 2) + this.head.xRot;
|
| 339 | this.leftArm.xRot = (float) (-Math.PI / 2) + this.head.xRot;
|
| 340 | break;
|
| 341 | case THROW_TRIDENT:
|
| 342 | this.rightArm.xRot = this.rightArm.xRot * 0.5F - (float) Math.PI;
|
| 343 | this.rightArm.yRot = 0.0F;
|
| 344 | break;
|
| 345 | case CROSSBOW_CHARGE:
|
| 346 | AnimationUtils.animateCrossbowCharge(this.rightArm, this.leftArm, state.maxCrossbowChargeDuration, state.ticksUsingItem, true);
|
| 347 | break;
|
| 348 | case CROSSBOW_HOLD:
|
| 349 | AnimationUtils.animateCrossbowHold(this.rightArm, this.leftArm, this.head, true);
|
| 350 | break;
|
| 351 | case SPYGLASS:
|
| 352 | this.rightArm.xRot = Mth.clamp(this.head.xRot - 1.9198622F - (state.isCrouching ? (float) (Math.PI / 12) : 0.0F), -2.4F, 3.3F);
|
| 353 | this.rightArm.yRot = this.head.yRot - (float) (Math.PI / 12);
|
| 354 | break;
|
| 355 | case TOOT_HORN:
|
| 356 | this.rightArm.xRot = Mth.clamp(this.head.xRot, -1.2F, 1.2F) - 1.4835298F;
|
| 357 | this.rightArm.yRot = this.head.yRot - (float) (Math.PI / 6);
|
| 358 | break;
|
| 359 | case BRUSH:
|
| 360 | this.rightArm.xRot = this.rightArm.xRot * 0.5F - (float) (Math.PI / 5);
|
| 361 | this.rightArm.yRot = 0.0F;
|
| 362 | break;
|
| 363 | case SPEAR:
|
| 364 | SpearAnimations.thirdPersonHandUse(this.rightArm, this.head, HumanoidArm.RIGHT, state.getUseItemStackForArm(HumanoidArm.RIGHT), state);
|
| 365 | }
|
| 366 | }
|
| 367 |
|
| 368 | private void poseLeftArm(final T state) {
|
| 369 | switch (state.leftArmPose) {
|
| 370 | case EMPTY:
|
| 371 | this.leftArm.yRot = 0.0F;
|
| 372 | break;
|
| 373 | case ITEM:
|
| 374 | this.leftArm.xRot = this.leftArm.xRot * 0.5F - (float) (Math.PI / 10);
|
| 375 | this.leftArm.yRot = 0.0F;
|
| 376 | break;
|
| 377 | case BLOCK:
|
| 378 | this.poseBlockingArm(this.leftArm, false);
|
| 379 | break;
|
| 380 | case BOW_AND_ARROW:
|
| 381 | this.rightArm.yRot = -0.1F + this.head.yRot - 0.4F;
|
| 382 | this.leftArm.yRot = 0.1F + this.head.yRot;
|
| 383 | this.rightArm.xRot = (float) (-Math.PI / 2) + this.head.xRot;
|
| 384 | this.leftArm.xRot = (float) (-Math.PI / 2) + this.head.xRot;
|
| 385 | break;
|
| 386 | case THROW_TRIDENT:
|
| 387 | this.leftArm.xRot = this.leftArm.xRot * 0.5F - (float) Math.PI;
|
| 388 | this.leftArm.yRot = 0.0F;
|
| 389 | break;
|
| 390 | case CROSSBOW_CHARGE:
|
| 391 | AnimationUtils.animateCrossbowCharge(this.rightArm, this.leftArm, state.maxCrossbowChargeDuration, state.ticksUsingItem, false);
|
| 392 | break;
|
| 393 | case CROSSBOW_HOLD:
|
| 394 | AnimationUtils.animateCrossbowHold(this.rightArm, this.leftArm, this.head, false);
|
| 395 | break;
|
| 396 | case SPYGLASS:
|
| 397 | this.leftArm.xRot = Mth.clamp(this.head.xRot - 1.9198622F - (state.isCrouching ? (float) (Math.PI / 12) : 0.0F), -2.4F, 3.3F);
|
| 398 | this.leftArm.yRot = this.head.yRot + (float) (Math.PI / 12);
|
| 399 | break;
|
| 400 | case TOOT_HORN:
|
| 401 | this.leftArm.xRot = Mth.clamp(this.head.xRot, -1.2F, 1.2F) - 1.4835298F;
|
| 402 | this.leftArm.yRot = this.head.yRot + (float) (Math.PI / 6);
|
| 403 | break;
|
| 404 | case BRUSH:
|
| 405 | this.leftArm.xRot = this.leftArm.xRot * 0.5F - (float) (Math.PI / 5);
|
| 406 | this.leftArm.yRot = 0.0F;
|
| 407 | break;
|
| 408 | case SPEAR:
|
| 409 | SpearAnimations.thirdPersonHandUse(this.leftArm, this.head, HumanoidArm.LEFT, state.getUseItemStackForArm(HumanoidArm.LEFT), state);
|
| 410 | }
|
| 411 | }
|
| 412 |
|
| 413 | private void poseBlockingArm(final ModelPart arm, final boolean right) {
|
| 414 | arm.xRot = arm.xRot * 0.5F - 0.9424779F + Mth.clamp(this.head.xRot, (float) (-Math.PI * 4.0 / 9.0), 0.43633232F);
|
| 415 | arm.yRot = (right ? -30.0F : 30.0F) * (float) (Math.PI / 180.0) + Mth.clamp(this.head.yRot, (float) (-Math.PI / 6), (float) (Math.PI / 6));
|
| 416 | }
|
| 417 |
|
| 418 | protected void setupAttackAnimation(final T state) {
|
| 419 | float swingAnimation = state.swingAnimation;
|
| 420 | SwingDescription swing = state.currentSwing;
|
| 421 | if (!(swingAnimation <= 0.0F) && swing != null) {
|
| 422 | HumanoidArm swingArm = swing.hand().asArm(state.mainArm);
|
| 423 | this.body.yRot = Mth.sin(Mth.sqrt(swingAnimation) * (float) (Math.PI * 2)) * 0.2F;
|
| 424 | if (swingArm == HumanoidArm.LEFT) {
|
| 425 | this.body.yRot *= -1.0F;
|
| 426 | }
|
| 427 |
|
| 428 | float ageScale = state.ageScale;
|
| 429 | this.rightArm.z = Mth.sin(this.body.yRot) * 5.0F * ageScale;
|
| 430 | this.rightArm.x = -Mth.cos(this.body.yRot) * 5.0F * ageScale;
|
| 431 | this.leftArm.z = -Mth.sin(this.body.yRot) * 5.0F * ageScale;
|
| 432 | this.leftArm.x = Mth.cos(this.body.yRot) * 5.0F * ageScale;
|
| 433 | this.rightArm.yRot = this.rightArm.yRot + this.body.yRot;
|
| 434 | this.leftArm.yRot = this.leftArm.yRot + this.body.yRot;
|
| 435 | this.leftArm.xRot = this.leftArm.xRot + this.body.yRot;
|
| 436 | switch (swing.animation().type()) {
|
| 437 | case WHACK:
|
| 438 | float aa = Mth.sin(Ease.outQuart(swingAnimation) * (float) Math.PI);
|
| 439 | float bb = Mth.sin(swingAnimation * (float) Math.PI) * -(this.head.xRot - 0.7F) * 0.75F;
|
| 440 | ModelPart attackArm = this.getArm(swingArm);
|
| 441 | attackArm.xRot -= aa * 1.2F + bb;
|
| 442 | attackArm.yRot = attackArm.yRot + this.body.yRot * 2.0F;
|
| 443 | attackArm.zRot = attackArm.zRot + Mth.sin(swingAnimation * (float) Math.PI) * -0.4F;
|
| 444 | case NONE:
|
| 445 | default:
|
| 446 | break;
|
| 447 | case STAB:
|
| 448 | SpearAnimations.thirdPersonAttackHand(this, swingAnimation, swingArm);
|
| 449 | }
|
| 450 | }
|
| 451 | }
|
| 452 |
|
| 453 | private float quadraticArmUpdate(final float x) {
|
| 454 | return -65.0F * x + x * x;
|
| 455 | }
|
| 456 |
|
| 457 | public void translateToHand(final HumanoidRenderState state, final HumanoidArm arm, final PoseStack poseStack) {
|
| 458 | this.root.translateAndRotate(poseStack);
|
| 459 | this.getArm(arm).translateAndRotate(poseStack);
|
| 460 | }
|
| 461 |
|
| 462 | public ModelPart getArm(final HumanoidArm arm) {
|
| 463 | return arm == HumanoidArm.LEFT ? this.leftArm : this.rightArm;
|
| 464 | }
|
| 465 |
|
| 466 | @Override
|
| 467 | public ModelPart getHead() {
|
| 468 | return this.head;
|
| 469 | }
|
| 470 |
|
| 471 | @Environment(EnvType.CLIENT)
|
| 472 | public enum ArmPose {
|
| 473 | EMPTY(false, false),
|
| 474 | ITEM(false, false),
|
| 475 | BLOCK(false, false),
|
| 476 | BOW_AND_ARROW(true, true),
|
| 477 | THROW_TRIDENT(false, true),
|
| 478 | CROSSBOW_CHARGE(true, true),
|
| 479 | CROSSBOW_HOLD(true, true),
|
| 480 | SPYGLASS(false, false),
|
| 481 | TOOT_HORN(false, false),
|
| 482 | BRUSH(false, false),
|
| 483 | SPEAR("SPEAR", 10, false, false);
|
| 484 |
|
| 485 | private final boolean twoHanded;
|
| 486 | private final boolean affectsOffhandPose;
|
| 487 |
|
| 488 | ArmPose(final boolean twoHanded, final boolean affectsOffhandPose) {
|
| 489 | this.twoHanded = twoHanded;
|
| 490 | this.affectsOffhandPose = affectsOffhandPose;
|
| 491 | }
|
| 492 |
|
| 493 | public boolean isTwoHanded() {
|
| 494 | return this.twoHanded;
|
| 495 | }
|
| 496 |
|
| 497 | public boolean affectsOffhandPose() {
|
| 498 | return this.affectsOffhandPose;
|
| 499 | }
|
| 500 |
|
| 501 | public <S extends ArmedEntityRenderState> void animateUseItem(
|
| 502 | final S state, final PoseStack poseStack, final float ticksUsingItem, final HumanoidArm arm, final ItemStack actualItem
|
| 503 | ) {
|
| 504 | }
|
| 505 | }
|
| 506 | }
|
| 507 |
|