Jump to content

[1.16.5] Need a help with a creating a new render layer


FeedokTV

Recommended Posts

Hello guys! I have an idea to make mod for accessories mod (hat's like mod) and have some troubles.
I need to render hat model that I have on a player. I know that layers can help me, but idk how I can do that, even after watching the sources I have troubles.

 

public class HauntedPumpkinHeadModel extends BipedModel<LivingEntity> {

    protected final ModelRenderer armorHead;
    
    public HauntedPumpkinHeadModel() {
        super(1.0F);


        armorHead = new ModelRenderer(this);
        armorHead.setPos(0.0F, 0.0F, 0.0F);
        head.texOffs(0,0);
        head.addChild(armorHead);

        armorHead.setPos(0.0F,0.0F,0.0F);
        armorHead.texOffs(0, 0).addBox(-11.0F, -1.0F, 5.0F, 5.0F, 1.0F, 6.0F, 0.0F, false);
        armorHead.texOffs(0, 8).addBox(-10.0F, -4.0F, 6.0F, 3.0F, 4.0F, 4.0F, 0.0F, false);

    }

 

public class ItemsLayer <T extends LivingEntity, M extends EntityModel<T>> extends LayerRenderer<T, M> {

   
    private final HauntedPumpkinHeadModel hatmodel = new HauntedPumpkinHeadModel();

    public ItemsLayer(IEntityRenderer<T, M> rendererIn) {
        super(rendererIn);
  
        //super((IEntityRenderer<T, M>)Minecraft.getInstance().getEntityRenderDispatcher().);

        InfCust.LOGGER.error("[INFCUST] ITEMSLAYER READY");
    }



    @Override
    public void render(MatrixStack mstack, IRenderTypeBuffer p_225628_2_, int p_225628_3_, T p_225628_4_, float p_225628_5_, float p_225628_6_, float p_225628_7_, float p_225628_8_, float p_225628_9_, float p_225628_10_) {

        InfCust.LOGGER.error("[INFCUST] ITEMSLAYER READY");

        mstack.pushPose();
        // Something funny will be there
        mstack.popPose();
    }
}

 

private void setup(final FMLCommonSetupEvent event) {

        LOGGER.error("[INFCUST] SETUP EVENT INIT");

        Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap().get("default").addLayer(new ItemsLayer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>>(NewPlayerRenderer.instance));
        Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap().get("slim").addLayer(new ItemsLayer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>>(NewPlayerRenderer.instance));

        // Im tried to do smth here
        // NewPlayerRenderer class has only instance variable and nothing more
    }

 

Link to comment
Share on other sites

Huh, ok ill try. What is enqueueWork tag?

 

public class NewPlayerRenderer extends PlayerRenderer {

    public static NewPlayerRenderer instance;

    public NewPlayerRenderer(EntityRendererManager p_i46102_1_) {
        super(p_i46102_1_,false);
        InfCust.LOGGER.error("[INFCUST] PLAYERRENDER READY");
    }
}

 

Link to comment
Share on other sites

I used this as a stub for the ItemsLayer class, because it requires the IEntityRenderer parameter for input. Shit code I know. As I suppose I just need to put my player's renderer there, but honestly I couldn't put the player's renderer in the super method via Minecraft.getInstance

I mean this

public class ItemsLayer <T extends LivingEntity, M extends EntityModel<T>> extends LayerRenderer<T, M> {
    HatModel hatModel = new HatModel();

    public ItemsLayer(IEntityRenderer<T, M> rendererIn) {
        super(rendererIn);
        //super((IEntityRenderer<T, M>)Minecraft.getInstance().getEntityRenderDispatcher().);

        InfCust.LOGGER.error("[INFCUST] ITEMSLAYER READY");
    }



So, now how I can render my model on a players head (for example)

Link to comment
Share on other sites

This is where I ran into problems.

Idk how I can get player renderer. Maybe like this

 

PlayerRenderer rend = Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap().get("default");

Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap().get("default").addLayer(new ItemsLayer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>>(rend));

 

Link to comment
Share on other sites

Oh! Thank you so much. You won't believe how grateful I am to you

If you have time, could you explain to me how to render my hat model to head.

 

public class HatModel extends BipedModel<LivingEntity> {

	protected final ModelRenderer armorHead;

	public HatModel() {
		super(1.0F);


		armorHead = new ModelRenderer(this);
		armorHead.setPos(0.0F, 0.0F, 0.0F);
		head.texOffs(0,0);
		head.addChild(armorHead);

		armorHead.setPos(0.0F,0.0F,0.0F);
		armorHead.texOffs(0, 0).addBox(-11.0F, -1.0F, 5.0F, 5.0F, 1.0F, 6.0F, 0.0F, false);
		armorHead.texOffs(0, 8).addBox(-10.0F, -4.0F, 6.0F, 3.0F, 4.0F, 4.0F, 0.0F, false);

	}


	@Override
	public void renderToBuffer(MatrixStack p_225598_1_, IVertexBuilder p_225598_2_, int p_225598_3_, int p_225598_4_, float p_225598_5_, float p_225598_6_, float p_225598_7_, float p_225598_8_) {

	}
}

 

Link to comment
Share on other sites

I know that I have to write in overrided render function, but idk what correctly.

Only that I have there is

 

    @Override
    public void render(MatrixStack mstack, IRenderTypeBuffer p_225628_2_, int p_225628_3_, T p_225628_4_, float p_225628_5_, float p_225628_6_, float p_225628_7_, float p_225628_8_, float p_225628_9_, float p_225628_10_) {

        InfCust.LOGGER.error("[INFCUST] ITEMSLAYER RENDER");

        ItemStack itemstack = p_225628_4_.getItemBySlot(EquipmentSlotType.HEAD);

        mstack.pushPose();
		// there will be magic
        mstack.popPose();
    }

 

Link to comment
Share on other sites

I have tried this before but will try now (yes I tried to use elytra model)

 

    @Override
    public void render(MatrixStack mstack, IRenderTypeBuffer p_225628_2_, int p_225628_3_, T p_225628_4_, float p_225628_5_, float p_225628_6_, float p_225628_7_, float p_225628_8_, float p_225628_9_, float p_225628_10_) {

        InfCust.LOGGER.error("[INFCUST] ITEMSLAYER RENDER");

        ItemStack itemstack = p_225628_4_.getItemBySlot(EquipmentSlotType.HEAD);

        mstack.pushPose();
        mstack.translate(0.0D, 0.0D, 0.125D);
        this.getParentModel().copyPropertiesTo(this.elytraModel);
        this.elytraModel.setupAnim(p_225628_4_, p_225628_5_, p_225628_6_, p_225628_8_, p_225628_9_, p_225628_10_);
        IVertexBuilder ivertexbuilder = ItemRenderer.getArmorFoilBuffer(p_225628_2_, RenderType.armorCutoutNoCull(WINGS_LOCATION), false, itemstack.hasFoil());
        this.elytraModel.renderToBuffer(mstack, ivertexbuilder, p_225628_3_, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
        mstack.popPose();


    }

 

Link to comment
Share on other sites

  • 4 months later...

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.



×
×
  • Create New...

Important Information

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