Skip to content

Keyframe Triggers (Geckolib4)

Tslat edited this page Apr 22, 2024 · 5 revisions

GeckoLib supports custom callbacks from animations via keyframe handlers. This allows for your animation to define certain additional effects such as particles, sounds, or just about anything else.

To use this feature in BlockBench, click Animation -> Animate Effects. You'll see a new animation panel pop up in the animator. From here, you can add global keyframes to your model.

This is split into three types in GeckoLib:

  • Sounds
  • Particles
  • Custom Instructions

Sound Keyframes

To handle sound keyframe callbacks, you add an instance of SoundKeyframeHandler to your AnimationController via setSoundKeyframeHandler. This listener will then be called at the appropriate time as marked by the keyframe in the animation json. For an example of this, see the Jack in the Box example item

AutoPlayingSoundKeyframeHandler

GeckoLib has a builtin SoundKeyframeHandler that allows you to skip the boilerplate of handling basic sound playing yourself.

To use this, add a SoundKeyframeHandler like normal, but instead of your own, just pass a new instance of AutoPlayingSoundKeyframeHandler

Then, in your animation json, you can use either of the two below formats for your keyframe instructions to have the handler auto-handle the sound for you:

namespace:soundid
namespace:soundid|volume|pitch

Particle Keyframes

To handle particle keyframe callbacks, you add an instance of ParticleKeyframeHandler to your AnimationController via setParticleKeyframeHandler. This listener will then be called at the appropriate time as marked by the keyframe in the animation json.

Custom Instruction Keyframes

Custom instructions are helpful for non-sound and non-particle things you want to do to your entity at a specific time in your keyframe. To handle custom keyframe callbacks, you add an instance of ICustomInstructionListener to your AnimationController via setCustomInstructionKeyframeHandler. This listener will then be called at the appropriate time as marked by the keyframe in the animation json.

Table of Contents

Geckolib 3
Geckolib 4

Hosted By: Cloudsmith

Package repository hosting is graciously provided by Cloudsmith.

Cloudsmith is the only fully hosted, cloud-native, universal package management solution that enables your organization to create, store and share packages in any format, to any place, with total confidence.

Clone this wiki locally