-
Notifications
You must be signed in to change notification settings - Fork 4
Manual(Scripted) Animations
In order to control geckolib animations from scripts, you need to use a special class called AnimationBuilder.
Here is the interface of this class
public class AnimationBuilder {
public AnimationBuilder addAnimation(String animationName);
public AnimationBuilder addRepeatingAnimation(String animationName, int timesToRepeat);
public AnimationBuilder playOnce(String animationName);
public AnimationBuilder loop(String animationName);
public AnimationBuilder playAndHold(String animationName);
public AnimationBuilder clearAnimations();
}
This class uses Builder design pattern, so you can write chained calls like this
builder.playOnce("anim1").playOnce("anim2").playOnce("anim3").loop("anim4") ...
For more convenient use, some useful methods were added to already existing CNPC API classes
NpcAPI:
public AnimationBuilder createAnimBuilder();ICustomNpc, IBlockScripted:
public void syncAnimationsFor(IPlayer player, AnimationBuilder builder);
public void syncAnimationsForAll(AnimationBuilder builder);Making an NPC wave his hand when interacted
function interact(event){ //The script should be performed during interact
var builder = event.API.createAnimBuilder() //We create an animation builder
builder.playOnce("animation.custom_model.wave") //We add a wave animation into it
event.npc.syncAnimationsFor(event.player, builder) //We synchronise the animation for the player, who interacted with the npc
}In order to control geckolib animations from scripts, you need to use a special class called AnimationBuilder.
Here is the interface of this class
public class RawAnimation {
public RawAnimation thenPlay(String animationName);
public RawAnimation thenLoop(String animationName);
public RawAnimation thenPlayAndHold(String animationName);
public RawAnimation thenPlayXTimes(String animationName, int playCount);
public RawAnimation thenWait(int ticks);
}
This class uses Builder design pattern, so you can write chained calls like this
builder.thenPlay("anim1").thenPlay("anim2").thenPlay("anim3").thenLoop("anim4") ...
For more convenient use, some useful methods were added to already existing CNPC API classes
NpcAPI:
public RawAnimation createAnimBuilder();ICustomNpc, IBlockScripted:
public void syncAnimationsFor(IPlayer player, RawAnimation builder);
public void syncAnimationsForAll(RawAnimation builder);Making an NPC wave his hand when interacted
function interact(event){ //The script should be performed during interact
var builder = event.API.createAnimBuilder() //We create an animation builder
builder.thenPlay("wave") //We add a wave animation into it
event.npc.syncAnimationsFor(event.player, builder) //We synchronise the animation for the player, who interacted with the npc
}