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 4:48 AM, 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));
Expand  

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

    • Is there a fix for this issue? I have tried reinstalling OpenAL.dll, switching Java versions, and even muting my game when it launched, but all of these attempts have resulted in my game crashing nonetheless. I have been dealing with this issue for approximately a week straight. I have not changed any sound settings, so I am very confused. Full Code: https://gnomebot.dev/paste/mclogs/beEBzpm "4/16/2025 12:16:30 AM 1000 Error Faulting application name: javaw.exe, version: **.**.**.**, time stamp: 23 0xd75c3041 24 Faulting module name: OpenAL.dll, version: **.**.**.**, time stamp: 0x647635a125 Exception code: 0xc0000409 26 Fault offset: 0x00000000000a2b05 27 Faulting process id: 0x10A0 28 Faulting application start time: 0x1DBAE81D04A6F2F 29 Faulting application path: C:\Users\********\curseforge\minecraft\Install\java30 \java-runtime-delta\bin\javaw.exe 31 Faulting module path: C:\Users\********\curseforge\minecraft\Install\natives\n32 eoforge-21.1.148\OpenAL.dll 33 Report Id: 28552180-f359-40cc-adeb-08dada7e99d8 34 Faulting package full name: 35 Faulting package-relative application ID:" Any sort of insight would be greatly appreciated, it's giving me a headache.
    • I'm new to this, if that wasn't obvious. My friend and I are trying to make a modpack for 1.19.2. I've made a modpack previously with 0 issues before and many of the same mods. However, I can't seem to find the issue when trying to load up his new modpack.   Any help would be greatly appreciated.
    • Im trying to make a customized modpack for just myself using the atm9 modpack as a base. It was working till recently, when curseforge force updated all the mods in the pack. Currently every time I get to the main menu I try and create a world in single player and it just says saving world. then generates a crash report.    Crash Report: https://pastebin.com/xXESPfJs   Latest Log Part 1: https://pastebin.com/Cb2VpUyr  Part 2: https://pastebin.com/9SWVn4Dx
    • Okay, for him the config file looked like this: flywheel-client.toml: #Select the backend to use. Set to "DEFAULT" to let Flywheel decide. backend = "DEFAULT" #Enable or disable instance update limiting with distance. limitUpdates = true #The number of worker threads to use. Set to -1 to let Flywheel decide. Set to 0 to disable parallelism. Requires a game restart to take effect. #Range: -1 ~ 12 workerThreads = -1 #Config options for Flywheel's built-in backends. [flw_backends]     #How smooth Flywheel's shader-based lighting should be. May have a large performance impact.     #Allowed Values: FLAT, TRI_LINEAR, SMOOTH, SMOOTH_INNER_FACE_CORRECTED     lightSmoothness = "SMOOTH" There was no "INSTANCING", so we changed "DEFAULT" to "OFF", but this didn't help. Changing it to "INSTANCING" didn't work as well.
  • Topics

×
×
  • Create New...

Important Information

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