Interface IAnimationHook
- All Known Implementing Classes:
AudioAnimationHook
Animation.
The animation hook works very similarly to the IAnimatedBlockHook. The main difference is that instead of
hooking into the animated blocks themselves, they hook into the animation.
The animation hook allows its hooks to override methods to perform actions on specific events, such as
onAnimationCompleted() or onPostAnimationStep().
To use animation hooks, you need to register a subclass of IAnimationHookFactory with the
AnimationHookManager. An instance of this class can be obtained using
IAnimatedArchitecturePlatform.getAnimationHookManager().
Example usage:
private void registerMyAnimationHookFactory(IAnimatedArchitecturePlatform animatedArchitecturePlatform)
{
animatedArchitecturePlatform.getAnimationHookManager().registerFactory(
animation -> new MyAnimationHook(animation));
}
private static final class MyAnimationHook implements IAnimationHook<IAnimatedBlock>
{
private final Animation<IAnimatedBlock> animation;
MyAnimationHook(Animation<IAnimatedBlock> animation)
{
this.animation = animation;
}
@Override
public String getName()
{
return "MyAnimationHook";
}
@Override
public void onPostAnimationStep()
{
// Some code that is executed after each step of the animation.
}
}
The factory receives an Animation object and is called when a new animation is started by the
IAnimator. Whether the factory returns a new hook or reuses an existing one is up to the implementation. If
the factory returns null, the hook will not be registered for the given animation.
You can refer to the animation hook used by the audio system to see a full implementation:
AudioAnimationHook.
-
Method Summary
Modifier and TypeMethodDescriptiongetName()Returns the name of this hook.default voidExecuted when the animation has been aborted.default voidExecuted when the animation finishes.default voidExecuted when the animation is in the finishing phase.default voidExecuted after a new animation step is applied.default voidExecuted before a new animation step is applied.default voidExecuted right before the animation starts.
-
Method Details
-
getName
String getName()Returns the name of this hook.This is mostly used for logging purposes.
- Returns:
- The name of this hook.
-
onPreAnimationStep
default void onPreAnimationStep()Executed before a new animation step is applied.Note that this may never happen if the animation is skipped.
-
onPostAnimationStep
default void onPostAnimationStep()Executed after a new animation step is applied.Note that this may never happen if the animation is skipped.
-
onPrepare
default void onPrepare()Executed right before the animation starts.Note that this may never happen if the animation is skipped.
-
onAnimationEnding
default void onAnimationEnding()Executed when the animation is in the finishing phase.Note that this may never happen if the animation is skipped.
-
onAnimationAborted
default void onAnimationAborted()Executed when the animation has been aborted.This is not part of the normal animation pipeline. It may occur when the plugin stops, or when the chunks for the animation are being unloaded.
-
onAnimationCompleted
default void onAnimationCompleted()Executed when the animation finishes.
-