| 1 | package net.minecraft.client.model.monster.creeper;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.EntityModel;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.model.geom.PartPose;
|
| 8 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 9 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 10 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 12 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 13 | import net.minecraft.client.renderer.entity.state.CreeperRenderState;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class CreeperModel extends EntityModel<CreeperRenderState> {
|
| 18 | private final ModelPart head;
|
| 19 | private final ModelPart rightHindLeg;
|
| 20 | private final ModelPart leftHindLeg;
|
| 21 | private final ModelPart rightFrontLeg;
|
| 22 | private final ModelPart leftFrontLeg;
|
| 23 | private static final int Y_OFFSET = 6;
|
| 24 |
|
| 25 | public CreeperModel(final ModelPart root) {
|
| 26 | super(root);
|
| 27 | this.head = root.getChild("head");
|
| 28 | this.leftHindLeg = root.getChild("right_hind_leg");
|
| 29 | this.rightHindLeg = root.getChild("left_hind_leg");
|
| 30 | this.leftFrontLeg = root.getChild("right_front_leg");
|
| 31 | this.rightFrontLeg = root.getChild("left_front_leg");
|
| 32 | }
|
| 33 |
|
| 34 | public static LayerDefinition createBodyLayer(final CubeDeformation g) {
|
| 35 | MeshDefinition mesh = new MeshDefinition();
|
| 36 | PartDefinition root = mesh.getRoot();
|
| 37 | root.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, g), PartPose.offset(0.0F, 6.0F, 0.0F));
|
| 38 | root.addOrReplaceChild("body", CubeListBuilder.create().texOffs(16, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, g), PartPose.offset(0.0F, 6.0F, 0.0F));
|
| 39 | CubeListBuilder leg = CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 6.0F, 4.0F, g);
|
| 40 | root.addOrReplaceChild("right_hind_leg", leg, PartPose.offset(-2.0F, 18.0F, 4.0F));
|
| 41 | root.addOrReplaceChild("left_hind_leg", leg, PartPose.offset(2.0F, 18.0F, 4.0F));
|
| 42 | root.addOrReplaceChild("right_front_leg", leg, PartPose.offset(-2.0F, 18.0F, -4.0F));
|
| 43 | root.addOrReplaceChild("left_front_leg", leg, PartPose.offset(2.0F, 18.0F, -4.0F));
|
| 44 | return LayerDefinition.create(mesh, 64, 32);
|
| 45 | }
|
| 46 |
|
| 47 | public void setupAnim(final CreeperRenderState state) {
|
| 48 | super.setupAnim(state);
|
| 49 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 50 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 51 | float animationSpeed = state.walkAnimationSpeed;
|
| 52 | float animationPos = state.walkAnimationPos;
|
| 53 | this.rightHindLeg.xRot = Mth.cos(animationPos * 0.6662F) * 1.4F * animationSpeed;
|
| 54 | this.leftHindLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 1.4F * animationSpeed;
|
| 55 | this.rightFrontLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 1.4F * animationSpeed;
|
| 56 | this.leftFrontLeg.xRot = Mth.cos(animationPos * 0.6662F) * 1.4F * animationSpeed;
|
| 57 | }
|
| 58 | }
|
| 59 |
|