Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mysticsbiomes.client.entity.model;
- import com.mojang.blaze3d.vertex.PoseStack;
- import com.mojang.blaze3d.vertex.VertexConsumer;
- import com.mysticsbiomes.common.entity.SeaOtter;
- import net.minecraft.client.model.HierarchicalModel;
- import net.minecraft.client.model.geom.ModelPart;
- import net.minecraft.client.model.geom.PartPose;
- import net.minecraft.client.model.geom.builders.*;
- import net.minecraftforge.api.distmarker.Dist;
- import net.minecraftforge.api.distmarker.OnlyIn;
- @OnlyIn(Dist.CLIENT)
- public class SeaOtterModel<T extends SeaOtter> extends HierarchicalModel<T> {
- private final ModelPart root;
- private final ModelPart neckRoot;
- private final ModelPart neck;
- private final ModelPart head;
- private final ModelPart leftWhiskers;
- private final ModelPart rightWhiskers;
- private final ModelPart bodyRoot;
- private final ModelPart upperTorsoRoot;
- private final ModelPart upperTorso;
- private final ModelPart leftArm;
- private final ModelPart rightArm;
- private final ModelPart lowerTorsoRoot;
- private final ModelPart lowerTorso;
- private final ModelPart leftLeg;
- private final ModelPart leftHip;
- private final ModelPart leftFlipper;
- private final ModelPart rightLeg;
- private final ModelPart rightHip;
- private final ModelPart rightFlipper;
- private final ModelPart tail;
- private final ModelPart[] bodySegments;
- float[] baseRotX;
- float[] baseRotY;
- float[] baseRotZ;
- float[] offsetRotX;
- float[] offsetRotY;
- float[] offsetRotZ;
- public SeaOtterModel(ModelPart root) {
- this.root = root.getChild("root");
- /// head
- this.neckRoot = this.root.getChild("neck_root");
- this.neck = this.neckRoot.getChild("neck");
- this.head = this.neckRoot.getChild("head");
- this.leftWhiskers = this.head.getChild("left_whiskers");
- this.rightWhiskers = this.head.getChild("right_whiskers");
- /// body
- this.bodyRoot = this.root.getChild("body_root");
- /// segment 1
- this.upperTorsoRoot = this.bodyRoot.getChild("upper_torso_root");
- this.upperTorso = this.upperTorsoRoot.getChild("upper_torso");
- this.leftArm = this.upperTorsoRoot.getChild("left_arm");
- this.rightArm = this.upperTorsoRoot.getChild("right_arm");
- /// segment 2
- this.lowerTorsoRoot = this.upperTorsoRoot.getChild("lower_torso_root");
- this.lowerTorso = this.lowerTorsoRoot.getChild("lower_torso");
- this.leftLeg = this.lowerTorsoRoot.getChild("left_leg");
- this.leftHip = this.leftLeg.getChild("left_hip");
- this.leftFlipper = this.leftHip.getChild("left_flipper");
- this.rightLeg = this.lowerTorsoRoot.getChild("right_leg");
- this.rightHip = this.rightLeg.getChild("right_hip");
- this.rightFlipper = this.rightHip.getChild("right_flipper");
- /// segment 3
- this.tail = this.lowerTorsoRoot.getChild("tail");
- this.bodySegments = new ModelPart[]{this.upperTorsoRoot, this.lowerTorsoRoot, this.tail};
- this.baseRotX = new float[this.bodySegments.length];
- this.baseRotY = new float[this.bodySegments.length];
- this.baseRotZ = new float[this.bodySegments.length];
- this.offsetRotX = new float[this.bodySegments.length];
- this.offsetRotY = new float[this.bodySegments.length];
- this.offsetRotZ = new float[this.bodySegments.length];
- for (int i = 0; i < this.bodySegments.length; i++) {
- this.baseRotX[i] = this.bodySegments[i].xRot;
- this.baseRotY[i] = this.bodySegments[i].yRot;
- this.baseRotZ[i] = this.bodySegments[i].zRot;
- }
- }
- public static LayerDefinition createBodyLayer() {
- MeshDefinition mesh = new MeshDefinition();
- PartDefinition root = mesh.getRoot().addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(0.0F, 18.5F, -0.1F));
- PartDefinition neckRoot = root.addOrReplaceChild("neck_root", CubeListBuilder.create(), PartPose.offset(0.0F, -2.5F, -5.9F));
- PartDefinition neck = neckRoot.addOrReplaceChild("neck", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
- 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));
- 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));
- 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));
- 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));
- PartDefinition bodyRoot = root.addOrReplaceChild("body_root", CubeListBuilder.create(), PartPose.offset(0.0F, -0.5F, -5.9F));
- PartDefinition upperTorsoRoot = bodyRoot.addOrReplaceChild("upper_torso_root", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
- PartDefinition upperTorso = upperTorsoRoot.addOrReplaceChild("upper_torso", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
- 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));
- 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));
- 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));
- PartDefinition lowerTorsoRoot = upperTorsoRoot.addOrReplaceChild("lower_torso_root", CubeListBuilder.create(), PartPose.offset(0.0F, 1.0F, 6.0F));
- PartDefinition lowerTorso = lowerTorsoRoot.addOrReplaceChild("lower_torso", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
- 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));
- PartDefinition leftLeg = lowerTorsoRoot.addOrReplaceChild("left_leg", CubeListBuilder.create(), PartPose.offset(2.0F, 1.5F, 4.5F));
- PartDefinition leftHip = leftLeg.addOrReplaceChild("left_hip", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
- 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));
- PartDefinition leftFlipper = leftHip.addOrReplaceChild("left_flipper", CubeListBuilder.create(), PartPose.offset(0.0F, 2.5F, 2.0F));
- 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));
- PartDefinition rightLeg = lowerTorsoRoot.addOrReplaceChild("right_leg", CubeListBuilder.create(), PartPose.offset(-2.0F, 1.5F, 5.0F));
- PartDefinition rightHip = rightLeg.addOrReplaceChild("right_hip", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, -0.5F));
- 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));
- PartDefinition rightFlipper = rightHip.addOrReplaceChild("right_flipper", CubeListBuilder.create(), PartPose.offset(0.0F, 2.5F, 2.0F));
- 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));
- PartDefinition tail = lowerTorsoRoot.addOrReplaceChild("tail", CubeListBuilder.create(), PartPose.offset(0.0F, -1.5F, 7.0F));
- 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));
- return LayerDefinition.create(mesh, 64, 48);
- }
- @Override
- public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
- this.root().getAllParts().forEach(ModelPart::resetPose);
- float headYawTarget = netHeadYaw * ((float)Math.PI / 180F);
- float headPitchTarget = headPitch * ((float)Math.PI / 180F);
- this.head.yRot = headYawTarget;
- this.head.xRot = headPitchTarget;
- this.neck.visible = entity.isFloating();
- float swimSpeed = (float) entity.getDeltaMovement().length();
- float turnAmount = netHeadYaw - entity.prevHeadYaw;
- final float MAX_BEND_Y = (float)Math.toRadians(25);
- final float MAX_BEND_X = (float)Math.toRadians(15);
- final float RELAX_SPEED = 0.1F;
- for (int i = 0; i < this.bodySegments.length; i++) {
- ModelPart seg = this.bodySegments[i];
- float waveY = (float)Math.sin(ageInTicks * 0.2 + i * 0.6) * swimSpeed * 0.3F;
- float turnBend = turnAmount * 0.5F * ((i + 1) / (float) this.bodySegments.length);
- float totalY = waveY + turnBend;
- totalY = Math.max(-MAX_BEND_Y, Math.min(MAX_BEND_Y, totalY));
- float waveX = (float)Math.cos(ageInTicks * 0.25F + i * 0.4F) * swimSpeed * 0.1F;
- waveX = Math.max(-MAX_BEND_X, Math.min(MAX_BEND_X, waveX));
- this.offsetRotY[i] += (totalY - this.offsetRotY[i]) * RELAX_SPEED;
- this.offsetRotX[i] += (waveX - this.offsetRotX[i]) * RELAX_SPEED;
- seg.yRot = this.baseRotY[i] + this.offsetRotY[i];
- seg.xRot = this.baseRotX[i] + this.offsetRotX[i];
- }
- //this.animate(entity.idleInWaterAnimationState, MysticAnimations.SEA_OTTER_IDLE_WATER, ageInTicks);
- //this.animate(entity.swimmingAnimationState, MysticAnimations.SEA_OTTER_SWIMMING, ageInTicks);
- //this.animate(entity.floatingAnimationState, MysticAnimations.SEA_OTTER_FLOATING, ageInTicks);
- }
- @Override
- public void renderToBuffer(PoseStack stack, VertexConsumer consumer, int packedLight, int packedOverlay, int color) {
- super.renderToBuffer(stack, consumer, packedLight, packedOverlay, color);
- }
- @Override
- public ModelPart root() {
- return this.root;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment