Jump to content

Recommended Posts

Posted

I've made a custom layer for the player but its not showing in game.

Here is my model class

Spoiler

    public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation("test", "basic_suit"), "basic_suit");
    private final ModelPart LeftLeg;
    private final ModelPart RightLeg;
    private final ModelPart LeftArm;
    private final ModelPart RightArm;
    private final ModelPart Body;

    public BasicSuitModel(ModelPart root) {
        this.LeftLeg = root.getChild("left_leg");
        this.RightLeg = root.getChild("right_leg");
        this.LeftArm = root.getChild("left_arm");
        this.RightArm = root.getChild("right_arm");
        this.Body = root.getChild("body");
    }

    public static LayerDefinition createBodyLayer() {
        MeshDefinition meshdefinition = new MeshDefinition();
        PartDefinition partdefinition = meshdefinition.getRoot();

        PartDefinition LeftLeg = partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(0, 38).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 12.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(0, 48).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 RightLeg = partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(32, 0).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 12.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(0, 32).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 LeftArm = partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(1, 19).addBox(-1.0F, -2.0F, -3.0F, 5.0F, 12.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(5.0F, 2.0F, 0.0F, -0.7854F, 0.0F, 0.0F));

        PartDefinition RightArm = partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(24, 19).addBox(-3.0F, -2.0F, -3.0F, 5.0F, 13.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(40, 32).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(-5.0F, 2.0F, 0.0F, -0.7854F, 0.0F, 0.0F));

        PartDefinition Body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(0, 0).addBox(-5.0F, 0.0F, -3.0F, 10.0F, 12.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(16, 32).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));

        return LayerDefinition.create(meshdefinition, 64, 64);
    }

    @Override
    public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {

    }

    @Override
    public void renderToBuffer(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
        LeftLeg.render(poseStack, buffer, packedLight, packedOverlay);
        RightLeg.render(poseStack, buffer, packedLight, packedOverlay);
        LeftArm.render(poseStack, buffer, packedLight, packedOverlay);
        RightArm.render(poseStack, buffer, packedLight, packedOverlay);
        Body.render(poseStack, buffer, packedLight, packedOverlay);
    }

    @Override
    protected Iterable<ModelPart> headParts() {
        return null;
    }
    protected Iterable<ModelPart> bodyParts() {
        return ImmutableList.of(this.Body);
    }

Here is my Layer class

Spoiler

 private static final ResourceLocation SUIT_TEX = new ResourceLocation("test","textures/entity/suits/basic/suit_main.png");
    private final BasicSuitModel<T> suitModel;

    public BasicSuitModelRenderer(RenderLayerParent<T, M> parent, EntityModelSet modelSet) {
        super(parent);
        this.suitModel = new BasicSuitModel<>(modelSet.bakeLayer(BasicSuitModel.LAYER_LOCATION));
    }

    @Override
    public void render(PoseStack p_116951_, MultiBufferSource p_116952_, int p_116953_, T p_116954_, float p_116955_, float p_116956_, float p_116957_, float p_116958_, float p_116959_, float p_116960_) {
        ItemStack itemstack = p_116954_.getItemBySlot(EquipmentSlot.CHEST);
        if (true) {
            ResourceLocation resourcelocation = getTexture( p_116954_);
            p_116951_.pushPose();
            p_116951_.translate(0.0D, 0.0D, 0.125D);
            this.getParentModel().copyPropertiesTo(this.suitModel);
            this.suitModel.setupAnim(p_116954_, p_116955_, p_116956_, p_116958_, p_116959_, p_116960_);
            VertexConsumer vertexconsumer = ItemRenderer.getArmorFoilBuffer(p_116952_, RenderType.armorCutoutNoCull(resourcelocation), false, itemstack.hasFoil());
            this.suitModel.renderToBuffer(p_116951_, vertexconsumer, p_116953_, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
            p_116951_.popPose();
        }
    }

    public ResourceLocation getTexture(T entity) {
        return SUIT_TEX;
    }

And the registry in the main class 

Spoiler

    @SubscribeEvent(priority = EventPriority.LOW)
    public void renderPlayer(final EntityRenderersEvent.AddLayers event) {
        LivingEntityRenderer<Player, PlayerModel<Player>> renderer = event.getRenderer(EntityType.PLAYER);
        BasicSuitModelRenderer<Player, PlayerModel<Player>> layer = new BasicSuitModelRenderer<>(renderer, event.getEntityModels());
        renderer.addLayer(layer);
    }
    @SubscribeEvent
    public void registerLayers(final EntityRenderersEvent.RegisterLayerDefinitions event){
        event.registerLayerDefinition(BasicSuitModel.LAYER_LOCATION, BasicSuitModel::createBodyLayer);
    }

 

What have I done wrong?

Posted

Update: I found one issue. I was not registering to ModEventBus but now I get:

Spoiler

Caused by: java.lang.NullPointerException: Cannot invoke "net.minecraft.client.renderer.entity.LivingEntityRenderer.addLayer(net.minecraft.client.renderer.entity.layers.RenderLayer)" because "renderer" is null

What do I do about this?

Posted

Ok so I need getParentModel().copyPropertiesTo(suitModel);

And I ran to game to see no change.

 

looking back at the armor layer code I saw the copyPropertiesTo was in HumanoidModel

So I made my model extend HumanoidModel instead of AgeableListModel and I added:

Spoiler

    @Override
    protected Iterable<ModelPart> headParts() {
        return super.headParts();
    }

    @Override
    protected Iterable<ModelPart> bodyParts() {
        return super.bodyParts();
    }

but now the game won't run and I'm getting

Description: Rendering overlay

net.minecraftforge.fml.ModLoadingException: TestMod (test) encountered an error during the done event phase
§7java.util.NoSuchElementException: Can't find part head

 

What have I done wrong?

Posted

I assume by the stacktrace you mean this:

Spoiler

---- Minecraft Crash Report ----
// Shall we play a game?

Time: 11/29/21, 9:07 AM
Description: Rendering entity in world

java.util.NoSuchElementException: Can't find part LeftLeg
    at net.minecraft.client.model.geom.ModelPart.getChild(ModelPart.java:60) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at com.Twins730.SolarisSpace.client.Entity.Model.Suit.Basic.BasicSuitModel.<init>(BasicSuitModel.java:30) ~[%2379!:?] {re:classloading}
    at com.Twins730.SolarisSpace.client.Entity.Renderer.Suits.Basic.BasicSuitModelRenderer.render(BasicSuitModelRenderer.java:28) ~[%2379!:?] {re:classloading}
    at com.Twins730.SolarisSpace.client.Entity.Renderer.Suits.Basic.BasicSuitModelRenderer.render(BasicSuitModelRenderer.java:16) ~[%2379!:?] {re:classloading}
    at net.minecraft.client.renderer.entity.LivingEntityRenderer.render(LivingEntityRenderer.java:126) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.player.PlayerRenderer.render(PlayerRenderer.java:62) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.player.PlayerRenderer.render(PlayerRenderer.java:43) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.EntityRenderDispatcher.render(EntityRenderDispatcher.java:129) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.LevelRenderer.renderEntity(LevelRenderer.java:1280) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.LevelRenderer.renderLevel(LevelRenderer.java:1076) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.GameRenderer.renderLevel(GameRenderer.java:1050) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.GameRenderer.render(GameRenderer.java:830) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1039) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:659) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:186) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?] {}
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
    at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] {}
    at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:38) ~[fmlloader-1.17.1-37.0.126.jar%233!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) [bootstraplauncher-0.1.17.jar:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
    at net.minecraft.client.model.geom.ModelPart.getChild(ModelPart.java:60) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at com.Twins730.SolarisSpace.client.Entity.Model.Suit.Basic.BasicSuitModel.<init>(BasicSuitModel.java:30) ~[%2379!:?] {re:classloading}
    at com.Twins730.SolarisSpace.client.Entity.Renderer.Suits.Basic.BasicSuitModelRenderer.render(BasicSuitModelRenderer.java:28) ~[%2379!:?] {re:classloading}
    at com.Twins730.SolarisSpace.client.Entity.Renderer.Suits.Basic.BasicSuitModelRenderer.render(BasicSuitModelRenderer.java:16) ~[%2379!:?] {re:classloading}
    at net.minecraft.client.renderer.entity.LivingEntityRenderer.render(LivingEntityRenderer.java:126) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.player.PlayerRenderer.render(PlayerRenderer.java:62) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.player.PlayerRenderer.render(PlayerRenderer.java:43) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
-- Entity being rendered --
Details:
    Entity Type: minecraft:player (net.minecraft.client.player.LocalPlayer)
    Entity ID: 199
    Entity Name: Dev
    Entity's Exact location: 300.65, 75.00, 104.99
    Entity's Block location: World: (300,75,104), Section: (at 12,11,8 in 18,4,6; chunk contains blocks 288,0,96 to 303,255,111), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Entity's Momentum: 0.00, -0.08, 0.00
    Entity's Passengers: []
    Entity's Vehicle: null

-- Renderer details --
Details:
    Assigned renderer: net.minecraft.client.renderer.entity.player.PlayerRenderer@387c5d79
    Location: 0.83,-5.49,-0.57 - World: (0,-6,-1), Section: (at 0,10,15 in 0,-1,-1; chunk contains blocks 0,0,-16 to 15,255,-1), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
    Rotation: -124.3446
    Delta: 0.54000616
Stacktrace:
    at net.minecraft.client.renderer.entity.EntityRenderDispatcher.render(EntityRenderDispatcher.java:129) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.LevelRenderer.renderEntity(LevelRenderer.java:1280) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.LevelRenderer.renderLevel(LevelRenderer.java:1076) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.GameRenderer.renderLevel(GameRenderer.java:1050) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}


-- Affected level --
Details:
    All players: 1 total; [LocalPlayer['Dev'/199, l='ClientLevel', x=300.65, y=75.00, z=104.99]]
    Chunk stats: 441, 236
    Level dimension: minecraft:overworld
    Level spawn location: World: (32,66,-64), Section: (at 0,2,0 in 2,4,-4; chunk contains blocks 32,0,-64 to 47,255,-49), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
    Level time: 85016 game time, 20965 day time
    Server brand: forge
    Server type: Integrated singleplayer server
Stacktrace:
    at net.minecraft.client.multiplayer.ClientLevel.fillReportDetails(ClientLevel.java:364) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.fillReport(Minecraft.java:2245) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:676) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:186) ~[forge-1.17.1-37.0.126_mapped_official_1.17.1-recomp.jar%2375!:?] {re:classloading,pl:runtimedistcleaner:A}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?] {}
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
    at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] {}
    at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:38) ~[fmlloader-1.17.1-37.0.126.jar%233!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) [bootstraplauncher-0.1.17.jar:?] {}


 

If I am incorrect just tell me.

Also I have made changes to my code.

Posted

Ok Here is the Updated Code:

The Model Class:

Spoiler

public class BasicSuitModel extends HumanoidModel<AbstractClientPlayer> {

    public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation(SolarisSpace.MOD_ID, "basic_suit"), "basic_suit_wearable");
    private final ModelPart LeftLeg;
    private final ModelPart RightLeg;
    private final ModelPart LeftArm;
    private final ModelPart RightArm;
    private final ModelPart Body;

    public BasicSuitModel(ModelPart p_170821_) {
        super(p_170821_);
        this.LeftLeg = p_170821_.getChild("LeftLeg");
        this.RightLeg = p_170821_.getChild("RightLeg");
        this.LeftArm = p_170821_.getChild("LeftArm");
        this.RightArm = p_170821_.getChild("RightArm");
        this.Body = p_170821_.getChild("Body");
    }


    public void setupAngles(PlayerModel model) {
        this.Body.copyFrom(model.body);
        this.LeftArm.copyFrom(model.leftArm);
        this.RightArm.copyFrom(model.rightArm);
        this.LeftLeg.copyFrom(model.leftLeg);
        this.RightLeg.copyFrom(model.rightLeg);
    }

    public static LayerDefinition createBodyLayer() {
        MeshDefinition meshdefinition = new MeshDefinition();
        PartDefinition partdefinition = meshdefinition.getRoot();

        CubeDeformation cube = CubeDeformation.NONE;
        meshdefinition = HumanoidModel.createMesh(cube, 0.0F);
        partdefinition = meshdefinition.getRoot().getChild("body");

        PartDefinition LeftLeg = partdefinition.addOrReplaceChild("LeftLeg", CubeListBuilder.create().texOffs(0, 38).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 12.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(0, 48).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 RightLeg = partdefinition.addOrReplaceChild("RightLeg", CubeListBuilder.create().texOffs(32, 0).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 12.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(0, 32).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 LeftArm = partdefinition.addOrReplaceChild("LeftArm", CubeListBuilder.create().texOffs(0, 19).addBox(-1.0F, -3.0F, -3.0F, 6.0F, 13.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(48, 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 RightArm = partdefinition.addOrReplaceChild("RightArm", CubeListBuilder.create().texOffs(22, 19).addBox(-4.0F, -3.0F, -3.0F, 6.0F, 13.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(40, 32).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 Body = partdefinition.addOrReplaceChild("Body", CubeListBuilder.create().texOffs(0, 0).addBox(-5.0F, -1.0F, -3.0F, 10.0F, 13.0F, 6.0F, new CubeDeformation(0.0F)).texOffs(16, 32).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));

        return LayerDefinition.create(meshdefinition, 64, 64);
    }

    @Override
    public void renderToBuffer(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
        LeftLeg.render(poseStack, buffer, packedLight, packedOverlay);
        RightLeg.render(poseStack, buffer, packedLight, packedOverlay);
        LeftArm.render(poseStack, buffer, packedLight, packedOverlay);
        RightArm.render(poseStack, buffer, packedLight, packedOverlay);
        Body.render(poseStack, buffer, packedLight, packedOverlay);
    }

    @Override
    protected Iterable<ModelPart> headParts() {
        return ImmutableList.of(this.head);
    }

    @Override
    protected Iterable<ModelPart> bodyParts() {
        return ImmutableList.of(this.body, this.rightArm, this.leftArm, this.rightLeg, this.leftLeg, this.hat);
    }
}

My Renderer class:

Spoiler

public class BasicSuitModelRenderer extends RenderLayer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> {

    private static final ResourceLocation SUIT_TEX = new ResourceLocation(SolarisSpace.MOD_ID,"textures/entity/suits/basic/suit_main.png");
    private BasicSuitModel suitModel;

    public BasicSuitModelRenderer(RenderLayerParent<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> renderer) {
        super(renderer);
    }


    @Override
    public void render(PoseStack poseStack, MultiBufferSource p_116952_, int p_116953_, AbstractClientPlayer p_116954_, float p_116955_, float p_116956_, float p_116957_, float p_116958_, float p_116959_, float p_116960_) {
        suitModel = new BasicSuitModel(BasicSuitModel.createBodyLayer().bakeRoot());
        if (true) {
            poseStack.pushPose();
            ((PlayerModel)this.getParentModel()).copyPropertiesTo(this.suitModel);
            this.suitModel.setupAngles((PlayerModel)this.getParentModel());
            poseStack.translate(0.0D, 0.0D, 0.0D);
            this.suitModel.setupAnim(p_116954_, p_116955_, p_116956_, p_116958_, p_116959_, p_116960_);
            VertexConsumer vertexConsumer = p_116952_.getBuffer(RenderType.entityCutoutNoCull(SUIT_TEX));
            this.suitModel.renderToBuffer(poseStack, vertexConsumer, p_116953_, OverlayTexture.NO_OVERLAY, 1,1,1, 1.0F);
            poseStack.popPose();
        }
    }

}

And the updated Main Class:

Spoiler


    @SubscribeEvent
    public void layerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
      event.registerLayerDefinition(BasicSuitModel.LAYER_LOCATION, () -> {
            return BasicSuitModel.createBodyLayer();
        });
    }

    @SubscribeEvent
    public void addLayers(EntityRenderersEvent.AddLayers evt) {
        addPlayerLayer(evt, "default");
        addPlayerLayer(evt, "slim");
    }

    private void addPlayerLayer(EntityRenderersEvent.AddLayers evt, String skin) {
        EntityRenderer<? extends Player> renderer = evt.getSkin(skin);
        if (renderer instanceof LivingEntityRenderer) {
            LivingEntityRenderer livingRenderer = (LivingEntityRenderer)renderer;
            livingRenderer.addLayer(new BasicSuitModelRenderer(livingRenderer));
        }

    }

Also, I realized that the Main Class Events shouldn't be static and now the game runs but the model isn't rendering.

  • 3 weeks later...
  • UserMC123 changed the title to SOLVED [1.17.1] Custom player layer not rendering.

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



×
×
  • Create New...

Important Information

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