Skip to main content
Start with the bot from your first NPC. Use the NpcHandle returned by firstNpc.ready() as npc in the examples below. A shared change is visible to every player watching that NPC.

Play an animation

A model contains named clips. The example bot has idle and wave. Calling npc.playClip("wave") selects the clip, but your application must also advance its time. The quickstart ZIP includes src/main/java/example/npc/NpcAnimations.java. It installs one repeating task on the owning instance and measures elapsed time with a monotonic clock. Keep it with your NPC so you can cancel the task later:
The bot should make its wave gesture. animations.play("idle") switches to its idle clip. The helper resets its clock only after an admitted start. If an NPC cannot start the clip, the returned stage fails and the current clock continues. The helper samples elapsed real time once per instance tick. A busy server can skip visual samples; elapsed animation time still follows the monotonic clock. It waits for an old frame to finish before switching clips and skips ticks while the new start is pending.

Turn the head and move the NPC

Head angles are degrees. This changes the head pose without turning the whole body:
To move it, supply a new world transform:
The example bot moves two blocks along X. Adapt the coordinates to your world.

Make a clip audible

Sound cues describe what to play. Your application decides who hears them; the default sound callback is silent. The example bot binds wave to the Vanilla event minecraft:entity.villager.yes. Use NpcSounds.java from the quickstart ZIP, then create the NPC with that callback:
Once it is ready, start wave through your animation helper. Players within the cue’s radius on this instance hear it. The callback uses the cue’s volume and pitch. Custom sound files must also be present in the resourcepack.

Stop and remove

npc.stopClip() selects the rest pose. To return to an authored idle animation, call animations.play("idle") instead. Before removing the NPC, stop its animation driver:
Do this in your host shutdown path, outside the instance tick. See application integration for handling several NPCs, cancellation and cleanup failures. Continue with changes for one player.