Interface IAnimatedBlockHook
IAnimatedBlocks.
The animated block hook works similarly to the IAnimationHook, but for every block in an animation instead of
one per animation.
Creating a subclass of this interface allows hooking into the animated blocks themselves. Subclasses of this
interface can override methods for specific events. For example, overriding the preMove(RotatedPosition)
method allows the hook to perform some action every time the animated block is about to be moved. There are also
methods for when an animated block (re)spawns, killing, block manipulations, etc.
When creating such a hook, you can register a factory for it with the AnimatedBlockHookManager. An instance
of that manager can be obtained using IAnimatedArchitecturePlatform.getAnimatedBlockHookManager().
Specifically, this class is used to register subclasses of IAnimatedBlockHookFactory. It is legal for the
factory to create a new hook for each animated block, to reuse existing hooks between any number of animated blocks,
or to return null, in which case the hook will not be registered for the given animated block.
Example usage:
private void registerMyAnimatedBlockHookFactory(IAnimatedArchitecturePlatform animatedArchitecturePlatform)
{
animatedArchitecturePlatform.getAnimatedBlockHookManager().registerFactory(MyAnimatedBlockHook::new);
}
private static final class MyAnimatedBlockHook implements IAnimatedBlockHook
{
private final IAnimatedBlock animatedBlock;
public MyAnimatedBlockHook(IAnimatedBlock animatedBlock)
{
this.animatedBlock = animatedBlock;
}
@Override
public String getName()
{
return "MyAnimatedBlockHook";
}
@Override
public void preSpawn()
{
// Some code that runs before the animated block is spawned.
}
}
Note that the IAnimatedBlockHookFactory has a type parameter. The type has to be a subclass of
IAnimatedBlock. This can be used to specialize the type of animated block for the specific platform. For
example, animated blocks on the Spigot platform will be subclasses of the IAnimatedBlockSpigot interface, which adds
some methods specific to the Spigot platform.
-
Method Summary
Modifier and TypeMethodDescriptiongetName()default voidFires after the block has been placed back into the world when the animation ends.default voidFires after the original block that serves as template for the animated block has been removed from the world.default voidpostKill()Fires after an animated block was killed.default voidpostMove(RotatedPosition newPosition) Fires after this animated block has been moved.default voidFires after an animated block has been respawned.default voidFires after an animated block has been spawned.default voidFires right before the block will be placed back into the world when the animation ends.default voidFires right before the original block that serves as template for the animated block will be removed from the world.default voidpreKill()Fires right before an animated block will be killed.default voidpreMove(RotatedPosition newPosition) Fires before this animated block will be moved.default voidFires right before an animated block will be respawned.default voidpreSpawn()Fires right before an animated block will be spawned.
-
Method Details
-
getName
String getName()- Returns:
- The name of this hook to use for logging purposes.
-
preSpawn
default void preSpawn()Fires right before an animated block will be spawned. Respawning is not counted. UsepreRespawn()for that.This is always called on the main thread.
-
postSpawn
default void postSpawn()Fires after an animated block has been spawned. Respawning is not counted. UsepostRespawn()for that.This is always called on the main thread.
-
preRespawn
default void preRespawn()Fires right before an animated block will be respawned.This is always called on the main thread.
-
postRespawn
default void postRespawn()Fires after an animated block has been respawned.This is always called on the main thread.
-
preKill
default void preKill()Fires right before an animated block will be killed.Respawning does not count.
This is always called on the main thread.
-
postKill
default void postKill()Fires after an animated block was killed.Respawning does not count.
This is always called on the main thread.
-
preDeleteOriginalBlock
default void preDeleteOriginalBlock()Fires right before the original block that serves as template for the animated block will be removed from the world.This is always called on the main thread.
-
postDeleteOriginalBlock
default void postDeleteOriginalBlock()Fires after the original block that serves as template for the animated block has been removed from the world.This is always called on the main thread.
-
preBlockPlace
default void preBlockPlace()Fires right before the block will be placed back into the world when the animation ends.This is always called on the main thread.
-
postBlockPlace
default void postBlockPlace()Fires after the block has been placed back into the world when the animation ends.This is always called on the main thread.
-
postMove
Fires after this animated block has been moved.This may be called asynchronously.
- Parameters:
newPosition- The position the animated block was moved to.
-
preMove
Fires before this animated block will be moved.This may be called asynchronously.
- Parameters:
newPosition- The position the animated block will move to.
-