2025-11-24 22:52:51 +03:00

89 lines
4.5 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.client.model;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HeadedModel;
import net.minecraft.client.model.VillagerLikeModel;
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.MeshTransformer;
import net.minecraft.client.model.geom.builders.PartDefinition;
import net.minecraft.client.renderer.entity.state.VillagerRenderState;
import net.minecraft.util.Mth;
public class VillagerModel
extends EntityModel<VillagerRenderState>
implements HeadedModel,
VillagerLikeModel<VillagerRenderState> {
public static final MeshTransformer BABY_TRANSFORMER = MeshTransformer.scaling(0.5f);
private final ModelPart head;
private final ModelPart rightLeg;
private final ModelPart leftLeg;
private final ModelPart arms;
public VillagerModel(ModelPart root) {
super(root);
this.head = root.getChild("head");
this.rightLeg = root.getChild("right_leg");
this.leftLeg = root.getChild("left_leg");
this.arms = root.getChild("arms");
}
public static MeshDefinition createBodyModel() {
MeshDefinition mesh = new MeshDefinition();
PartDefinition root = mesh.getRoot();
float offset = 0.5f;
PartDefinition head = root.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0f, -10.0f, -4.0f, 8.0f, 10.0f, 8.0f), PartPose.ZERO);
PartDefinition hat = head.addOrReplaceChild("hat", CubeListBuilder.create().texOffs(32, 0).addBox(-4.0f, -10.0f, -4.0f, 8.0f, 10.0f, 8.0f, new CubeDeformation(0.51f)), PartPose.ZERO);
hat.addOrReplaceChild("hat_rim", CubeListBuilder.create().texOffs(30, 47).addBox(-8.0f, -8.0f, -6.0f, 16.0f, 16.0f, 1.0f), PartPose.rotation(-1.5707964f, 0.0f, 0.0f));
head.addOrReplaceChild("nose", CubeListBuilder.create().texOffs(24, 0).addBox(-1.0f, -1.0f, -6.0f, 2.0f, 4.0f, 2.0f), PartPose.offset(0.0f, -2.0f, 0.0f));
PartDefinition body = root.addOrReplaceChild("body", CubeListBuilder.create().texOffs(16, 20).addBox(-4.0f, 0.0f, -3.0f, 8.0f, 12.0f, 6.0f), PartPose.ZERO);
body.addOrReplaceChild("jacket", CubeListBuilder.create().texOffs(0, 38).addBox(-4.0f, 0.0f, -3.0f, 8.0f, 20.0f, 6.0f, new CubeDeformation(0.5f)), PartPose.ZERO);
root.addOrReplaceChild("arms", CubeListBuilder.create().texOffs(44, 22).addBox(-8.0f, -2.0f, -2.0f, 4.0f, 8.0f, 4.0f).texOffs(44, 22).addBox(4.0f, -2.0f, -2.0f, 4.0f, 8.0f, 4.0f, true).texOffs(40, 38).addBox(-4.0f, 2.0f, -2.0f, 8.0f, 4.0f, 4.0f), PartPose.offsetAndRotation(0.0f, 3.0f, -1.0f, -0.75f, 0.0f, 0.0f));
root.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(0, 22).addBox(-2.0f, 0.0f, -2.0f, 4.0f, 12.0f, 4.0f), PartPose.offset(-2.0f, 12.0f, 0.0f));
root.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(0, 22).mirror().addBox(-2.0f, 0.0f, -2.0f, 4.0f, 12.0f, 4.0f), PartPose.offset(2.0f, 12.0f, 0.0f));
return mesh;
}
public static MeshDefinition createNoHatModel() {
MeshDefinition mesh = VillagerModel.createBodyModel();
mesh.getRoot().clearChild("head").clearRecursively();
return mesh;
}
@Override
public void setupAnim(VillagerRenderState state) {
super.setupAnim(state);
this.head.yRot = state.yRot * ((float)Math.PI / 180);
this.head.xRot = state.xRot * ((float)Math.PI / 180);
if (state.isUnhappy) {
this.head.zRot = 0.3f * Mth.sin(0.45f * state.ageInTicks);
this.head.xRot = 0.4f;
} else {
this.head.zRot = 0.0f;
}
this.rightLeg.xRot = Mth.cos(state.walkAnimationPos * 0.6662f) * 1.4f * state.walkAnimationSpeed * 0.5f;
this.leftLeg.xRot = Mth.cos(state.walkAnimationPos * 0.6662f + (float)Math.PI) * 1.4f * state.walkAnimationSpeed * 0.5f;
this.rightLeg.yRot = 0.0f;
this.leftLeg.yRot = 0.0f;
}
@Override
public ModelPart getHead() {
return this.head;
}
@Override
public void translateToArms(VillagerRenderState state, PoseStack outputPoseStack) {
this.root.translateAndRotate(outputPoseStack);
this.arms.translateAndRotate(outputPoseStack);
}
}