jayhillx

SeaOtterModel

Aug 29th, 2025
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.33 KB | None | 0 0
  1. package com.mysticsbiomes.client.entity.model;
  2.  
  3. import com.mojang.blaze3d.vertex.PoseStack;
  4. import com.mojang.blaze3d.vertex.VertexConsumer;
  5. import com.mysticsbiomes.common.entity.SeaOtter;
  6. import net.minecraft.client.model.HierarchicalModel;
  7. import net.minecraft.client.model.geom.ModelPart;
  8. import net.minecraft.client.model.geom.PartPose;
  9. import net.minecraft.client.model.geom.builders.*;
  10. import net.minecraftforge.api.distmarker.Dist;
  11. import net.minecraftforge.api.distmarker.OnlyIn;
  12.  
  13. @OnlyIn(Dist.CLIENT)
  14. public class SeaOtterModel<T extends SeaOtter> extends HierarchicalModel<T> {
  15.     private final ModelPart root;
  16.     private final ModelPart neckRoot;
  17.     private final ModelPart neck;
  18.     private final ModelPart head;
  19.     private final ModelPart leftWhiskers;
  20.     private final ModelPart rightWhiskers;
  21.     private final ModelPart bodyRoot;
  22.     private final ModelPart upperTorsoRoot;
  23.     private final ModelPart upperTorso;
  24.     private final ModelPart leftArm;
  25.     private final ModelPart rightArm;
  26.     private final ModelPart lowerTorsoRoot;
  27.     private final ModelPart lowerTorso;
  28.     private final ModelPart leftLeg;
  29.     private final ModelPart leftHip;
  30.     private final ModelPart leftFlipper;
  31.     private final ModelPart rightLeg;
  32.     private final ModelPart rightHip;
  33.     private final ModelPart rightFlipper;
  34.     private final ModelPart tail;
  35.     private final ModelPart[] bodySegments;
  36.     float[] baseRotX;
  37.     float[] baseRotY;
  38.     float[] baseRotZ;
  39.     float[] offsetRotX;
  40.     float[] offsetRotY;
  41.     float[] offsetRotZ;
  42.  
  43.     public SeaOtterModel(ModelPart root) {
  44.         this.root = root.getChild("root");
  45.         /// head
  46.         this.neckRoot = this.root.getChild("neck_root");
  47.         this.neck = this.neckRoot.getChild("neck");
  48.         this.head = this.neckRoot.getChild("head");
  49.         this.leftWhiskers = this.head.getChild("left_whiskers");
  50.         this.rightWhiskers = this.head.getChild("right_whiskers");
  51.         /// body
  52.         this.bodyRoot = this.root.getChild("body_root");
  53.         /// segment 1
  54.         this.upperTorsoRoot = this.bodyRoot.getChild("upper_torso_root");
  55.         this.upperTorso = this.upperTorsoRoot.getChild("upper_torso");
  56.         this.leftArm = this.upperTorsoRoot.getChild("left_arm");
  57.         this.rightArm = this.upperTorsoRoot.getChild("right_arm");
  58.         /// segment 2
  59.         this.lowerTorsoRoot = this.upperTorsoRoot.getChild("lower_torso_root");
  60.         this.lowerTorso = this.lowerTorsoRoot.getChild("lower_torso");
  61.         this.leftLeg = this.lowerTorsoRoot.getChild("left_leg");
  62.         this.leftHip = this.leftLeg.getChild("left_hip");
  63.         this.leftFlipper = this.leftHip.getChild("left_flipper");
  64.         this.rightLeg = this.lowerTorsoRoot.getChild("right_leg");
  65.         this.rightHip = this.rightLeg.getChild("right_hip");
  66.         this.rightFlipper = this.rightHip.getChild("right_flipper");
  67.         /// segment 3
  68.         this.tail = this.lowerTorsoRoot.getChild("tail");
  69.  
  70.         this.bodySegments = new ModelPart[]{this.upperTorsoRoot, this.lowerTorsoRoot, this.tail};
  71.         this.baseRotX = new float[this.bodySegments.length];
  72.         this.baseRotY = new float[this.bodySegments.length];
  73.         this.baseRotZ = new float[this.bodySegments.length];
  74.         this.offsetRotX = new float[this.bodySegments.length];
  75.         this.offsetRotY = new float[this.bodySegments.length];
  76.         this.offsetRotZ = new float[this.bodySegments.length];
  77.  
  78.         for (int i = 0; i < this.bodySegments.length; i++) {
  79.             this.baseRotX[i] = this.bodySegments[i].xRot;
  80.             this.baseRotY[i] = this.bodySegments[i].yRot;
  81.             this.baseRotZ[i] = this.bodySegments[i].zRot;
  82.         }
  83.     }
  84.  
  85.     public static LayerDefinition createBodyLayer() {
  86.         MeshDefinition mesh = new MeshDefinition();
  87.         PartDefinition root = mesh.getRoot().addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(0.0F, 18.5F, -0.1F));
  88.         PartDefinition neckRoot = root.addOrReplaceChild("neck_root", CubeListBuilder.create(), PartPose.offset(0.0F, -2.5F, -5.9F));
  89.         PartDefinition neck = neckRoot.addOrReplaceChild("neck", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
  90.         neck.addOrReplaceChild("neck_r1", CubeListBuilder.create().texOffs(44, 0).addBox(-3.0F, 0.0F, -4.0F, 6.0F, 6.0F, 4.0F, new CubeDeformation(-0.009F)), PartPose.offsetAndRotation(0.0F, 0.0F, -6.0F, 1.5708F, 0.0F, 0.0F));
  91.         PartDefinition headRoot = neckRoot.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-3.0F, -5.0F, -5.0F, 6.0F, 5.0F, 5.0F, new CubeDeformation(0.009F)).texOffs(25, 5).addBox(-2.0F, -3.0F, -6.0F, 4.0F, 3.0F, 1.0F, new CubeDeformation(0.009F)).texOffs(26, 11).addBox(-1.0F, -3.5F, -6.1F, 2.0F, 2.0F, 1.0F, new CubeDeformation(0.009F)), PartPose.offsetAndRotation(0.0F, 0.0F, -6.0F, 1.5708F, 0.0F, 0.0F));
  92.         headRoot.addOrReplaceChild("left_whiskers", CubeListBuilder.create().texOffs(36, 6).addBox(0.0F, -2.5F, 0.0F, 2.0F, 4.0F, 0.0F, new CubeDeformation(0.009F)), PartPose.offset(2.0F, -1.5F, -5.5F));
  93.         headRoot.addOrReplaceChild("right_whiskers", CubeListBuilder.create().texOffs(36, 6).mirror().addBox(-2.0F, -2.5F, 0.0F, 2.0F, 4.0F, 0.0F, new CubeDeformation(0.009F)).mirror(false), PartPose.offset(-2.0F, -1.5F, -5.5F));
  94.         PartDefinition bodyRoot = root.addOrReplaceChild("body_root", CubeListBuilder.create(), PartPose.offset(0.0F, -0.5F, -5.9F));
  95.         PartDefinition upperTorsoRoot = bodyRoot.addOrReplaceChild("upper_torso_root", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
  96.         PartDefinition upperTorso = upperTorsoRoot.addOrReplaceChild("upper_torso", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
  97.         upperTorso.addOrReplaceChild("upper_torso_r1", CubeListBuilder.create().texOffs(0, 11).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 6.0F, 6.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 1.0F, 0.0F, 1.5708F, 0.0F, 0.0F));
  98.         upperTorsoRoot.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(56, 19).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(1.9F, 2.0F, 1.1F));
  99.         upperTorsoRoot.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(56, 19).mirror().addBox(-1.0F, 0.0F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-1.9F, 2.0F, 1.1F));
  100.         PartDefinition lowerTorsoRoot = upperTorsoRoot.addOrReplaceChild("lower_torso_root", CubeListBuilder.create(), PartPose.offset(0.0F, 1.0F, 6.0F));
  101.         PartDefinition lowerTorso = lowerTorsoRoot.addOrReplaceChild("lower_torso", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
  102.         lowerTorso.addOrReplaceChild("lower_torso_r1", CubeListBuilder.create().texOffs(0, 24).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 7.0F, 6.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 1.5708F, 0.0F, 0.0F));
  103.         PartDefinition leftLeg = lowerTorsoRoot.addOrReplaceChild("left_leg", CubeListBuilder.create(), PartPose.offset(2.0F, 1.5F, 4.5F));
  104.         PartDefinition leftHip = leftLeg.addOrReplaceChild("left_hip", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
  105.         leftHip.addOrReplaceChild("left_hip_r1", CubeListBuilder.create().texOffs(41, 11).addBox(-2.0F, -1.5F, -1.5F, 4.0F, 4.0F, 3.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, 1.5708F, 0.0F));
  106.         PartDefinition leftFlipper = leftHip.addOrReplaceChild("left_flipper", CubeListBuilder.create(), PartPose.offset(0.0F, 2.5F, 2.0F));
  107.         leftFlipper.addOrReplaceChild("left_flipper_r1", CubeListBuilder.create().texOffs(56, 11).addBox(-1.5F, 0.0F, 0.0F, 3.0F, 6.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, -1.5708F, 0.0F, 0.0F));
  108.         PartDefinition rightLeg = lowerTorsoRoot.addOrReplaceChild("right_leg", CubeListBuilder.create(), PartPose.offset(-2.0F, 1.5F, 5.0F));
  109.         PartDefinition rightHip = rightLeg.addOrReplaceChild("right_hip", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, -0.5F));
  110.         rightHip.addOrReplaceChild("right_hip_r1", CubeListBuilder.create().texOffs(41, 11).mirror().addBox(-2.0F, -1.5F, -1.5F, 4.0F, 4.0F, 3.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, -1.5708F, 0.0F));
  111.         PartDefinition rightFlipper = rightHip.addOrReplaceChild("right_flipper", CubeListBuilder.create(), PartPose.offset(0.0F, 2.5F, 2.0F));
  112.         rightFlipper.addOrReplaceChild("right_flipper_r1", CubeListBuilder.create().texOffs(56, 11).mirror().addBox(-1.5F, 0.0F, 0.0F, 3.0F, 6.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, -1.5708F, 0.0F, 0.0F));
  113.         PartDefinition tail = lowerTorsoRoot.addOrReplaceChild("tail", CubeListBuilder.create(), PartPose.offset(0.0F, -1.5F, 7.0F));
  114.         tail.addOrReplaceChild("tail_r1", CubeListBuilder.create().texOffs(25, 27).addBox(-1.0F, 0.0F, -1.5F, 2.0F, 7.0F, 3.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 1.5708F, 0.0F, 0.0F));
  115.         return LayerDefinition.create(mesh, 64, 48);
  116.     }
  117.  
  118.     @Override
  119.     public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
  120.         this.root().getAllParts().forEach(ModelPart::resetPose);
  121.  
  122.         float headYawTarget = netHeadYaw * ((float)Math.PI / 180F);
  123.         float headPitchTarget = headPitch * ((float)Math.PI / 180F);
  124.         this.head.yRot = headYawTarget;
  125.         this.head.xRot = headPitchTarget;
  126.         this.neck.visible = entity.isFloating();
  127.  
  128.         float swimSpeed = (float) entity.getDeltaMovement().length();
  129.         float turnAmount = netHeadYaw - entity.prevHeadYaw;
  130.  
  131.         final float MAX_BEND_Y = (float)Math.toRadians(25);
  132.         final float MAX_BEND_X = (float)Math.toRadians(15);
  133.         final float RELAX_SPEED = 0.1F;
  134.  
  135.         for (int i = 0; i < this.bodySegments.length; i++) {
  136.             ModelPart seg = this.bodySegments[i];
  137.  
  138.             float waveY = (float)Math.sin(ageInTicks * 0.2 + i * 0.6) * swimSpeed * 0.3F;
  139.             float turnBend = turnAmount * 0.5F * ((i + 1) / (float) this.bodySegments.length);
  140.  
  141.             float totalY = waveY + turnBend;
  142.             totalY = Math.max(-MAX_BEND_Y, Math.min(MAX_BEND_Y, totalY));
  143.  
  144.             float waveX = (float)Math.cos(ageInTicks * 0.25F + i * 0.4F) * swimSpeed * 0.1F;
  145.             waveX = Math.max(-MAX_BEND_X, Math.min(MAX_BEND_X, waveX));
  146.  
  147.             this.offsetRotY[i] += (totalY - this.offsetRotY[i]) * RELAX_SPEED;
  148.             this.offsetRotX[i] += (waveX - this.offsetRotX[i]) * RELAX_SPEED;
  149.  
  150.             seg.yRot = this.baseRotY[i] + this.offsetRotY[i];
  151.             seg.xRot = this.baseRotX[i] + this.offsetRotX[i];
  152.         }
  153.  
  154.         //this.animate(entity.idleInWaterAnimationState, MysticAnimations.SEA_OTTER_IDLE_WATER, ageInTicks);
  155.         //this.animate(entity.swimmingAnimationState, MysticAnimations.SEA_OTTER_SWIMMING, ageInTicks);
  156.         //this.animate(entity.floatingAnimationState, MysticAnimations.SEA_OTTER_FLOATING, ageInTicks);
  157.     }
  158.  
  159.     @Override
  160.     public void renderToBuffer(PoseStack stack, VertexConsumer consumer, int packedLight, int packedOverlay, int color) {
  161.         super.renderToBuffer(stack, consumer, packedLight, packedOverlay, color);
  162.     }
  163.  
  164.     @Override
  165.     public ModelPart root() {
  166.         return this.root;
  167.     }
  168.  
  169. }
Advertisement
Add Comment
Please, Sign In to add comment