Advertisement
jayhillx

redpandamodel

Jan 11th, 2024
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.23 KB | None | 0 0
  1. package com.mysticsbiomes.client.model.entity;
  2.  
  3. import com.google.common.collect.ImmutableList;
  4. import com.mojang.blaze3d.vertex.PoseStack;
  5. import com.mojang.blaze3d.vertex.VertexConsumer;
  6. import com.mysticsbiomes.client.animation.RedPandaAnimation;
  7. import com.mysticsbiomes.common.entity.animal.RedPanda;
  8. import net.minecraft.client.model.HierarchicalModel;
  9. import net.minecraft.client.model.geom.ModelPart;
  10. import net.minecraft.client.model.geom.PartPose;
  11. import net.minecraft.client.model.geom.builders.*;
  12. import net.minecraftforge.api.distmarker.Dist;
  13. import net.minecraftforge.api.distmarker.OnlyIn;
  14.  
  15. @OnlyIn(Dist.CLIENT)
  16. public class RedPandaModel<T extends RedPanda> extends HierarchicalModel<T> {
  17.     private final ModelPart root;
  18.     private final ModelPart head;
  19.     private final ModelPart headStanding;
  20.     private final ModelPart body;
  21.     private final ModelPart rightFrontLeg;
  22.     private final ModelPart leftFrontLeg;
  23.     private final ModelPart rightHindLeg;
  24.     private final ModelPart leftHindLeg;
  25.  
  26.     public RedPandaModel(ModelPart root) {
  27.         this.root = root.getChild("root");
  28.         this.head = this.root.getChild("head");
  29.         this.headStanding = this.root.getChild("head_standing");
  30.         this.body = this.root.getChild("body");
  31.         this.rightFrontLeg = this.root.getChild("right_front_leg");
  32.         this.leftFrontLeg = this.root.getChild("left_front_leg");
  33.         this.rightHindLeg = this.root.getChild("right_hind_leg");
  34.         this.leftHindLeg = this.root.getChild("left_hind_leg");
  35.     }
  36.  
  37.     public static LayerDefinition createBodyLayer() {
  38.         MeshDefinition mesh = new MeshDefinition();
  39.         PartDefinition root = mesh.getRoot().addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(0.0F, 24.0F, 0.0F));
  40.         PartDefinition head = root.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -3.0F, -5.0F, 8.0F, 6.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, -6.0F, -3.0F));
  41.         head.addOrReplaceChild("right_ear", CubeListBuilder.create().texOffs(27, 6).mirror().addBox(-1.5F, -1.5F, -0.5F, 3.0F, 3.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-3.5F, -2.5F, -1.5F));
  42.         head.addOrReplaceChild("left_ear", CubeListBuilder.create().texOffs(27, 6).addBox(-1.5F, -1.5F, -0.5F, 3.0F, 3.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(3.5F, -2.5F, -1.5F));
  43.         head.addOrReplaceChild("snout", CubeListBuilder.create().texOffs(27, 0).addBox(-2.0F, -1.5F, -2.0F, 4.0F, 3.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 1.5F, -5.0F));
  44.         PartDefinition head_standing = root.addOrReplaceChild("head_standing", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -6.0F, -2.5F, 8.0F, 6.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, -3.0F, -5.5F));
  45.         head_standing.addOrReplaceChild("right_ear2", CubeListBuilder.create().texOffs(27, 6).mirror().addBox(-1.5F, -1.5F, -0.5F, 3.0F, 3.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-3.5F, -5.5F, 1.0F));
  46.         head_standing.addOrReplaceChild("left_ear2", CubeListBuilder.create().texOffs(27, 6).addBox(-1.5F, -1.5F, -0.5F, 3.0F, 3.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(3.5F, -5.5F, 1.0F));
  47.         head_standing.addOrReplaceChild("snout2", CubeListBuilder.create().texOffs(27, 0).addBox(-2.0F, -1.5F, -2.0F, 4.0F, 3.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, -1.5F, -2.5F));
  48.         PartDefinition body = root.addOrReplaceChild("body", CubeListBuilder.create(), PartPose.offset(0.0F, -6.0F, 2.0F));
  49.         body.addOrReplaceChild("body_r1", CubeListBuilder.create().texOffs(0, 16).addBox(-3.0F, -5.0F, -3.0F, 6.0F, 10.0F, 6.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 1.5708F, 0.0F, 0.0F));
  50.         PartDefinition tail = body.addOrReplaceChild("tail", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 5.0F));
  51.         tail.addOrReplaceChild("tail_r1", CubeListBuilder.create().texOffs(27, 17).addBox(-2.5F, 0.0F, -2.5F, 5.0F, 9.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 1.5708F, 0.0F, 0.0F));
  52.         root.addOrReplaceChild("right_front_leg", CubeListBuilder.create().texOffs(40, 1).mirror().addBox(-0.99F, 0.0F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-2.0F, -4.0F, -2.0F));
  53.         root.addOrReplaceChild("left_front_leg", CubeListBuilder.create().texOffs(40, 1).addBox(-1.01F, 0.0F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(2.0F, -4.0F, -2.0F));
  54.         root.addOrReplaceChild("right_hind_leg", CubeListBuilder.create().texOffs(40, 1).mirror().addBox(-0.99F, 0.0F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-2.0F, -4.0F, 5.0F));
  55.         root.addOrReplaceChild("left_hind_leg", CubeListBuilder.create().texOffs(40, 1).addBox(-1.01F, 0.0F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(2.0F, -4.0F, 5.0F));
  56.         return LayerDefinition.create(mesh, 48, 32);
  57.     }
  58.  
  59.     @Override
  60.     public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
  61.         this.root().getAllParts().forEach(ModelPart::resetPose);
  62.         this.head.xRot = headPitch * 0.017453292F;
  63.         this.head.yRot = netHeadYaw * 0.017453292F;
  64.         this.headStanding.xRot = headPitch * 0.017453292F;
  65.         this.headStanding.yRot = netHeadYaw * 0.017453292F;
  66.  
  67.         boolean flag = entity.isStanding();
  68.         this.head.visible = !flag;
  69.         this.headStanding.visible = flag;
  70.         if (flag) {
  71.             this.animateWalk(RedPandaAnimation.STANDING_WALK, limbSwing, limbSwingAmount, 9.0F, 8.5F);
  72.         } else {
  73.             this.animateWalk(RedPandaAnimation.WALKING, limbSwing, limbSwingAmount, 9.5F, 8.5F);
  74.         }
  75.  
  76.         this.animate(entity.idleAnimationState, RedPandaAnimation.IDLE, ageInTicks);
  77.         this.animate(entity.sleepingAnimationState, RedPandaAnimation.SLEEPING, ageInTicks);
  78.     }
  79.  
  80.     @Override
  81.     public void renderToBuffer(PoseStack stack, VertexConsumer consumer, int light, int overlay, float r, float g, float b, float a) {
  82.         if (this.young) {
  83.             stack.pushPose();
  84.             float f1;
  85.             f1 = 1.5F / 2.5F;
  86.             stack.scale(f1, f1, f1);
  87.  
  88.             stack.translate(0.0F, 14.0F / 16.0F, 1.0F / 16.0F);
  89.             this.headParts().forEach((part) -> part.render(stack, consumer, light, overlay, r, g, b, a));
  90.             stack.popPose();
  91.             stack.pushPose();
  92.             f1 = 1.0F / 2.0F;
  93.             stack.scale(f1, f1, f1);
  94.             stack.translate(0.0F, 1.0F, 0.0F);
  95.             this.bodyParts().forEach((part) -> part.render(stack, consumer, light, overlay, r, g, b, a));
  96.             stack.popPose();
  97.         } else {
  98.             super.renderToBuffer(stack, consumer, light, overlay, r, g, b, a);
  99.         }
  100.     }
  101.  
  102.     protected Iterable<ModelPart> headParts() {
  103.         return ImmutableList.of(this.head);
  104.     }
  105.  
  106.     protected Iterable<ModelPart> bodyParts() {
  107.         return ImmutableList.of(this.body, this.rightFrontLeg, this.leftFrontLeg, this.rightHindLeg, this.leftHindLeg);
  108.     }
  109.  
  110.     @Override
  111.     public ModelPart root() {
  112.         return this.root;
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement