| 1 | package net.minecraft.client.model.effects;
|
| 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.EvokerFangsRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class EvokerFangsModel extends EntityModel<EvokerFangsRenderState> {
|
| 17 | private static final String BASE = "base";
|
| 18 | private static final String UPPER_JAW = "upper_jaw";
|
| 19 | private static final String LOWER_JAW = "lower_jaw";
|
| 20 | private final ModelPart base;
|
| 21 | private final ModelPart upperJaw;
|
| 22 | private final ModelPart lowerJaw;
|
| 23 |
|
| 24 | public EvokerFangsModel(final ModelPart root) {
|
| 25 | super(root);
|
| 26 | this.base = root.getChild("base");
|
| 27 | this.upperJaw = this.base.getChild("upper_jaw");
|
| 28 | this.lowerJaw = this.base.getChild("lower_jaw");
|
| 29 | }
|
| 30 |
|
| 31 | public static LayerDefinition createBodyLayer() {
|
| 32 | MeshDefinition mesh = new MeshDefinition();
|
| 33 | PartDefinition root = mesh.getRoot();
|
| 34 | PartDefinition base = root.addOrReplaceChild(
|
| 35 | "base", CubeListBuilder.create().texOffs(0, 0).addBox(0.0F, 0.0F, 0.0F, 10.0F, 12.0F, 10.0F), PartPose.offset(-5.0F, 24.0F, -5.0F)
|
| 36 | );
|
| 37 | CubeListBuilder jaw = CubeListBuilder.create().texOffs(40, 0).addBox(0.0F, 0.0F, 0.0F, 4.0F, 14.0F, 8.0F);
|
| 38 | base.addOrReplaceChild("upper_jaw", jaw, PartPose.offsetAndRotation(6.5F, 0.0F, 1.0F, 0.0F, 0.0F, 2.042035F));
|
| 39 | base.addOrReplaceChild("lower_jaw", jaw, PartPose.offsetAndRotation(3.5F, 0.0F, 9.0F, 0.0F, (float) Math.PI, 4.2411504F));
|
| 40 | return LayerDefinition.create(mesh, 64, 32);
|
| 41 | }
|
| 42 |
|
| 43 | public void setupAnim(final EvokerFangsRenderState state) {
|
| 44 | super.setupAnim(state);
|
| 45 | float biteProgress = state.biteProgress;
|
| 46 | float biteAmount = Math.min(biteProgress * 2.0F, 1.0F);
|
| 47 | biteAmount = 1.0F - biteAmount * biteAmount * biteAmount;
|
| 48 | this.upperJaw.zRot = (float) Math.PI - biteAmount * 0.35F * (float) Math.PI;
|
| 49 | this.lowerJaw.zRot = (float) Math.PI + biteAmount * 0.35F * (float) Math.PI;
|
| 50 | this.base.y = this.base.y - (biteProgress + Mth.sin(biteProgress * 2.7F)) * 7.2F;
|
| 51 | float preScale = 1.0F;
|
| 52 | if (biteProgress > 0.9F) {
|
| 53 | preScale *= (1.0F - biteProgress) / 0.1F;
|
| 54 | }
|
| 55 |
|
| 56 | this.root.y = 24.0F - 20.0F * preScale;
|
| 57 | this.root.xScale = preScale;
|
| 58 | this.root.yScale = preScale;
|
| 59 | this.root.zScale = preScale;
|
| 60 | }
|
| 61 | }
|
| 62 |
|