package net.minecraft.client.model; import com.google.common.collect.ImmutableList; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.model.geom.builders.CubeDeformation; import net.minecraft.client.model.geom.builders.CubeListBuilder; import net.minecraft.client.model.geom.builders.MeshDefinition; import net.minecraft.client.model.geom.builders.PartDefinition; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @Environment(EnvType.CLIENT) public class QuadrupedModel extends AgeableListModel { protected final ModelPart head; protected final ModelPart body; protected final ModelPart rightHindLeg; protected final ModelPart leftHindLeg; protected final ModelPart rightFrontLeg; protected final ModelPart leftFrontLeg; protected QuadrupedModel( ModelPart root, boolean scaleHead, float babyYHeadOffset, float babyZHeadOffset, float babyHeadScale, float babyBodyScale, int bodyYOffset ) { super(scaleHead, babyYHeadOffset, babyZHeadOffset, babyHeadScale, babyBodyScale, bodyYOffset); this.head = root.getChild("head"); this.body = root.getChild("body"); this.rightHindLeg = root.getChild("right_hind_leg"); this.leftHindLeg = root.getChild("left_hind_leg"); this.rightFrontLeg = root.getChild("right_front_leg"); this.leftFrontLeg = root.getChild("left_front_leg"); } public static MeshDefinition createBodyMesh(int yOffset, CubeDeformation cubeDeformation) { MeshDefinition meshDefinition = new MeshDefinition(); PartDefinition partDefinition = meshDefinition.getRoot(); partDefinition.addOrReplaceChild( "head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -4.0F, -8.0F, 8.0F, 8.0F, 8.0F, cubeDeformation), PartPose.offset(0.0F, 18 - yOffset, -6.0F) ); partDefinition.addOrReplaceChild( "body", CubeListBuilder.create().texOffs(28, 8).addBox(-5.0F, -10.0F, -7.0F, 10.0F, 16.0F, 8.0F, cubeDeformation), PartPose.offsetAndRotation(0.0F, 17 - yOffset, 2.0F, (float) (Math.PI / 2), 0.0F, 0.0F) ); CubeListBuilder cubeListBuilder = CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, (float)yOffset, 4.0F, cubeDeformation); partDefinition.addOrReplaceChild("right_hind_leg", cubeListBuilder, PartPose.offset(-3.0F, 24 - yOffset, 7.0F)); partDefinition.addOrReplaceChild("left_hind_leg", cubeListBuilder, PartPose.offset(3.0F, 24 - yOffset, 7.0F)); partDefinition.addOrReplaceChild("right_front_leg", cubeListBuilder, PartPose.offset(-3.0F, 24 - yOffset, -5.0F)); partDefinition.addOrReplaceChild("left_front_leg", cubeListBuilder, PartPose.offset(3.0F, 24 - yOffset, -5.0F)); return meshDefinition; } @Override protected Iterable headParts() { return ImmutableList.of(this.head); } @Override protected Iterable bodyParts() { return ImmutableList.of(this.body, this.rightHindLeg, this.leftHindLeg, this.rightFrontLeg, this.leftFrontLeg); } @Override public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.head.xRot = headPitch * (float) (Math.PI / 180.0); this.head.yRot = netHeadYaw * (float) (Math.PI / 180.0); this.rightHindLeg.xRot = Mth.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; this.leftHindLeg.xRot = Mth.cos(limbSwing * 0.6662F + (float) Math.PI) * 1.4F * limbSwingAmount; this.rightFrontLeg.xRot = Mth.cos(limbSwing * 0.6662F + (float) Math.PI) * 1.4F * limbSwingAmount; this.leftFrontLeg.xRot = Mth.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; } }