| 1 | package net.minecraft.client.model.ambient;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.animation.KeyframeAnimation;
|
| 6 | import net.minecraft.client.animation.definitions.BatAnimation;
|
| 7 | import net.minecraft.client.model.EntityModel;
|
| 8 | import net.minecraft.client.model.geom.ModelPart;
|
| 9 | import net.minecraft.client.model.geom.PartPose;
|
| 10 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 11 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 12 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 13 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 14 | import net.minecraft.client.renderer.entity.state.BatRenderState;
|
| 15 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class BatModel extends EntityModel<BatRenderState> {
|
| 19 | private final ModelPart head;
|
| 20 | private final ModelPart body;
|
| 21 | private final ModelPart rightWing;
|
| 22 | private final ModelPart leftWing;
|
| 23 | private final ModelPart rightWingTip;
|
| 24 | private final ModelPart leftWingTip;
|
| 25 | private final ModelPart feet;
|
| 26 | private final KeyframeAnimation flyingAnimation;
|
| 27 | private final KeyframeAnimation restingAnimation;
|
| 28 |
|
| 29 | public BatModel(final ModelPart root) {
|
| 30 | super(root, RenderTypes::entityCutoutCull);
|
| 31 | this.body = root.getChild("body");
|
| 32 | this.head = root.getChild("head");
|
| 33 | this.rightWing = this.body.getChild("right_wing");
|
| 34 | this.rightWingTip = this.rightWing.getChild("right_wing_tip");
|
| 35 | this.leftWing = this.body.getChild("left_wing");
|
| 36 | this.leftWingTip = this.leftWing.getChild("left_wing_tip");
|
| 37 | this.feet = this.body.getChild("feet");
|
| 38 | this.flyingAnimation = BatAnimation.BAT_FLYING.bake(root);
|
| 39 | this.restingAnimation = BatAnimation.BAT_RESTING.bake(root);
|
| 40 | }
|
| 41 |
|
| 42 | public static LayerDefinition createBodyLayer() {
|
| 43 | MeshDefinition meshdefinition = new MeshDefinition();
|
| 44 | PartDefinition partdefinition = meshdefinition.getRoot();
|
| 45 | PartDefinition body = partdefinition.addOrReplaceChild(
|
| 46 | "body", CubeListBuilder.create().texOffs(0, 0).addBox(-1.5F, 0.0F, -1.0F, 3.0F, 5.0F, 2.0F), PartPose.offset(0.0F, 17.0F, 0.0F)
|
| 47 | );
|
| 48 | PartDefinition head = partdefinition.addOrReplaceChild(
|
| 49 | "head", CubeListBuilder.create().texOffs(0, 7).addBox(-2.0F, -3.0F, -1.0F, 4.0F, 3.0F, 2.0F), PartPose.offset(0.0F, 17.0F, 0.0F)
|
| 50 | );
|
| 51 | head.addOrReplaceChild("right_ear", CubeListBuilder.create().texOffs(1, 15).addBox(-2.5F, -4.0F, 0.0F, 3.0F, 5.0F, 0.0F), PartPose.offset(-1.5F, -2.0F, 0.0F));
|
| 52 | head.addOrReplaceChild("left_ear", CubeListBuilder.create().texOffs(8, 15).addBox(-0.1F, -3.0F, 0.0F, 3.0F, 5.0F, 0.0F), PartPose.offset(1.1F, -3.0F, 0.0F));
|
| 53 | PartDefinition rightWing = body.addOrReplaceChild(
|
| 54 | "right_wing", CubeListBuilder.create().texOffs(12, 0).addBox(-2.0F, -2.0F, 0.0F, 2.0F, 7.0F, 0.0F), PartPose.offset(-1.5F, 0.0F, 0.0F)
|
| 55 | );
|
| 56 | rightWing.addOrReplaceChild(
|
| 57 | "right_wing_tip", CubeListBuilder.create().texOffs(16, 0).addBox(-6.0F, -2.0F, 0.0F, 6.0F, 8.0F, 0.0F), PartPose.offset(-2.0F, 0.0F, 0.0F)
|
| 58 | );
|
| 59 | PartDefinition leftWing = body.addOrReplaceChild(
|
| 60 | "left_wing", CubeListBuilder.create().texOffs(12, 7).addBox(0.0F, -2.0F, 0.0F, 2.0F, 7.0F, 0.0F), PartPose.offset(1.5F, 0.0F, 0.0F)
|
| 61 | );
|
| 62 | leftWing.addOrReplaceChild(
|
| 63 | "left_wing_tip", CubeListBuilder.create().texOffs(16, 8).addBox(0.0F, -2.0F, 0.0F, 6.0F, 8.0F, 0.0F), PartPose.offset(2.0F, 0.0F, 0.0F)
|
| 64 | );
|
| 65 | body.addOrReplaceChild("feet", CubeListBuilder.create().texOffs(16, 16).addBox(-1.5F, 0.0F, 0.0F, 3.0F, 2.0F, 0.0F), PartPose.offset(0.0F, 5.0F, 0.0F));
|
| 66 | return LayerDefinition.create(meshdefinition, 32, 32);
|
| 67 | }
|
| 68 |
|
| 69 | public void setupAnim(final BatRenderState state) {
|
| 70 | super.setupAnim(state);
|
| 71 | if (state.isResting) {
|
| 72 | this.applyHeadRotation(state.yRot);
|
| 73 | }
|
| 74 |
|
| 75 | this.flyingAnimation.apply(state.flyAnimationState, state.ageInTicks);
|
| 76 | this.restingAnimation.apply(state.restAnimationState, state.ageInTicks);
|
| 77 | }
|
| 78 |
|
| 79 | private void applyHeadRotation(final float yRot) {
|
| 80 | this.head.yRot = yRot * (float) (Math.PI / 180.0);
|
| 81 | }
|
| 82 | }
|
| 83 |
|