package software.bernie.geckolib.animatable; import net.minecraft.class_1937; import net.minecraft.class_2586; import net.minecraft.class_3218; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import software.bernie.geckolib.GeckoLibConstants; import software.bernie.geckolib.GeckoLibServices; import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.animation.AnimationController; import software.bernie.geckolib.constant.dataticket.SerializableDataTicket; import software.bernie.geckolib.util.RenderUtil; /** * The {@link GeoAnimatable} interface specific to {@link class_2586 BlockEntities} * * @see GeckoLib Wiki - Block Animations */ public interface GeoBlockEntity extends GeoAnimatable { /** * Get server-synced animation data via its relevant {@link SerializableDataTicket}. *
* Should only be used on the client-side *
* DO NOT OVERRIDE
*
* @param dataTicket The data ticket for the data to retrieve
* @return The synced data, or null if no data of that type has been synced
*/
@ApiStatus.NonExtendable
@Nullable
default
* DO NOT OVERRIDE
*
* @param dataTicket The DataTicket to sync the data for
* @param data The data to sync
*/
@ApiStatus.NonExtendable
default
* This can be fired from either the client or the server, but optimally you would call it from the server
*
* DO NOT OVERRIDE
*
* @param controllerName The name of the controller name the animation belongs to, or null to do an inefficient lazy search
* @param animName The name of animation to trigger. This needs to have been registered with the controller via {@link AnimationController#triggerableAnim AnimationController.triggerableAnim}
*/
@ApiStatus.NonExtendable
default void triggerAnim(@Nullable String controllerName, String animName) {
class_2586 blockEntity = (class_2586)this;
class_1937 level = blockEntity.method_10997();
if (level == null) {
GeckoLibConstants.LOGGER.error("Attempting to trigger an animation for a BlockEntity too early! Must wait until after the BlockEntity has been set in the world. (" + blockEntity.getClass().toString() + ")");
return;
}
if (level.method_8608()) {
if (controllerName != null) {
getAnimatableInstanceCache().getManagerForId(0).tryTriggerAnimation(controllerName, animName);
}
else {
getAnimatableInstanceCache().getManagerForId(0).tryTriggerAnimation(animName);
}
}
else {
GeckoLibServices.NETWORK.triggerBlockEntityAnim(blockEntity.method_11016(), controllerName, animName, (class_3218)level);
}
}
/**
* Stop a previously triggered animation for this BlockEntity for the given controller name and animation name
*
* This can be fired from either the client or the server, but optimally you would call it from the server
*
* DO NOT OVERRIDE
*
* @param controllerName The name of the controller name the animation belongs to, or null to do an inefficient lazy search
* @param animName The name of the triggered animation to stop, or null to stop any currently playing triggered animation
*/
@ApiStatus.NonExtendable
default void stopTriggeredAnim(@Nullable String controllerName, @Nullable String animName) {
class_2586 blockEntity = (class_2586)this;
class_1937 level = blockEntity.method_10997();
if (level == null) {
GeckoLibConstants.LOGGER.error("Attempting to stop a triggered animation for a BlockEntity too early! Must wait until after the BlockEntity has been set in the world. (" + blockEntity.getClass().toString() + ")");
return;
}
if (level.method_8608()) {
AnimatableManager
* By default this is just the animatable's age in ticks, but this method allows for non-ticking custom animatables to provide their own values
*
* @param blockEntity The BlockEntity representing this animatable
* @return The current tick/age of the animatable, for animation purposes
*/
@Override
default double getTick(Object blockEntity) {
return RenderUtil.getCurrentTick();
}
}