Skip to content

[OLD] Rendering Trinkets

Emily Rose Alexandra edited this page May 27, 2021 · 1 revision

Rendering Trinkets

In order to have trinkets render, all you need to do is override the render method in ITrinket and draw your model. The following example will render an ender pearl over the center of the player's face while the trinket is worn.

@Override
public void render(String slot, PlayerEntityModel<AbstractClientPlayerEntity> model, AbstractClientPlayerEntity player, float headYaw, float headPitch){
	ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
	ItemStack stack = new ItemStack(Items.ENDER_PEARL);
	ITrinket.translateToFace(model, player, headYaw, headPitch);
	GlStateManager.scalef(0.2F, -0.2F, 0.2F);
	itemRenderer.renderItem(stack, ModelTransformation.Type.FIXED);
}

ITrinket provides developers 6 functions to translate your rendering context to a point on a player's body part.

Function Position
translateToFace The center of the player's face
translateToChest The center of the player's front torso/chest face
translateToRightArm The center of the player's right palm
translateToLeftArm The center of the player's left palm
translateToRightLeg The center of the player's right foot
translateToLeftLeg The center of the player's left foot

All of these transformations rotate and transform the rendering context to be the body part as if the player is standing rigidly, so, for example, if you called translateToLeftArm then GLStateManager.translatef(0.0F, -0.375, -0.125) before drawing your model, it would be positioned halfway up the player's arm on the front side, no matter how the player is being animated.

Notes

  • The two Trinkets slot groups hand and offhand should represent the player's main and off hands, a check should be preformed to draw on the proper arm.
  • The default translations put the rendering point under armor, if it is being worn, if you want your trinkets to show over armor you should check to see if any is being worn and apply a z transformation if so.
Clone this wiki locally