-
Notifications
You must be signed in to change notification settings - Fork 56
Item Rendering
Interfaces you implement on an item to change how it's held, animated and drawn.
Vanilla decides all of this for you. These hooks let an item pose the player's arms, move itself in first person, render like a spyglass (in player space rather than hand space), or use a fully custom renderer. It's how telescopes, flutes and lanterns end up not looking like a stick.
Implement the interfaces you need on the item, or attach one provider object per item with the
interface's attach methods if you can't touch the item class:
public class MyItem extends Item implements IFirstPersonAnimationProvider, IThirdPersonAnimationProvider {
@Override
public UseAnim getUseAnimation(ItemStack stack) {
return UseAnim.NONE; // so vanilla doesn't animate on top of yours
}
@Override
public void animateItemFirstPerson(Player player, ItemStack stack, InteractionHand hand, HumanoidArm arm,
PoseStack poseStack, float partialTicks, float pitch,
float attackAnim, float handHeight) {
if (player.isUsingItem() && player.getUsedItemHand() == hand) {
float t = stack.getUseDuration(player) - (player.getUseItemRemainingTicks() - partialTicks + 1);
poseStack.translate(0, 0, t * 0.04F);
}
}
@Override
public <T extends LivingEntity> boolean poseRightArm(ItemStack stack, HumanoidModel<T> model, T entity, HumanoidArm mainHand) {
model.rightArm.yRot = -10;
return true; // true means you handled the pose
}
}Example: ItemAnimationExample
| Interface | For |
|---|---|
IFirstPersonAnimationProvider |
Move the item in first person |
IThirdPersonAnimationProvider |
Pose the player's arms |
IFirstPersonSpecialItemRenderer / IThirdPersonSpecialItemRenderer
|
Render in player space instead of hand space, like the spyglass |
ICustomItemRendererProvider |
A full custom renderer for the item (BEWLR on Forge, its Fabric equivalent) |
IItemDecoratorRenderer |
Draw over the item's inventory slot |
ILeftClickReact |
React to a left click, which vanilla doesn't give items |
Ready made animations live in api/client/anim: SwingAnimation, SwayingAnimation,
PendulumAnimation, for things that hang or swing as you move.
Basics Platform Helpers Registration Networking Events Configs Config Screen
Resources Runtime Resource Packs Texture Manipulation Resource Helpers Block Set API
Client Custom Models Item Rendering Rendered Textures Post Shaders GUI Toolkit Colors
World Block and Item Interfaces Additional Item Placements Improved Entities Fake Levels World Data Dispenser Behaviors
Utilities Codec Utilities Misc Helpers Commands
Datapacks Villagers Soft Fluids Map Markers Spawn Boxes Global Datapack Folder