183 lines
7.9 KiB
Java
183 lines
7.9 KiB
Java
package net.minecraft.client.model;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
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.client.renderer.entity.state.IllagerRenderState;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.entity.HumanoidArm;
|
|
import net.minecraft.world.entity.monster.AbstractIllager;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class IllagerModel<S extends IllagerRenderState> extends EntityModel<S> implements ArmedModel, HeadedModel {
|
|
private final ModelPart head;
|
|
private final ModelPart hat;
|
|
private final ModelPart arms;
|
|
private final ModelPart leftLeg;
|
|
private final ModelPart rightLeg;
|
|
private final ModelPart rightArm;
|
|
private final ModelPart leftArm;
|
|
|
|
public IllagerModel(ModelPart root) {
|
|
super(root);
|
|
this.head = root.getChild("head");
|
|
this.hat = this.head.getChild("hat");
|
|
this.hat.visible = false;
|
|
this.arms = root.getChild("arms");
|
|
this.leftLeg = root.getChild("left_leg");
|
|
this.rightLeg = root.getChild("right_leg");
|
|
this.leftArm = root.getChild("left_arm");
|
|
this.rightArm = root.getChild("right_arm");
|
|
}
|
|
|
|
public static LayerDefinition createBodyLayer() {
|
|
MeshDefinition meshDefinition = new MeshDefinition();
|
|
PartDefinition partDefinition = meshDefinition.getRoot();
|
|
PartDefinition partDefinition2 = partDefinition.addOrReplaceChild(
|
|
"head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -10.0F, -4.0F, 8.0F, 10.0F, 8.0F), PartPose.offset(0.0F, 0.0F, 0.0F)
|
|
);
|
|
partDefinition2.addOrReplaceChild(
|
|
"hat", CubeListBuilder.create().texOffs(32, 0).addBox(-4.0F, -10.0F, -4.0F, 8.0F, 12.0F, 8.0F, new CubeDeformation(0.45F)), PartPose.ZERO
|
|
);
|
|
partDefinition2.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.addOrReplaceChild(
|
|
"body",
|
|
CubeListBuilder.create()
|
|
.texOffs(16, 20)
|
|
.addBox(-4.0F, 0.0F, -3.0F, 8.0F, 12.0F, 6.0F)
|
|
.texOffs(0, 38)
|
|
.addBox(-4.0F, 0.0F, -3.0F, 8.0F, 20.0F, 6.0F, new CubeDeformation(0.5F)),
|
|
PartPose.offset(0.0F, 0.0F, 0.0F)
|
|
);
|
|
PartDefinition partDefinition3 = partDefinition.addOrReplaceChild(
|
|
"arms",
|
|
CubeListBuilder.create().texOffs(44, 22).addBox(-8.0F, -2.0F, -2.0F, 4.0F, 8.0F, 4.0F).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)
|
|
);
|
|
partDefinition3.addOrReplaceChild(
|
|
"left_shoulder", CubeListBuilder.create().texOffs(44, 22).mirror().addBox(4.0F, -2.0F, -2.0F, 4.0F, 8.0F, 4.0F), PartPose.ZERO
|
|
);
|
|
partDefinition.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)
|
|
);
|
|
partDefinition.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)
|
|
);
|
|
partDefinition.addOrReplaceChild(
|
|
"right_arm", CubeListBuilder.create().texOffs(40, 46).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(-5.0F, 2.0F, 0.0F)
|
|
);
|
|
partDefinition.addOrReplaceChild(
|
|
"left_arm", CubeListBuilder.create().texOffs(40, 46).mirror().addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(5.0F, 2.0F, 0.0F)
|
|
);
|
|
return LayerDefinition.create(meshDefinition, 64, 64);
|
|
}
|
|
|
|
public void setupAnim(S illagerRenderState) {
|
|
super.setupAnim(illagerRenderState);
|
|
this.head.yRot = illagerRenderState.yRot * (float) (Math.PI / 180.0);
|
|
this.head.xRot = illagerRenderState.xRot * (float) (Math.PI / 180.0);
|
|
if (illagerRenderState.isRiding) {
|
|
this.rightArm.xRot = (float) (-Math.PI / 5);
|
|
this.rightArm.yRot = 0.0F;
|
|
this.rightArm.zRot = 0.0F;
|
|
this.leftArm.xRot = (float) (-Math.PI / 5);
|
|
this.leftArm.yRot = 0.0F;
|
|
this.leftArm.zRot = 0.0F;
|
|
this.rightLeg.xRot = -1.4137167F;
|
|
this.rightLeg.yRot = (float) (Math.PI / 10);
|
|
this.rightLeg.zRot = 0.07853982F;
|
|
this.leftLeg.xRot = -1.4137167F;
|
|
this.leftLeg.yRot = (float) (-Math.PI / 10);
|
|
this.leftLeg.zRot = -0.07853982F;
|
|
} else {
|
|
float f = illagerRenderState.walkAnimationSpeed;
|
|
float g = illagerRenderState.walkAnimationPos;
|
|
this.rightArm.xRot = Mth.cos(g * 0.6662F + (float) Math.PI) * 2.0F * f * 0.5F;
|
|
this.rightArm.yRot = 0.0F;
|
|
this.rightArm.zRot = 0.0F;
|
|
this.leftArm.xRot = Mth.cos(g * 0.6662F) * 2.0F * f * 0.5F;
|
|
this.leftArm.yRot = 0.0F;
|
|
this.leftArm.zRot = 0.0F;
|
|
this.rightLeg.xRot = Mth.cos(g * 0.6662F) * 1.4F * f * 0.5F;
|
|
this.rightLeg.yRot = 0.0F;
|
|
this.rightLeg.zRot = 0.0F;
|
|
this.leftLeg.xRot = Mth.cos(g * 0.6662F + (float) Math.PI) * 1.4F * f * 0.5F;
|
|
this.leftLeg.yRot = 0.0F;
|
|
this.leftLeg.zRot = 0.0F;
|
|
}
|
|
|
|
AbstractIllager.IllagerArmPose illagerArmPose = illagerRenderState.armPose;
|
|
if (illagerArmPose == AbstractIllager.IllagerArmPose.ATTACKING) {
|
|
if (illagerRenderState.getMainHandItem().isEmpty()) {
|
|
AnimationUtils.animateZombieArms(this.leftArm, this.rightArm, true, illagerRenderState.attackAnim, illagerRenderState.ageInTicks);
|
|
} else {
|
|
AnimationUtils.swingWeaponDown(this.rightArm, this.leftArm, illagerRenderState.mainArm, illagerRenderState.attackAnim, illagerRenderState.ageInTicks);
|
|
}
|
|
} else if (illagerArmPose == AbstractIllager.IllagerArmPose.SPELLCASTING) {
|
|
this.rightArm.z = 0.0F;
|
|
this.rightArm.x = -5.0F;
|
|
this.leftArm.z = 0.0F;
|
|
this.leftArm.x = 5.0F;
|
|
this.rightArm.xRot = Mth.cos(illagerRenderState.ageInTicks * 0.6662F) * 0.25F;
|
|
this.leftArm.xRot = Mth.cos(illagerRenderState.ageInTicks * 0.6662F) * 0.25F;
|
|
this.rightArm.zRot = (float) (Math.PI * 3.0 / 4.0);
|
|
this.leftArm.zRot = (float) (-Math.PI * 3.0 / 4.0);
|
|
this.rightArm.yRot = 0.0F;
|
|
this.leftArm.yRot = 0.0F;
|
|
} else if (illagerArmPose == AbstractIllager.IllagerArmPose.BOW_AND_ARROW) {
|
|
this.rightArm.yRot = -0.1F + this.head.yRot;
|
|
this.rightArm.xRot = (float) (-Math.PI / 2) + this.head.xRot;
|
|
this.leftArm.xRot = -0.9424779F + this.head.xRot;
|
|
this.leftArm.yRot = this.head.yRot - 0.4F;
|
|
this.leftArm.zRot = (float) (Math.PI / 2);
|
|
} else if (illagerArmPose == AbstractIllager.IllagerArmPose.CROSSBOW_HOLD) {
|
|
AnimationUtils.animateCrossbowHold(this.rightArm, this.leftArm, this.head, true);
|
|
} else if (illagerArmPose == AbstractIllager.IllagerArmPose.CROSSBOW_CHARGE) {
|
|
AnimationUtils.animateCrossbowCharge(this.rightArm, this.leftArm, illagerRenderState.maxCrossbowChargeDuration, illagerRenderState.ticksUsingItem, true);
|
|
} else if (illagerArmPose == AbstractIllager.IllagerArmPose.CELEBRATING) {
|
|
this.rightArm.z = 0.0F;
|
|
this.rightArm.x = -5.0F;
|
|
this.rightArm.xRot = Mth.cos(illagerRenderState.ageInTicks * 0.6662F) * 0.05F;
|
|
this.rightArm.zRot = 2.670354F;
|
|
this.rightArm.yRot = 0.0F;
|
|
this.leftArm.z = 0.0F;
|
|
this.leftArm.x = 5.0F;
|
|
this.leftArm.xRot = Mth.cos(illagerRenderState.ageInTicks * 0.6662F) * 0.05F;
|
|
this.leftArm.zRot = (float) (-Math.PI * 3.0 / 4.0);
|
|
this.leftArm.yRot = 0.0F;
|
|
}
|
|
|
|
boolean bl = illagerArmPose == AbstractIllager.IllagerArmPose.CROSSED;
|
|
this.arms.visible = bl;
|
|
this.leftArm.visible = !bl;
|
|
this.rightArm.visible = !bl;
|
|
}
|
|
|
|
private ModelPart getArm(HumanoidArm arm) {
|
|
return arm == HumanoidArm.LEFT ? this.leftArm : this.rightArm;
|
|
}
|
|
|
|
public ModelPart getHat() {
|
|
return this.hat;
|
|
}
|
|
|
|
@Override
|
|
public ModelPart getHead() {
|
|
return this.head;
|
|
}
|
|
|
|
@Override
|
|
public void translateToHand(HumanoidArm side, PoseStack poseStack) {
|
|
this.root.translateAndRotate(poseStack);
|
|
this.getArm(side).translateAndRotate(poseStack);
|
|
}
|
|
}
|