package net.minecraft.client.model; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; 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.LayerDefinition; 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.animal.horse.AbstractChestedHorse; @Environment(EnvType.CLIENT) public class LlamaModel extends EntityModel { private final ModelPart head; private final ModelPart body; private final ModelPart rightHindLeg; private final ModelPart leftHindLeg; private final ModelPart rightFrontLeg; private final ModelPart leftFrontLeg; private final ModelPart rightChest; private final ModelPart leftChest; public LlamaModel(ModelPart root) { this.head = root.getChild("head"); this.body = root.getChild("body"); this.rightChest = root.getChild("right_chest"); this.leftChest = root.getChild("left_chest"); 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 LayerDefinition createBodyLayer(CubeDeformation cubeDeformation) { MeshDefinition meshDefinition = new MeshDefinition(); PartDefinition partDefinition = meshDefinition.getRoot(); partDefinition.addOrReplaceChild( "head", CubeListBuilder.create() .texOffs(0, 0) .addBox(-2.0F, -14.0F, -10.0F, 4.0F, 4.0F, 9.0F, cubeDeformation) .texOffs(0, 14) .addBox("neck", -4.0F, -16.0F, -6.0F, 8.0F, 18.0F, 6.0F, cubeDeformation) .texOffs(17, 0) .addBox("ear", -4.0F, -19.0F, -4.0F, 3.0F, 3.0F, 2.0F, cubeDeformation) .texOffs(17, 0) .addBox("ear", 1.0F, -19.0F, -4.0F, 3.0F, 3.0F, 2.0F, cubeDeformation), PartPose.offset(0.0F, 7.0F, -6.0F) ); partDefinition.addOrReplaceChild( "body", CubeListBuilder.create().texOffs(29, 0).addBox(-6.0F, -10.0F, -7.0F, 12.0F, 18.0F, 10.0F, cubeDeformation), PartPose.offsetAndRotation(0.0F, 5.0F, 2.0F, (float) (Math.PI / 2), 0.0F, 0.0F) ); partDefinition.addOrReplaceChild( "right_chest", CubeListBuilder.create().texOffs(45, 28).addBox(-3.0F, 0.0F, 0.0F, 8.0F, 8.0F, 3.0F, cubeDeformation), PartPose.offsetAndRotation(-8.5F, 3.0F, 3.0F, 0.0F, (float) (Math.PI / 2), 0.0F) ); partDefinition.addOrReplaceChild( "left_chest", CubeListBuilder.create().texOffs(45, 41).addBox(-3.0F, 0.0F, 0.0F, 8.0F, 8.0F, 3.0F, cubeDeformation), PartPose.offsetAndRotation(5.5F, 3.0F, 3.0F, 0.0F, (float) (Math.PI / 2), 0.0F) ); int i = 4; int j = 14; CubeListBuilder cubeListBuilder = CubeListBuilder.create().texOffs(29, 29).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 14.0F, 4.0F, cubeDeformation); partDefinition.addOrReplaceChild("right_hind_leg", cubeListBuilder, PartPose.offset(-3.5F, 10.0F, 6.0F)); partDefinition.addOrReplaceChild("left_hind_leg", cubeListBuilder, PartPose.offset(3.5F, 10.0F, 6.0F)); partDefinition.addOrReplaceChild("right_front_leg", cubeListBuilder, PartPose.offset(-3.5F, 10.0F, -5.0F)); partDefinition.addOrReplaceChild("left_front_leg", cubeListBuilder, PartPose.offset(3.5F, 10.0F, -5.0F)); return LayerDefinition.create(meshDefinition, 128, 64); } /** * Sets this entity's model rotation angles */ 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; boolean bl = !entity.isBaby() && entity.hasChest(); this.rightChest.visible = bl; this.leftChest.visible = bl; } @Override public void renderToBuffer(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay, int color) { if (this.young) { float f = 2.0F; poseStack.pushPose(); float g = 0.7F; poseStack.scale(0.71428573F, 0.64935064F, 0.7936508F); poseStack.translate(0.0F, 1.3125F, 0.22F); this.head.render(poseStack, buffer, packedLight, packedOverlay, color); poseStack.popPose(); poseStack.pushPose(); float h = 1.1F; poseStack.scale(0.625F, 0.45454544F, 0.45454544F); poseStack.translate(0.0F, 2.0625F, 0.0F); this.body.render(poseStack, buffer, packedLight, packedOverlay, color); poseStack.popPose(); poseStack.pushPose(); poseStack.scale(0.45454544F, 0.41322312F, 0.45454544F); poseStack.translate(0.0F, 2.0625F, 0.0F); ImmutableList.of(this.rightHindLeg, this.leftHindLeg, this.rightFrontLeg, this.leftFrontLeg, this.rightChest, this.leftChest) .forEach(modelPart -> modelPart.render(poseStack, buffer, packedLight, packedOverlay, color)); poseStack.popPose(); } else { ImmutableList.of(this.head, this.body, this.rightHindLeg, this.leftHindLeg, this.rightFrontLeg, this.leftFrontLeg, this.rightChest, this.leftChest) .forEach(modelPart -> modelPart.render(poseStack, buffer, packedLight, packedOverlay, color)); } } }