| 1 | package net.minecraft.client.model.animal.allay;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import com.mojang.math.Axis;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.model.ArmedModel;
|
| 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.CubeDeformation;
|
| 12 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 13 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 14 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 15 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 16 | import net.minecraft.client.renderer.entity.state.AllayRenderState;
|
| 17 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 18 | import net.minecraft.util.Mth;
|
| 19 | import net.minecraft.world.entity.HumanoidArm;
|
| 20 |
|
| 21 | @Environment(EnvType.CLIENT)
|
| 22 | public class AllayModel extends EntityModel<AllayRenderState> implements ArmedModel<AllayRenderState> {
|
| 23 | private final ModelPart head = this.root.getChild("head");
|
| 24 | private final ModelPart body = this.root.getChild("body");
|
| 25 | private final ModelPart right_arm = this.body.getChild("right_arm");
|
| 26 | private final ModelPart left_arm = this.body.getChild("left_arm");
|
| 27 | private final ModelPart right_wing = this.body.getChild("right_wing");
|
| 28 | private final ModelPart left_wing = this.body.getChild("left_wing");
|
| 29 | private static final float FLYING_ANIMATION_X_ROT = (float) (Math.PI / 4);
|
| 30 | private static final float MAX_HAND_HOLDING_ITEM_X_ROT_RAD = -1.134464F;
|
| 31 | private static final float MIN_HAND_HOLDING_ITEM_X_ROT_RAD = (float) (-Math.PI / 3);
|
| 32 |
|
| 33 | public AllayModel(final ModelPart root) {
|
| 34 | super(root.getChild("root"), RenderTypes::entityTranslucent);
|
| 35 | }
|
| 36 |
|
| 37 | public static LayerDefinition createBodyLayer() {
|
| 38 | MeshDefinition meshdefinition = new MeshDefinition();
|
| 39 | PartDefinition partdefinition = meshdefinition.getRoot();
|
| 40 | PartDefinition root = partdefinition.addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(0.0F, 23.5F, 0.0F));
|
| 41 | root.addOrReplaceChild(
|
| 42 | "head", CubeListBuilder.create().texOffs(0, 0).addBox(-2.5F, -5.0F, -2.5F, 5.0F, 5.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, -3.99F, 0.0F)
|
| 43 | );
|
| 44 | PartDefinition body = root.addOrReplaceChild(
|
| 45 | "body",
|
| 46 | CubeListBuilder.create()
|
| 47 | .texOffs(0, 10)
|
| 48 | .addBox(-1.5F, 0.0F, -1.0F, 3.0F, 4.0F, 2.0F, new CubeDeformation(0.0F))
|
| 49 | .texOffs(0, 16)
|
| 50 | .addBox(-1.5F, 0.0F, -1.0F, 3.0F, 5.0F, 2.0F, new CubeDeformation(-0.2F)),
|
| 51 | PartPose.offset(0.0F, -4.0F, 0.0F)
|
| 52 | );
|
| 53 | body.addOrReplaceChild(
|
| 54 | "right_arm",
|
| 55 | CubeListBuilder.create().texOffs(23, 0).addBox(-0.75F, -0.5F, -1.0F, 1.0F, 4.0F, 2.0F, new CubeDeformation(-0.01F)),
|
| 56 | PartPose.offset(-1.75F, 0.5F, 0.0F)
|
| 57 | );
|
| 58 | body.addOrReplaceChild(
|
| 59 | "left_arm",
|
| 60 | CubeListBuilder.create().texOffs(23, 6).addBox(-0.25F, -0.5F, -1.0F, 1.0F, 4.0F, 2.0F, new CubeDeformation(-0.01F)),
|
| 61 | PartPose.offset(1.75F, 0.5F, 0.0F)
|
| 62 | );
|
| 63 | body.addOrReplaceChild(
|
| 64 | "right_wing",
|
| 65 | CubeListBuilder.create().texOffs(16, 14).addBox(0.0F, 1.0F, 0.0F, 0.0F, 5.0F, 8.0F, new CubeDeformation(0.0F)),
|
| 66 | PartPose.offset(-0.5F, 0.0F, 0.6F)
|
| 67 | );
|
| 68 | body.addOrReplaceChild(
|
| 69 | "left_wing",
|
| 70 | CubeListBuilder.create().texOffs(16, 14).addBox(0.0F, 1.0F, 0.0F, 0.0F, 5.0F, 8.0F, new CubeDeformation(0.0F)),
|
| 71 | PartPose.offset(0.5F, 0.0F, 0.6F)
|
| 72 | );
|
| 73 | return LayerDefinition.create(meshdefinition, 32, 32);
|
| 74 | }
|
| 75 |
|
| 76 | public void setupAnim(final AllayRenderState state) {
|
| 77 | super.setupAnim(state);
|
| 78 | float animationSpeed = state.walkAnimationSpeed;
|
| 79 | float animationPos = state.walkAnimationPos;
|
| 80 | float flapSpeed = state.ageInTicks * 20.0F * (float) (Math.PI / 180.0) + animationPos;
|
| 81 | float flapAmount = Mth.cos(flapSpeed) * (float) Math.PI * 0.15F + animationSpeed;
|
| 82 | float idleBobSpeed = state.ageInTicks * 9.0F * (float) (Math.PI / 180.0);
|
| 83 | float flyingFactor = Math.min(animationSpeed / 0.3F, 1.0F);
|
| 84 | float idleBobFactor = 1.0F - flyingFactor;
|
| 85 | float holdingItemFactor = state.holdingAnimationProgress;
|
| 86 | if (state.isDancing) {
|
| 87 | float danceSpeed = state.ageInTicks * 8.0F * (float) (Math.PI / 180.0) + animationSpeed;
|
| 88 | float danceFrequency = Mth.cos(danceSpeed) * 16.0F * (float) (Math.PI / 180.0);
|
| 89 | float spinningRotation = state.spinningProgress;
|
| 90 | float headTiltZ = Mth.cos(danceSpeed) * 14.0F * (float) (Math.PI / 180.0);
|
| 91 | float headTiltY = Mth.cos(danceSpeed) * 30.0F * (float) (Math.PI / 180.0);
|
| 92 | this.root.yRot = state.isSpinning ? (float) (Math.PI * 4) * spinningRotation : this.root.yRot;
|
| 93 | this.root.zRot = danceFrequency * (1.0F - spinningRotation);
|
| 94 | this.head.yRot = headTiltY * (1.0F - spinningRotation);
|
| 95 | this.head.zRot = headTiltZ * (1.0F - spinningRotation);
|
| 96 | } else {
|
| 97 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 98 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 99 | }
|
| 100 |
|
| 101 | this.right_wing.xRot = 0.43633232F * (1.0F - flyingFactor);
|
| 102 | this.right_wing.yRot = (float) (-Math.PI / 4) + flapAmount;
|
| 103 | this.left_wing.xRot = 0.43633232F * (1.0F - flyingFactor);
|
| 104 | this.left_wing.yRot = (float) (Math.PI / 4) - flapAmount;
|
| 105 | this.body.xRot = flyingFactor * (float) (Math.PI / 4);
|
| 106 | float armFlyingRotX = holdingItemFactor * Mth.lerp(flyingFactor, (float) (-Math.PI / 3), -1.134464F);
|
| 107 | this.root.y = this.root.y + (float)Math.cos(idleBobSpeed) * 0.25F * idleBobFactor;
|
| 108 | this.right_arm.xRot = armFlyingRotX;
|
| 109 | this.left_arm.xRot = armFlyingRotX;
|
| 110 | float armIdleBobFactor = idleBobFactor * (1.0F - holdingItemFactor);
|
| 111 | float armIdleBobAmount = 0.43633232F - Mth.cos(idleBobSpeed + (float) (Math.PI * 3.0 / 2.0)) * (float) Math.PI * 0.075F * armIdleBobFactor;
|
| 112 | this.left_arm.zRot = -armIdleBobAmount;
|
| 113 | this.right_arm.zRot = armIdleBobAmount;
|
| 114 | this.right_arm.yRot = 0.27925268F * holdingItemFactor;
|
| 115 | this.left_arm.yRot = -0.27925268F * holdingItemFactor;
|
| 116 | }
|
| 117 |
|
| 118 | public void translateToHand(final AllayRenderState state, final HumanoidArm arm, final PoseStack poseStack) {
|
| 119 | float yOffset = 1.0F;
|
| 120 | float zOffset = 3.0F;
|
| 121 | this.root.translateAndRotate(poseStack);
|
| 122 | this.body.translateAndRotate(poseStack);
|
| 123 | poseStack.translate(0.0F, 0.0625F, 0.1875F);
|
| 124 | poseStack.rotate(Axis.XP, this.right_arm.xRot);
|
| 125 | poseStack.scale(0.7F, 0.7F, 0.7F);
|
| 126 | poseStack.translate(0.0625F, 0.0F, 0.0F);
|
| 127 | }
|
| 128 | }
|
| 129 |
|