Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi, I'm trying to add this as a constant render layer on the player. This works perfectly, unless the player crouches:

java_0557.pngjava_0559.png

Interestingly enough, if I add the model as a model for armor, it works just fine:

java_0560.png

I almost feel like I'm missing something obvious, like getting the rotation angles from somewhere, but am oblivious to where it could get them from.

In my RenderSetup I add the render layer:

@Mod.EventBusSubscriber(modid = Main.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class RenderSetup
{
	public static final ResourceLocation KNIGHT_LAYER_TEXTURE = new ResourceLocation(Main.MODID, "textures/models/armor/knight_layer_1.png");
	public static final ModelLayerLocation KNIGHT_LAYER_LOCATION = new ModelLayerLocation(KNIGHT_LAYER_TEXTURE, "knight");

	@SubscribeEvent
	public static void onRegisterLayerDefinition(final EntityRenderersEvent.RegisterLayerDefinitions evt)
	{
		evt.registerLayerDefinition(KNIGHT_LAYER_LOCATION, ModelKnight::createLayer);
	}

	@SubscribeEvent
	public static void onEntityAddLayers(final EntityRenderersEvent.AddLayers evt)
	{
		for (String skin : evt.getSkins())
		{
			final LivingEntityRenderer<Player, EntityModel<Player>> renderer = evt.getSkin(skin);
			renderer.addLayer(new LayerTT<>(renderer));
		}
	}
}

 

And my LayerTT looks like this:

public class LayerTT<T extends LivingEntity, M extends EntityModel<T>> extends RenderLayer<T, M>
{
	private final ModelKnight<T> MODEL_KNIGHT_HEAD;
	private final ModelKnight<T> MODEL_KNIGHT_CHEST;
	private final ModelKnight<T> MODEL_KNIGHT_LEGS;
	private final ModelKnight<T> MODEL_KNIGHT_FEET;

	public LayerTT(RenderLayerParent<T, M> entityRendererOwner)
	{
		super(entityRendererOwner);

		final ModelPart bakedKnight = Minecraft.getInstance().getEntityModels().bakeLayer(RenderSetup.KNIGHT_LAYER_LOCATION);
		this.MODEL_KNIGHT_HEAD = new ModelKnight<>(EquipmentSlot.HEAD, bakedKnight);
		this.MODEL_KNIGHT_CHEST = new ModelKnight<>(EquipmentSlot.CHEST, bakedKnight);
		this.MODEL_KNIGHT_LEGS = new ModelKnight<>(EquipmentSlot.LEGS, bakedKnight);
		this.MODEL_KNIGHT_FEET = new ModelKnight<>(EquipmentSlot.FEET, bakedKnight);
	}

	@Override
	public void render(PoseStack pMatrixStack, MultiBufferSource pBuffer, int pPackedLight, T pLivingEntity, float pLimbSwing, float pLimbSwingAmount, float pPartialTicks, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch)
	{
		pMatrixStack.pushPose();
          
		M parentModel = this.getParentModel();
		coloredCutoutModelCopyLayerRender(parentModel, MODEL_KNIGHT_HEAD, RenderSetup.KNIGHT_LAYER_TEXTURE, pMatrixStack, pBuffer, pPackedLight, pLivingEntity, pLimbSwing, pLimbSwingAmount, pAgeInTicks, pNetHeadYaw, pHeadPitch, pPartialTicks, 1, 1, 1);
		coloredCutoutModelCopyLayerRender(parentModel, MODEL_KNIGHT_CHEST, RenderSetup.KNIGHT_LAYER_TEXTURE, pMatrixStack, pBuffer, pPackedLight, pLivingEntity, pLimbSwing, pLimbSwingAmount, pAgeInTicks, pNetHeadYaw, pHeadPitch, pPartialTicks, 1, 1, 1);
		coloredCutoutModelCopyLayerRender(parentModel, MODEL_KNIGHT_LEGS, RenderSetup.KNIGHT_LAYER_TEXTURE, pMatrixStack, pBuffer, pPackedLight, pLivingEntity, pLimbSwing, pLimbSwingAmount, pAgeInTicks, pNetHeadYaw, pHeadPitch, pPartialTicks, 1, 1, 1);
		coloredCutoutModelCopyLayerRender(parentModel, MODEL_KNIGHT_FEET, RenderSetup.KNIGHT_LAYER_TEXTURE, pMatrixStack, pBuffer, pPackedLight, pLivingEntity, pLimbSwing, pLimbSwingAmount, pAgeInTicks, pNetHeadYaw, pHeadPitch, pPartialTicks, 1, 1, 1);

		pMatrixStack.popPose();
	}
}

 

I'd be happy if anyone could give me a direction of where to look. Thanks :)

Edited by trienow
Solved

  • Author

Hi diesieben! Thanks for your swift reply.

I thought I called it through coloredCutoutModelCopyLayerRender, but I was wrong!

As I made LayerTT's parent Model to an EntityModel and not a HumanoidModel, copyPropertiesTo was not copying all the expected model parts.

 

Unfortunatly the EntityRenderersEvent.AddLayers Event only gives me a renderer for EntityModel<Player> and not HumanoidModel<Player>, so I'll have to figure something out there.

Hopefully, without having to make my own Version of the PlayerRenderer.

 

Thanks for giving me a direction :)

Edited by trienow

  • Author

I got it to work.

Just for future reference, I decided to take your advice and use instanceof and cast by dropping the generics (which do add up).

It isn't pretty as Java gives me warnings, but at least no errors.

public static void onEntityAddLayers(final EntityRenderersEvent.AddLayers evt)
{
	for (String skin : evt.getSkins())
	{
		final LivingEntityRenderer livingEntityRenderer = evt.getSkin(skin);
		if (livingEntityRenderer instanceof LivingEntityRenderer)
		{
			livingEntityRenderer.addLayer(new LayerTT<>(livingEntityRenderer));
		}
	}
}

I then was able to make my layer class reference HumanoidModel<T> and also call copyPropertiesTo before calling the coloredCutoutModelCopyLayerRender.

Take care!

Edited by trienow
Decided to sum up other changes I made to get the code to work

  • trienow changed the title to [SOLVED] Custom render layer doesn't respect a players crouching pose

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.