| 1 | package net.minecraft.client.model.monster.vex;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.model.ArmedModel;
|
| 7 | import net.minecraft.client.model.EntityModel;
|
| 8 | import net.minecraft.client.model.geom.ModelPart;
|
| 9 | import net.minecraft.client.model.geom.PartPose;
|
| 10 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 11 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 12 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 13 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 14 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 15 | import net.minecraft.client.renderer.entity.state.VexRenderState;
|
| 16 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 17 | import net.minecraft.util.Mth;
|
| 18 | import net.minecraft.world.entity.HumanoidArm;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public class VexModel extends EntityModel<VexRenderState> implements ArmedModel<VexRenderState> {
|
| 22 | private final ModelPart body = this.root.getChild("body");
|
| 23 | private final ModelPart rightArm = this.body.getChild("right_arm");
|
| 24 | private final ModelPart leftArm = this.body.getChild("left_arm");
|
| 25 | private final ModelPart rightWing = this.body.getChild("right_wing");
|
| 26 | private final ModelPart leftWing = this.body.getChild("left_wing");
|
| 27 | private final ModelPart head = this.root.getChild("head");
|
| 28 |
|
| 29 | public VexModel(final ModelPart root) {
|
| 30 | super(root.getChild("root"), RenderTypes::entityTranslucent);
|
| 31 | }
|
| 32 |
|
| 33 | public static LayerDefinition createBodyLayer() {
|
| 34 | MeshDefinition meshdefinition = new MeshDefinition();
|
| 35 | PartDefinition partdefinition = meshdefinition.getRoot();
|
| 36 | PartDefinition root = partdefinition.addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(0.0F, -2.5F, 0.0F));
|
| 37 | root.addOrReplaceChild(
|
| 38 | "head", CubeListBuilder.create().texOffs(0, 0).addBox(-2.5F, -5.0F, -2.5F, 5.0F, 5.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 20.0F, 0.0F)
|
| 39 | );
|
| 40 | PartDefinition body = root.addOrReplaceChild(
|
| 41 | "body",
|
| 42 | CubeListBuilder.create()
|
| 43 | .texOffs(0, 10)
|
| 44 | .addBox(-1.5F, 0.0F, -1.0F, 3.0F, 4.0F, 2.0F, new CubeDeformation(0.0F))
|
| 45 | .texOffs(0, 16)
|
| 46 | .addBox(-1.5F, 1.0F, -1.0F, 3.0F, 5.0F, 2.0F, new CubeDeformation(-0.2F)),
|
| 47 | PartPose.offset(0.0F, 20.0F, 0.0F)
|
| 48 | );
|
| 49 | body.addOrReplaceChild(
|
| 50 | "right_arm",
|
| 51 | CubeListBuilder.create().texOffs(23, 0).addBox(-1.25F, -0.5F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(-0.1F)),
|
| 52 | PartPose.offset(-1.75F, 0.25F, 0.0F)
|
| 53 | );
|
| 54 | body.addOrReplaceChild(
|
| 55 | "left_arm",
|
| 56 | CubeListBuilder.create().texOffs(23, 6).addBox(-0.75F, -0.5F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(-0.1F)),
|
| 57 | PartPose.offset(1.75F, 0.25F, 0.0F)
|
| 58 | );
|
| 59 | body.addOrReplaceChild(
|
| 60 | "left_wing",
|
| 61 | CubeListBuilder.create().texOffs(16, 14).mirror().addBox(0.0F, 0.0F, 0.0F, 0.0F, 5.0F, 8.0F, new CubeDeformation(0.0F)).mirror(false),
|
| 62 | PartPose.offset(0.5F, 1.0F, 1.0F)
|
| 63 | );
|
| 64 | body.addOrReplaceChild(
|
| 65 | "right_wing",
|
| 66 | CubeListBuilder.create().texOffs(16, 14).addBox(0.0F, 0.0F, 0.0F, 0.0F, 5.0F, 8.0F, new CubeDeformation(0.0F)),
|
| 67 | PartPose.offset(-0.5F, 1.0F, 1.0F)
|
| 68 | );
|
| 69 | return LayerDefinition.create(meshdefinition, 32, 32);
|
| 70 | }
|
| 71 |
|
| 72 | public void setupAnim(final VexRenderState state) {
|
| 73 | super.setupAnim(state);
|
| 74 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 75 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 76 | float movingArmZBob = Mth.cos(state.ageInTicks * 5.5F * (float) (Math.PI / 180.0)) * 0.1F;
|
| 77 | this.rightArm.zRot = (float) (Math.PI / 5) + movingArmZBob;
|
| 78 | this.leftArm.zRot = -((float) (Math.PI / 5) + movingArmZBob);
|
| 79 | if (state.isCharging) {
|
| 80 | this.body.xRot = 0.0F;
|
| 81 | this.setArmsCharging(!state.rightHandItemState.isEmpty(), !state.leftHandItemState.isEmpty(), movingArmZBob);
|
| 82 | } else {
|
| 83 | this.body.xRot = (float) (Math.PI / 20);
|
| 84 | }
|
| 85 |
|
| 86 | this.leftWing.yRot = 1.0995574F + Mth.cos(state.ageInTicks * 45.836624F * (float) (Math.PI / 180.0)) * (float) (Math.PI / 180.0) * 16.2F;
|
| 87 | this.rightWing.yRot = -this.leftWing.yRot;
|
| 88 | this.leftWing.xRot = 0.47123888F;
|
| 89 | this.leftWing.zRot = -0.47123888F;
|
| 90 | this.rightWing.xRot = 0.47123888F;
|
| 91 | this.rightWing.zRot = 0.47123888F;
|
| 92 | }
|
| 93 |
|
| 94 | private void setArmsCharging(final boolean hasItemInRightHand, final boolean hasItemInLeftHand, final float movingArmZBob) {
|
| 95 | if (!hasItemInRightHand && !hasItemInLeftHand) {
|
| 96 | this.rightArm.xRot = -1.2217305F;
|
| 97 | this.rightArm.yRot = (float) (Math.PI / 12);
|
| 98 | this.rightArm.zRot = -0.47123888F - movingArmZBob;
|
| 99 | this.leftArm.xRot = -1.2217305F;
|
| 100 | this.leftArm.yRot = (float) (-Math.PI / 12);
|
| 101 | this.leftArm.zRot = 0.47123888F + movingArmZBob;
|
| 102 | } else {
|
| 103 | if (hasItemInRightHand) {
|
| 104 | this.rightArm.xRot = (float) (Math.PI * 7.0 / 6.0);
|
| 105 | this.rightArm.yRot = (float) (Math.PI / 12);
|
| 106 | this.rightArm.zRot = -0.47123888F - movingArmZBob;
|
| 107 | }
|
| 108 |
|
| 109 | if (hasItemInLeftHand) {
|
| 110 | this.leftArm.xRot = (float) (Math.PI * 7.0 / 6.0);
|
| 111 | this.leftArm.yRot = (float) (-Math.PI / 12);
|
| 112 | this.leftArm.zRot = 0.47123888F + movingArmZBob;
|
| 113 | }
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | public void translateToHand(final VexRenderState state, final HumanoidArm arm, final PoseStack poseStack) {
|
| 118 | boolean mainArm = arm == HumanoidArm.RIGHT;
|
| 119 | ModelPart activeArm = mainArm ? this.rightArm : this.leftArm;
|
| 120 | this.root.translateAndRotate(poseStack);
|
| 121 | this.body.translateAndRotate(poseStack);
|
| 122 | activeArm.translateAndRotate(poseStack);
|
| 123 | poseStack.scale(0.55F, 0.55F, 0.55F);
|
| 124 | this.offsetStackPosition(poseStack, mainArm);
|
| 125 | }
|
| 126 |
|
| 127 | private void offsetStackPosition(final PoseStack poseStack, final boolean mainArm) {
|
| 128 | if (mainArm) {
|
| 129 | poseStack.translate(0.046875, -0.15625, 0.078125);
|
| 130 | } else {
|
| 131 | poseStack.translate(-0.046875, -0.15625, 0.078125);
|
| 132 | }
|
| 133 | }
|
| 134 | }
|
| 135 |
|