API reference Obsidian.API.Entities
IEntityBehavior interface
What the entities of a plugin's entity type do. Implement the methods the entity needs.
public interface IEntityBehavior
In Obsidian.API.
Remarks
The behaviour belongs to the plugin and is dropped when the plugin unloads, while its entities are kept in their chunks as saved until it's loaded again, so keep state on the entity or in the plugin, not here.
Methods
CanMount(IEntity, IPlayer)
bool CanMount(IEntity entity, IPlayer player);Called when a player who isn't sneaking uses a mob and IEntityBehavior.InteractAsync didn't use the interaction: whether the player mounts it (see IPlayer.StartRiding).
CanSpawn(ILevel, Vector)
bool CanSpawn(ILevel level, Vector position);Called before natural spawning places a mob of a type with a EntityProperties.SpawnPlacement, once its placement fits, like a vanilla entity type's spawn predicate: whether it may spawn there, its feet in the block at position. Runs on the level's tick; read the level's loaded blocks only.
DiedAsync(IEntity, DamageSource)
ValueTask DiedAsync(IEntity entity, DamageSource source);Called when a mob dies, before it drops its loot table.
HitAsync(IEntity, EntityHit)
ValueTask HitAsync(IEntity projectile, EntityHit hit);Called when a projectile hits a block or a living entity, before it's removed.
HurtAsync(IEntity, EntityDamage)
ValueTask HurtAsync(IEntity entity, EntityDamage damage);Called when a mob is about to take damage, after vanilla's immunities (its fire immunity, say) and before its hurt cooldown, armour and absorption: like NeoForge's LivingIncomingDamageEvent, change EntityDamage.Amount or set EntityDamage.Cancelled to take none.
InteractAsync(IEntity, IPlayer, InteractionHand)
ValueTask<bool> InteractAsync(IEntity entity, IPlayer player, InteractionHand hand);Called when a player uses the entity (right-clicks it), before the held item's use on it.
Returns
Whether the entity used the interaction, which keeps the held item from being used on it (see IItemBehavior.UseOnEntityAsync), like a vanilla entity's interaction succeeding.
TickAsync(IEntity)
ValueTask TickAsync(IEntity entity);Called every tick the entity is alive, after its movement.