| 1 | package net.minecraft.client.model.monster.dragon;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.EntityModel;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.model.geom.PartPose;
|
| 8 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 9 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 10 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 12 | import net.minecraft.client.renderer.entity.state.EnderDragonRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 | import net.minecraft.world.entity.boss.enderdragon.DragonFlightHistory.Sample;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class EnderDragonModel extends EntityModel<EnderDragonRenderState> {
|
| 18 | private static final int NECK_PART_COUNT = 5;
|
| 19 | private static final int TAIL_PART_COUNT = 12;
|
| 20 | private final ModelPart head;
|
| 21 | private final ModelPart[] neckParts = new ModelPart[5];
|
| 22 | private final ModelPart[] tailParts = new ModelPart[12];
|
| 23 | private final ModelPart jaw;
|
| 24 | private final ModelPart body;
|
| 25 | private final ModelPart leftWing;
|
| 26 | private final ModelPart leftWingTip;
|
| 27 | private final ModelPart leftFrontLeg;
|
| 28 | private final ModelPart leftFrontLegTip;
|
| 29 | private final ModelPart leftFrontFoot;
|
| 30 | private final ModelPart leftRearLeg;
|
| 31 | private final ModelPart leftRearLegTip;
|
| 32 | private final ModelPart leftRearFoot;
|
| 33 | private final ModelPart rightWing;
|
| 34 | private final ModelPart rightWingTip;
|
| 35 | private final ModelPart rightFrontLeg;
|
| 36 | private final ModelPart rightFrontLegTip;
|
| 37 | private final ModelPart rightFrontFoot;
|
| 38 | private final ModelPart rightRearLeg;
|
| 39 | private final ModelPart rightRearLegTip;
|
| 40 | private final ModelPart rightRearFoot;
|
| 41 |
|
| 42 | private static String neckName(final int index) {
|
| 43 | return "neck" + index;
|
| 44 | }
|
| 45 |
|
| 46 | private static String tailName(final int index) {
|
| 47 | return "tail" + index;
|
| 48 | }
|
| 49 |
|
| 50 | public EnderDragonModel(final ModelPart root) {
|
| 51 | super(root);
|
| 52 | this.head = root.getChild("head");
|
| 53 | this.jaw = this.head.getChild("jaw");
|
| 54 |
|
| 55 | for (int i = 0; i < this.neckParts.length; i++) {
|
| 56 | this.neckParts[i] = root.getChild(neckName(i));
|
| 57 | }
|
| 58 |
|
| 59 | for (int i = 0; i < this.tailParts.length; i++) {
|
| 60 | this.tailParts[i] = root.getChild(tailName(i));
|
| 61 | }
|
| 62 |
|
| 63 | this.body = root.getChild("body");
|
| 64 | this.leftWing = this.body.getChild("left_wing");
|
| 65 | this.leftWingTip = this.leftWing.getChild("left_wing_tip");
|
| 66 | this.leftFrontLeg = this.body.getChild("left_front_leg");
|
| 67 | this.leftFrontLegTip = this.leftFrontLeg.getChild("left_front_leg_tip");
|
| 68 | this.leftFrontFoot = this.leftFrontLegTip.getChild("left_front_foot");
|
| 69 | this.leftRearLeg = this.body.getChild("left_hind_leg");
|
| 70 | this.leftRearLegTip = this.leftRearLeg.getChild("left_hind_leg_tip");
|
| 71 | this.leftRearFoot = this.leftRearLegTip.getChild("left_hind_foot");
|
| 72 | this.rightWing = this.body.getChild("right_wing");
|
| 73 | this.rightWingTip = this.rightWing.getChild("right_wing_tip");
|
| 74 | this.rightFrontLeg = this.body.getChild("right_front_leg");
|
| 75 | this.rightFrontLegTip = this.rightFrontLeg.getChild("right_front_leg_tip");
|
| 76 | this.rightFrontFoot = this.rightFrontLegTip.getChild("right_front_foot");
|
| 77 | this.rightRearLeg = this.body.getChild("right_hind_leg");
|
| 78 | this.rightRearLegTip = this.rightRearLeg.getChild("right_hind_leg_tip");
|
| 79 | this.rightRearFoot = this.rightRearLegTip.getChild("right_hind_foot");
|
| 80 | }
|
| 81 |
|
| 82 | public static LayerDefinition createBodyLayer() {
|
| 83 | MeshDefinition mesh = new MeshDefinition();
|
| 84 | PartDefinition root = mesh.getRoot();
|
| 85 | float zo = -16.0F;
|
| 86 | PartDefinition head = root.addOrReplaceChild(
|
| 87 | "head",
|
| 88 | CubeListBuilder.create()
|
| 89 | .addBox("upperlip", -6.0F, -1.0F, -24.0F, 12, 5, 16, 176, 44)
|
| 90 | .addBox("upperhead", -8.0F, -8.0F, -10.0F, 16, 16, 16, 112, 30)
|
| 91 | .mirror()
|
| 92 | .addBox("scale", -5.0F, -12.0F, -4.0F, 2, 4, 6, 0, 0)
|
| 93 | .addBox("nostril", -5.0F, -3.0F, -22.0F, 2, 2, 4, 112, 0)
|
| 94 | .mirror()
|
| 95 | .addBox("scale", 3.0F, -12.0F, -4.0F, 2, 4, 6, 0, 0)
|
| 96 | .addBox("nostril", 3.0F, -3.0F, -22.0F, 2, 2, 4, 112, 0),
|
| 97 | PartPose.offset(0.0F, 20.0F, -62.0F)
|
| 98 | );
|
| 99 | head.addOrReplaceChild("jaw", CubeListBuilder.create().addBox("jaw", -6.0F, 0.0F, -16.0F, 12, 4, 16, 176, 65), PartPose.offset(0.0F, 4.0F, -8.0F));
|
| 100 | CubeListBuilder spineCubes = CubeListBuilder.create()
|
| 101 | .addBox("box", -5.0F, -5.0F, -5.0F, 10, 10, 10, 192, 104)
|
| 102 | .addBox("scale", -1.0F, -9.0F, -3.0F, 2, 4, 6, 48, 0);
|
| 103 |
|
| 104 | for (int i = 0; i < 5; i++) {
|
| 105 | root.addOrReplaceChild(neckName(i), spineCubes, PartPose.offset(0.0F, 20.0F, -12.0F - i * 10.0F));
|
| 106 | }
|
| 107 |
|
| 108 | for (int i = 0; i < 12; i++) {
|
| 109 | root.addOrReplaceChild(tailName(i), spineCubes, PartPose.offset(0.0F, 10.0F, 60.0F + i * 10.0F));
|
| 110 | }
|
| 111 |
|
| 112 | PartDefinition body = root.addOrReplaceChild(
|
| 113 | "body",
|
| 114 | CubeListBuilder.create()
|
| 115 | .addBox("body", -12.0F, -16.0F, -16.0F, 24, 24, 64, 0, 0)
|
| 116 | .addBox("scale", -1.0F, -22.0F, -10.0F, 2, 6, 12, 220, 53)
|
| 117 | .addBox("scale", -1.0F, -22.0F, 10.0F, 2, 6, 12, 220, 53)
|
| 118 | .addBox("scale", -1.0F, -22.0F, 30.0F, 2, 6, 12, 220, 53),
|
| 119 | PartPose.offset(0.0F, 20.0F, 8.0F)
|
| 120 | );
|
| 121 | PartDefinition leftWing = body.addOrReplaceChild(
|
| 122 | "left_wing",
|
| 123 | CubeListBuilder.create().mirror().addBox("bone", 0.0F, -4.0F, -4.0F, 56, 8, 8, 112, 88).addBox("skin", 0.0F, 0.0F, 2.0F, 56, 0, 56, -56, 88),
|
| 124 | PartPose.offset(12.0F, -15.0F, -6.0F)
|
| 125 | );
|
| 126 | leftWing.addOrReplaceChild(
|
| 127 | "left_wing_tip",
|
| 128 | CubeListBuilder.create().mirror().addBox("bone", 0.0F, -2.0F, -2.0F, 56, 4, 4, 112, 136).addBox("skin", 0.0F, 0.0F, 2.0F, 56, 0, 56, -56, 144),
|
| 129 | PartPose.offset(56.0F, 0.0F, 0.0F)
|
| 130 | );
|
| 131 | PartDefinition leftFrontLeg = body.addOrReplaceChild(
|
| 132 | "left_front_leg",
|
| 133 | CubeListBuilder.create().addBox("main", -4.0F, -4.0F, -4.0F, 8, 24, 8, 112, 104),
|
| 134 | PartPose.offsetAndRotation(12.0F, 0.0F, -6.0F, 1.3F, 0.0F, 0.0F)
|
| 135 | );
|
| 136 | PartDefinition leftFrontLegTip = leftFrontLeg.addOrReplaceChild(
|
| 137 | "left_front_leg_tip",
|
| 138 | CubeListBuilder.create().addBox("main", -3.0F, -1.0F, -3.0F, 6, 24, 6, 226, 138),
|
| 139 | PartPose.offsetAndRotation(0.0F, 20.0F, -1.0F, -0.5F, 0.0F, 0.0F)
|
| 140 | );
|
| 141 | leftFrontLegTip.addOrReplaceChild(
|
| 142 | "left_front_foot",
|
| 143 | CubeListBuilder.create().addBox("main", -4.0F, 0.0F, -12.0F, 8, 4, 16, 144, 104),
|
| 144 | PartPose.offsetAndRotation(0.0F, 23.0F, 0.0F, 0.75F, 0.0F, 0.0F)
|
| 145 | );
|
| 146 | PartDefinition leftRearLeg = body.addOrReplaceChild(
|
| 147 | "left_hind_leg",
|
| 148 | CubeListBuilder.create().addBox("main", -8.0F, -4.0F, -8.0F, 16, 32, 16, 0, 0),
|
| 149 | PartPose.offsetAndRotation(16.0F, -4.0F, 34.0F, 1.0F, 0.0F, 0.0F)
|
| 150 | );
|
| 151 | PartDefinition leftRearLegTip = leftRearLeg.addOrReplaceChild(
|
| 152 | "left_hind_leg_tip",
|
| 153 | CubeListBuilder.create().addBox("main", -6.0F, -2.0F, 0.0F, 12, 32, 12, 196, 0),
|
| 154 | PartPose.offsetAndRotation(0.0F, 32.0F, -4.0F, 0.5F, 0.0F, 0.0F)
|
| 155 | );
|
| 156 | leftRearLegTip.addOrReplaceChild(
|
| 157 | "left_hind_foot",
|
| 158 | CubeListBuilder.create().addBox("main", -9.0F, 0.0F, -20.0F, 18, 6, 24, 112, 0),
|
| 159 | PartPose.offsetAndRotation(0.0F, 31.0F, 4.0F, 0.75F, 0.0F, 0.0F)
|
| 160 | );
|
| 161 | PartDefinition rightWing = body.addOrReplaceChild(
|
| 162 | "right_wing",
|
| 163 | CubeListBuilder.create().addBox("bone", -56.0F, -4.0F, -4.0F, 56, 8, 8, 112, 88).addBox("skin", -56.0F, 0.0F, 2.0F, 56, 0, 56, -56, 88),
|
| 164 | PartPose.offset(-12.0F, -15.0F, -6.0F)
|
| 165 | );
|
| 166 | rightWing.addOrReplaceChild(
|
| 167 | "right_wing_tip",
|
| 168 | CubeListBuilder.create().addBox("bone", -56.0F, -2.0F, -2.0F, 56, 4, 4, 112, 136).addBox("skin", -56.0F, 0.0F, 2.0F, 56, 0, 56, -56, 144),
|
| 169 | PartPose.offset(-56.0F, 0.0F, 0.0F)
|
| 170 | );
|
| 171 | PartDefinition rightFrontLeg = body.addOrReplaceChild(
|
| 172 | "right_front_leg",
|
| 173 | CubeListBuilder.create().addBox("main", -4.0F, -4.0F, -4.0F, 8, 24, 8, 112, 104),
|
| 174 | PartPose.offsetAndRotation(-12.0F, 0.0F, -6.0F, 1.3F, 0.0F, 0.0F)
|
| 175 | );
|
| 176 | PartDefinition rightFrontLegTip = rightFrontLeg.addOrReplaceChild(
|
| 177 | "right_front_leg_tip",
|
| 178 | CubeListBuilder.create().addBox("main", -3.0F, -1.0F, -3.0F, 6, 24, 6, 226, 138),
|
| 179 | PartPose.offsetAndRotation(0.0F, 20.0F, -1.0F, -0.5F, 0.0F, 0.0F)
|
| 180 | );
|
| 181 | rightFrontLegTip.addOrReplaceChild(
|
| 182 | "right_front_foot",
|
| 183 | CubeListBuilder.create().addBox("main", -4.0F, 0.0F, -12.0F, 8, 4, 16, 144, 104),
|
| 184 | PartPose.offsetAndRotation(0.0F, 23.0F, 0.0F, 0.75F, 0.0F, 0.0F)
|
| 185 | );
|
| 186 | PartDefinition rightRearLeg = body.addOrReplaceChild(
|
| 187 | "right_hind_leg",
|
| 188 | CubeListBuilder.create().addBox("main", -8.0F, -4.0F, -8.0F, 16, 32, 16, 0, 0),
|
| 189 | PartPose.offsetAndRotation(-16.0F, -4.0F, 34.0F, 1.0F, 0.0F, 0.0F)
|
| 190 | );
|
| 191 | PartDefinition rightRearLegTip = rightRearLeg.addOrReplaceChild(
|
| 192 | "right_hind_leg_tip",
|
| 193 | CubeListBuilder.create().addBox("main", -6.0F, -2.0F, 0.0F, 12, 32, 12, 196, 0),
|
| 194 | PartPose.offsetAndRotation(0.0F, 32.0F, -4.0F, 0.5F, 0.0F, 0.0F)
|
| 195 | );
|
| 196 | rightRearLegTip.addOrReplaceChild(
|
| 197 | "right_hind_foot",
|
| 198 | CubeListBuilder.create().addBox("main", -9.0F, 0.0F, -20.0F, 18, 6, 24, 112, 0),
|
| 199 | PartPose.offsetAndRotation(0.0F, 31.0F, 4.0F, 0.75F, 0.0F, 0.0F)
|
| 200 | );
|
| 201 | return LayerDefinition.create(mesh, 256, 256);
|
| 202 | }
|
| 203 |
|
| 204 | public void setupAnim(final EnderDragonRenderState state) {
|
| 205 | super.setupAnim(state);
|
| 206 | float flapTime = state.flapTime * (float) (Math.PI * 2);
|
| 207 | this.jaw.xRot = (Mth.sin(flapTime) + 1.0F) * 0.2F;
|
| 208 | float bounce = Mth.sin(flapTime - 1.0F) + 1.0F;
|
| 209 | bounce = (bounce * bounce + bounce * 2.0F) * 0.05F;
|
| 210 | this.root.y = (bounce - 2.0F) * 16.0F;
|
| 211 | this.root.z = -48.0F;
|
| 212 | this.root.xRot = bounce * 2.0F * (float) (Math.PI / 180.0);
|
| 213 | float xx = this.neckParts[0].x;
|
| 214 | float yy = this.neckParts[0].y;
|
| 215 | float zz = this.neckParts[0].z;
|
| 216 | float rotScale = 1.5F;
|
| 217 | Sample start = state.getHistoricalPos(6);
|
| 218 | float rot2 = Mth.wrapDegrees(state.getHistoricalPos(5).yRot() - state.getHistoricalPos(10).yRot());
|
| 219 | float rot = Mth.wrapDegrees(state.getHistoricalPos(5).yRot() + rot2 / 2.0F);
|
| 220 |
|
| 221 | for (int i = 0; i < 5; i++) {
|
| 222 | ModelPart neck = this.neckParts[i];
|
| 223 | Sample point = state.getHistoricalPos(5 - i);
|
| 224 | float neckXRot = Mth.cos(i * 0.45F + flapTime) * 0.15F;
|
| 225 | neck.yRot = Mth.wrapDegrees(point.yRot() - start.yRot()) * (float) (Math.PI / 180.0) * 1.5F;
|
| 226 | neck.xRot = neckXRot + state.getHeadPartYOffset(i, start, point) * (float) (Math.PI / 180.0) * 1.5F * 5.0F;
|
| 227 | neck.zRot = -Mth.wrapDegrees(point.yRot() - rot) * (float) (Math.PI / 180.0) * 1.5F;
|
| 228 | neck.y = yy;
|
| 229 | neck.z = zz;
|
| 230 | neck.x = xx;
|
| 231 | xx -= Mth.sin(neck.yRot) * Mth.cos(neck.xRot) * 10.0F;
|
| 232 | yy += Mth.sin(neck.xRot) * 10.0F;
|
| 233 | zz -= Mth.cos(neck.yRot) * Mth.cos(neck.xRot) * 10.0F;
|
| 234 | }
|
| 235 |
|
| 236 | this.head.y = yy;
|
| 237 | this.head.z = zz;
|
| 238 | this.head.x = xx;
|
| 239 | Sample current = state.getHistoricalPos(0);
|
| 240 | this.head.yRot = Mth.wrapDegrees(current.yRot() - start.yRot()) * (float) (Math.PI / 180.0);
|
| 241 | this.head.xRot = Mth.wrapDegrees(state.getHeadPartYOffset(6, start, current)) * (float) (Math.PI / 180.0) * 1.5F * 5.0F;
|
| 242 | this.head.zRot = -Mth.wrapDegrees(current.yRot() - rot) * (float) (Math.PI / 180.0);
|
| 243 | this.body.zRot = -rot2 * 1.5F * (float) (Math.PI / 180.0);
|
| 244 | this.leftWing.xRot = 0.125F - Mth.cos(flapTime) * 0.2F;
|
| 245 | this.leftWing.yRot = -0.25F;
|
| 246 | this.leftWing.zRot = -(Mth.sin(flapTime) + 0.125F) * 0.8F;
|
| 247 | this.leftWingTip.zRot = (Mth.sin(flapTime + 2.0F) + 0.5F) * 0.75F;
|
| 248 | this.rightWing.xRot = this.leftWing.xRot;
|
| 249 | this.rightWing.yRot = -this.leftWing.yRot;
|
| 250 | this.rightWing.zRot = -this.leftWing.zRot;
|
| 251 | this.rightWingTip.zRot = -this.leftWingTip.zRot;
|
| 252 | this.poseLimbs(bounce, this.leftFrontLeg, this.leftFrontLegTip, this.leftFrontFoot, this.leftRearLeg, this.leftRearLegTip, this.leftRearFoot);
|
| 253 | this.poseLimbs(bounce, this.rightFrontLeg, this.rightFrontLegTip, this.rightFrontFoot, this.rightRearLeg, this.rightRearLegTip, this.rightRearFoot);
|
| 254 | float tailXRot = 0.0F;
|
| 255 | yy = this.tailParts[0].y;
|
| 256 | zz = this.tailParts[0].z;
|
| 257 | xx = this.tailParts[0].x;
|
| 258 | start = state.getHistoricalPos(11);
|
| 259 |
|
| 260 | for (int i = 0; i < 12; i++) {
|
| 261 | Sample point = state.getHistoricalPos(12 + i);
|
| 262 | tailXRot += Mth.sin(i * 0.45F + flapTime) * 0.05F;
|
| 263 | ModelPart tail = this.tailParts[i];
|
| 264 | tail.yRot = (Mth.wrapDegrees(point.yRot() - start.yRot()) * 1.5F + 180.0F) * (float) (Math.PI / 180.0);
|
| 265 | tail.xRot = tailXRot + (float)(point.y() - start.y()) * (float) (Math.PI / 180.0) * 1.5F * 5.0F;
|
| 266 | tail.zRot = Mth.wrapDegrees(point.yRot() - rot) * (float) (Math.PI / 180.0) * 1.5F;
|
| 267 | tail.y = yy;
|
| 268 | tail.z = zz;
|
| 269 | tail.x = xx;
|
| 270 | yy += Mth.sin(tail.xRot) * 10.0F;
|
| 271 | zz -= Mth.cos(tail.yRot) * Mth.cos(tail.xRot) * 10.0F;
|
| 272 | xx -= Mth.sin(tail.yRot) * Mth.cos(tail.xRot) * 10.0F;
|
| 273 | }
|
| 274 | }
|
| 275 |
|
| 276 | private void poseLimbs(
|
| 277 | final float bounce,
|
| 278 | final ModelPart frontLeg,
|
| 279 | final ModelPart frontLegTip,
|
| 280 | final ModelPart frontFoot,
|
| 281 | final ModelPart rearLeg,
|
| 282 | final ModelPart rearLegTip,
|
| 283 | final ModelPart rearFoot
|
| 284 | ) {
|
| 285 | rearLeg.xRot = 1.0F + bounce * 0.1F;
|
| 286 | rearLegTip.xRot = 0.5F + bounce * 0.1F;
|
| 287 | rearFoot.xRot = 0.75F + bounce * 0.1F;
|
| 288 | frontLeg.xRot = 1.3F + bounce * 0.1F;
|
| 289 | frontLegTip.xRot = -0.5F - bounce * 0.1F;
|
| 290 | frontFoot.xRot = 0.75F + bounce * 0.1F;
|
| 291 | }
|
| 292 | }
|
| 293 |
|