Jump to content

[SOLVED][1.18.2]Implementation of custom armor animations


Recommended Posts

Posted (edited)

I created the armor and implemented it this way, but the SetupAnim does not work.

I think the problem is that it is not being called, but where and how can I call it?

Is it correct to describe it in the execution of each tick?

 

Model

public class Test_ArmorModel<T extends LivingEntity> extends HumanoidModel<T> {
    public static  ModelLayerLocation LAYER_LOCATION_TOP = new ModelLayerLocation(new ResourceLocation(TestWorldMod.MOD_ID, "Test_armor_top"), "main");
   public static  ModelLayerLocation LAYER_LOCATION_BOTTOM = new ModelLayerLocation(new ResourceLocation(TestWorldMod.MOD_ID, "Test_armor_bottom"), "main");

    public Test_ArmorModel(ModelPart root) {
        super(root);
    }

    public static LayerDefinition createBodyLayer(CubeDeformation size) {
        MeshDefinition meshdefinition = HumanoidModel.createMesh(size,0.0F);
        PartDefinition partdefinition = meshdefinition.getRoot();

        PartDefinition Head = partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 16).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.0F))
                .texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.5F)), PartPose.offset(0.0F, 0.0F, 0.0F));

        PartDefinition moon2 = Head.addOrReplaceChild("moon2", CubeListBuilder.create().texOffs(4, 18).addBox(5.0F, -24.0F, -6.7F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(4, 18).addBox(4.0F, -24.5F, -6.7F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(4, 18).addBox(6.0F, -24.5F, -6.7F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 18).addBox(5.5F, -23.0F, -7.0F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 18).addBox(4.5F, -23.5F, -7.0F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 18).addBox(4.5F, -24.5F, -7.0F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 18).addBox(5.5F, -25.0F, -7.0F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(-3.0F, 17.0F, 2.0F));

        PartDefinition Body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(0, 32).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
                .texOffs(28, 28).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(0.0F, 0.0F, 0.0F));

        PartDefinition RightArm = partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(56, 0).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
                .texOffs(52, 44).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(-5.0F, 2.0F, 0.0F));

        PartDefinition LeftArm = partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(52, 28).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
                .texOffs(0, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(5.0F, 2.0F, 0.0F));

        PartDefinition RightLeg = partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(36, 44).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
                .texOffs(20, 44).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(-1.9F, 12.0F, 0.0F));

        PartDefinition LeftLeg = partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(44, 12).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
                .texOffs(32, 0).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(1.9F, 12.0F, 0.0F));

        PartDefinition RightFeather2 =Body.addOrReplaceChild("LeftFeather", CubeListBuilder.create().texOffs(4, 2).mirror().addBox(-7.5665F, -16.7195F, 0.0796F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(4, 2).mirror().addBox(-8.5665F, -17.7195F, 0.0796F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 0).mirror().addBox(-11.5665F, -15.7195F, 0.0796F, 3.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(24, 0).mirror().addBox(-17.5665F, -18.7195F, 0.0796F, 4.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 16).mirror().addBox(-15.5665F, -19.7195F, 0.0796F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 16).mirror().addBox(-15.5665F, -17.7195F, 0.0796F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 20).mirror().addBox(-6.5665F, -19.7195F, 0.0796F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(24, 16).mirror().addBox(-14.5665F, -20.7195F, 0.0796F, 8.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(16, 60).mirror().addBox(-18.5665F, -21.7195F, 0.0796F, 11.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(24, 18).mirror().addBox(-16.5665F, -22.7195F, 0.0796F, 7.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(32, 20).mirror().addBox(-13.5665F, -19.7195F, 0.0796F, 5.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 2).addBox(-6.5665F, -15.7195F, 0.0796F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(2.0F, 23.0F, 0.0F, 0.0F, 0.2618F, 0.0873F));

        PartDefinition RightFeather = Body.addOrReplaceChild("RightFeather", CubeListBuilder.create().texOffs(4, 2).addBox(0.793F, -17.2424F, 1.6266F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(4, 2).addBox(1.793F, -18.2424F, 1.6266F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 0).addBox(2.793F, -16.2424F, 1.6266F, 3.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(24, 0).addBox(7.793F, -19.2424F, 1.6266F, 4.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 16).addBox(7.793F, -20.2424F, 1.6266F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 16).addBox(7.793F, -18.2424F, 1.6266F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 20).addBox(-0.207F, -20.2424F, 1.6266F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(24, 16).addBox(0.793F, -21.2424F, 1.6266F, 8.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(16, 60).addBox(1.793F, -22.2424F, 1.6266F, 11.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(24, 18).addBox(3.793F, -23.2424F, 1.6266F, 7.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(32, 20).addBox(2.793F, -20.2424F, 1.6266F, 5.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 2).addBox(-0.207F, -16.2424F, 1.6266F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(4.0F, 23.0F, 0.0F, 0.0F, -0.2618F, -0.0873F));

        return LayerDefinition.create(meshdefinition, 128, 128);

    }

    @Override
    public void renderToBuffer(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
        head.render(poseStack, buffer, packedLight, packedOverlay);
        body.render(poseStack, buffer, packedLight, packedOverlay);
        rightArm.render(poseStack, buffer, packedLight, packedOverlay);
        leftArm.render(poseStack, buffer, packedLight, packedOverlay);
        rightLeg.render(poseStack, buffer, packedLight, packedOverlay);
        leftLeg.render(poseStack, buffer, packedLight, packedOverlay);
    }

    @Override
    public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        if (entity instanceof ArmorStand) {
            super.setupAnim(entity, 0, 0, 0, 0, 0);
        } else {
            float ff = ageInTicks * (float)Math.PI * -0.1F;
            rightArm.copyFrom(super.rightArm);
            leftArm.copyFrom(super.leftArm);
            head.copyFrom(super.head);
            body.copyFrom(super.body);
            leftLeg.copyFrom(super.leftLeg);
            rightLeg.copyFrom(super.rightLeg);
            super.setupAnim(entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
        }
    }

}

Renderer

public class ModEntityRenderers extends EntityRenderers {   
	public static final Map<Item, HumanoidModel<LivingEntity>> armorModels = new HashMap<>();
    @SubscribeEvent
    public static void registerLayerDefinition(EntityRenderersEvent.RegisterLayerDefinitions event) {
        event.registerLayerDefinition(LAYER_LOCATION_TOP, () ->Test_ArmorModel.createBodyLayer(new CubeDeformation(0.5F)));
        event.registerLayerDefinition(LAYER_LOCATION_BOTTOM, ()-> Test_ArmorModel.createBodyLayer(new CubeDeformation(0.25F)));

    }

    @SubscribeEvent
    public static void registerLayers(EntityRenderersEvent.AddLayers event) {
        EntityRendererProvider.Context context = new EntityRendererProvider.Context(Minecraft.getInstance().getEntityRenderDispatcher(),Minecraft.getInstance().getItemRenderer(), Minecraft.getInstance().getResourceManager(), Minecraft.getInstance().getEntityModels(), Minecraft.getInstance().font);
        Test_ArmorModel<LivingEntity> vTop = new Test_ArmorModel<>(context.bakeLayer(LAYER_LOCATION_TOP));
        Test_ArmorModel<LivingEntity> vBot = new Test_ArmorModel<>(context.bakeLayer(LAYER_LOCATION_BOTTOM));
        armorModels.put(ModItems.HELMET.get(), vTop);
        armorModels.put(ModItems.CHESTPLATE.get(), vTop);
        armorModels.put(ModItems.LEGGINGS.get(), vBot);
        armorModels.put(ModItems.BOOTS.get(), vTop);
   }
}

 

Edited by ocome
Posted (edited)

Thank you for answering.

We were able to confirm the operation.
However, I felt that this method did not do what I expected it to do (armor model + animate with elytra).

To do this, would it be necessary to create a separate elytra render to display the entity when the armor is installed?

 

It would be nice if the animation could be performed only on the "RightFeather"...

 

Edited by ocome
Posted

Sorry for my bad English.

We are currently creating the left and right wings and they are included in the "body"

On 4/13/2022 at 1:48 PM, ocome said:
        PartDefinition RightFeather2 =Body.addOrReplaceChild("LeftFeather", CubeListBuilder.create().texOffs(4, 2).mirror().addBox(-7.5665F, -16.7195F, 0.0796F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(4, 2).mirror().addBox(-8.5665F, -17.7195F, 0.0796F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 0).mirror().addBox(-11.5665F, -15.7195F, 0.0796F, 3.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(24, 0).mirror().addBox(-17.5665F, -18.7195F, 0.0796F, 4.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 16).mirror().addBox(-15.5665F, -19.7195F, 0.0796F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 16).mirror().addBox(-15.5665F, -17.7195F, 0.0796F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 20).mirror().addBox(-6.5665F, -19.7195F, 0.0796F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(24, 16).mirror().addBox(-14.5665F, -20.7195F, 0.0796F, 8.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(16, 60).mirror().addBox(-18.5665F, -21.7195F, 0.0796F, 11.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(24, 18).mirror().addBox(-16.5665F, -22.7195F, 0.0796F, 7.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(32, 20).mirror().addBox(-13.5665F, -19.7195F, 0.0796F, 5.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false)
                .texOffs(0, 2).addBox(-6.5665F, -15.7195F, 0.0796F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(2.0F, 23.0F, 0.0F, 0.0F, 0.2618F, 0.0873F));

        PartDefinition RightFeather = Body.addOrReplaceChild("RightFeather", CubeListBuilder.create().texOffs(4, 2).addBox(0.793F, -17.2424F, 1.6266F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(4, 2).addBox(1.793F, -18.2424F, 1.6266F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 0).addBox(2.793F, -16.2424F, 1.6266F, 3.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(24, 0).addBox(7.793F, -19.2424F, 1.6266F, 4.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 16).addBox(7.793F, -20.2424F, 1.6266F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 16).addBox(7.793F, -18.2424F, 1.6266F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 20).addBox(-0.207F, -20.2424F, 1.6266F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(24, 16).addBox(0.793F, -21.2424F, 1.6266F, 8.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(16, 60).addBox(1.793F, -22.2424F, 1.6266F, 11.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(24, 18).addBox(3.793F, -23.2424F, 1.6266F, 7.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(32, 20).addBox(2.793F, -20.2424F, 1.6266F, 5.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 2).addBox(-0.207F, -16.2424F, 1.6266F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(4.0F, 23.0F, 0.0F, 0.0F, -0.2618F, -0.0873F));

This causes the "rightfether","leftfether" move, but of course the body moves with it.

			public HumanoidModel<?> getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot armorSlot, HumanoidModel<?> _default) {
				HumanoidModel armorModel = ModEntityRenderers.armorModels.get(itemStack.getItem());
				tick ++;
					float f = tick * (float)Math.PI * -0.1F;
					_default.body.getChild("body").yRot = tick * Mth.sin(f) * 5.0F;

            }

I want to animate leftfether,rightfether by itself

Posted (edited)

Sorry, it was still in error.

					_default.body.yRot = tick * Mth.sin(f) * 5.0F; //working

					_default.body.getChild("body").yRot = tick * Mth.sin(f) * 5.0F; //not working
					_default.body.getChild("RightFeather").yRot = tick * Mth.sin(f) * 5.0F; //not working
					armorModel.body.getChild("body").yRot = tick * Mth.sin(f) * 5.0F; //not working
					armorModel.body.getChild("RightFeather").yRot = tick * Mth.sin(f) * 5.0F; //not working

It is impossible to get this way

Error

Caused by: java.util.NoSuchElementException: Can't find part body

 

 

--> Ah It may work.  just a minute

Edited by ocome
Posted (edited)

Yes,  I understand now.
I seem to have gone wrong while messing with getChild.

I also have a better understanding of the model specifications

Thanks for the support!

Edited by ocome
  • ocome changed the title to [SOLVED][1.18.2]Implementation of custom armor animations

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Forge only supports Java Edition, you'll need to ask elsewhere for Pocket Edition support. Also, don't post in unrelated topics. I've split your post into its own topic.
    • How do I download mods for minecraft pe
    • I've tried multiple ways to get the chunk coordinates and none of them have worked, so I'm guessing it may be getChunk().  Is there another way to forcibly load a chunk on that same tick? If all else fails I guess I can just delay my action by a tick, but that's a pain in the butt and makes it more complex to provide appropriate feedback... Also welcome, Zander.  If you're searching for a similar solution, I hope this (eventually) helps you too 😅
    • My guess would be that you are not getting the chunk coordinates right, or getChunk dosnt work.
    • Hello, Recently I have been hosting an RLcraft server on Minecraft Forge Version 1.12.2 - 14.23.5.2860 I originally had lag issues and I chalked it up to playing on less than perfect hardware so I moved the server to better hardware(i9-9900k with 64GB of RAM for 1 player.) After lots of troubleshooting I discovered a couple of things. World saving was causing the MSPT to spike to over 2000Miliseconds and was happening every minute. This kind of makes sense as the world was pre-generated and is over 100GB. I learned that I could turn off world saving and just schedule that and that resolved that issue. After that issue was resolved I discovered another issue. It appears that when exploring chunks, any chunks explored stay loaded. They persist. I was originally thinking that this had to be a mod issue, but it didn't seem like anyone was talking about it. This isn't really a problem on packs with few worldgen mods or just few mods in general, but on beefier packs it becomes a problem. I went through forge changelogs and found this line. Build: 1.12.2-14.23.5.2841 - Thu Aug 29 01:58:50 GMT 2019 bs2609: Improve performance of persistent chunk checks (#5706) Is this a related item to what I am dealing with or just something else?   I went ahead and created a new dedicated server with Just Forge 14.23.5.2860, spark reforged, and it's core mods. I was able to replicate the issue and log it with spark. Hopefully you're able to see this spark profile. It basically shows that as I explored the chunk loading persisted(2000 chunks loaded over 10 minutes with one player)The view distance is set to 10 so that should be 200 chunks per player. If I don't move the loaded chunks are 200. I was however able to fix the persistent chunk issue if I save the world more frequently. My question is, is this intended function of the game or is this a bug? Everywhere I read seems to indicate Minecraft servers save every 5 minutes and not every minute. Can chunks not unload if the world does not autosave. Additionally. Autosave specifically appears to fix this issue. Manually running save-all does not resolve the issue.   I realize this is kind of a log one, sorry. Please let me know if you require further information. Thanks in advance for your time. https://spark.lucko.me/NvlMtC39Yt https://imgur.com/a/K0oyukx https://pastebin.com/z0qGu1Vh  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.