Class EntityBehavior
- Namespace
- Vintagestory.API.Common.Entities
- Assembly
- VintagestoryAPI.dll
Defines a basic entity behavior that can be attached to entities Open in GitHub
public abstract class EntityBehavior
- Inheritance
-
EntityBehavior
- Derived
- Inherited Members
- Extension Methods
Constructors
EntityBehavior(Entity)
public EntityBehavior(Entity entity)
Parameters
entityEntity
Fields
entity
public Entity entity
Field Value
Properties
ProfilerName
public string ProfilerName { get; }
Property Value
ThreadSafe
An implementing behavior can return true if it is thread-safe: allows the behavior to be multi-threaded for better multiplayer performance
public virtual bool ThreadSafe { get; }
Property Value
Methods
AfterInitialized(bool)
Called after initializing all the behaviors in case they need to cross-refer to each other or set some initial values only at spawn-time
public virtual void AfterInitialized(bool onFirstSpawn)
Parameters
onFirstSpawnbool
DidAttack(DamageSource, EntityAgent, ref EnumHandling)
public virtual void DidAttack(DamageSource source, EntityAgent targetEntity, ref EnumHandling handled)
Parameters
sourceDamageSourcetargetEntityEntityAgenthandledEnumHandling
FromBytes(bool)
This method is not called on the server side
public virtual void FromBytes(bool isSync)
Parameters
isSyncbool
GetDrops(IWorldAccessor, BlockPos, IPlayer, ref EnumHandling)
gets the drops for this specific entity.
public virtual ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
Parameters
worldIWorldAccessorThe world of this entity
posBlockPosThe block position of the entity.
byPlayerIPlayerThe player this entity was killed by.
handlingEnumHandlingHow this event was handled.
Returns
- ItemStack[]
the items dropped from this entity
GetInfoText(StringBuilder)
Gets the information text when highlighting this entity.
public virtual void GetInfoText(StringBuilder infotext)
Parameters
infotextStringBuilderThe supplied stringbuilder information.
GetInteractionHelp(IClientWorldAccessor, EntitySelection, IClientPlayer, ref EnumHandling)
Called when a player looks at the entity with interaction help enabled
public virtual WorldInteraction[] GetInteractionHelp(IClientWorldAccessor world, EntitySelection es, IClientPlayer player, ref EnumHandling handled)
Parameters
worldIClientWorldAccessoresEntitySelectionplayerIClientPlayerhandledEnumHandling
Returns
GetName(ref EnumHandling)
public virtual string GetName(ref EnumHandling handling)
Parameters
handlingEnumHandling
Returns
GetTextureSource(ref EnumHandling)
public virtual ITexPositionSource GetTextureSource(ref EnumHandling handling)
Parameters
handlingEnumHandling
Returns
GetTouchDistance(ref EnumHandling)
The distance at which entities are counted as "touching" each other, for example used by EntityPartitioning and RepulseAgents
Note: from 1.20.4 this is gathered and cached in a field when each entity is Initialized, if for any reason a mod or behavior needs to change the result later than Initialization then you should also update the Entity field .touchDistance
public virtual float GetTouchDistance(ref EnumHandling handling)
Parameters
handlingEnumHandling
Returns
Initialize(EntityProperties, JsonObject)
Initializes the entity.
If your code modifies the supplied attributes (not recommended!), then your changes will apply to all entities of the same type.
public virtual void Initialize(EntityProperties properties, JsonObject attributes)
Parameters
propertiesEntityPropertiesThe properties of this entity.
attributesJsonObjectThe attributes of this entity.
IntersectsRay(Ray, AABBIntersectionTest, out double, ref int, ref EnumHandling)
public virtual bool IntersectsRay(Ray ray, AABBIntersectionTest interesectionTester, out double intersectionDistance, ref int selectionBoxIndex, ref EnumHandling handled)
Parameters
rayRayinteresectionTesterAABBIntersectionTestintersectionDistancedoubleselectionBoxIndexinthandledEnumHandling
Returns
Notify(string, object)
The notify method bubbled up from entity.Notify()
public virtual void Notify(string key, object data)
Parameters
OnEntityDeath(DamageSource)
The event fired when the entity dies.
public virtual void OnEntityDeath(DamageSource damageSourceForDeath)
Parameters
damageSourceForDeathDamageSourceThe source of damage for the entity.
OnEntityDespawn(EntityDespawnData)
The event fired when the entity is despawned.
public virtual void OnEntityDespawn(EntityDespawnData despawn)
Parameters
despawnEntityDespawnDataThe reason the entity despawned.
OnEntityLoaded()
The event fired when the entity is loaded from disk (not called during spawn)
public virtual void OnEntityLoaded()
OnEntityReceiveDamage(DamageSource, ref float)
The event fired when the entity recieves damage.
public virtual void OnEntityReceiveDamage(DamageSource damageSource, ref float damage)
Parameters
damageSourceDamageSourceThe source of the damage
damagefloatThe amount of the damage.
OnEntityReceiveSaturation(float, EnumFoodCategory, float, float)
The event fired when the entity recieves saturation.
public virtual void OnEntityReceiveSaturation(float saturation, EnumFoodCategory foodCat = EnumFoodCategory.Unknown, float saturationLossDelay = 10, float nutritionGainMultiplier = 1)
Parameters
saturationfloatThe amount of saturation recieved.
foodCatEnumFoodCategoryThe category of food recieved.
saturationLossDelayfloatThe delay before the loss of saturation.
nutritionGainMultiplierfloat
OnEntityRevive()
When the entity got revived (only for players and traders currently)
public virtual void OnEntityRevive()
OnEntitySpawn()
The event fired when the entity is spawned (not called when loaded from the savegame).
public virtual void OnEntitySpawn()
OnFallToGround(Vec3d, double)
The event fired when the entity falls to the ground.
public virtual void OnFallToGround(Vec3d lastTerrainContact, double withYMotion)
Parameters
lastTerrainContactVec3dthe point which the entity was previously on the ground.
withYMotiondoubleThe vertical motion the entity had before landing on the ground.
OnGameTick(float)
The event fired when a game ticks over.
public virtual void OnGameTick(float deltaTime)
Parameters
deltaTimefloat
OnInteract(EntityAgent, ItemSlot, Vec3d, EnumInteractMode, ref EnumHandling)
The event fired when the entity is interacted with by the player.
public virtual void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled)
Parameters
byEntityEntityAgentThe entity it was interacted with.
itemslotItemSlotThe item slot involved (if any)
hitPositionVec3dThe hit position of the entity.
modeEnumInteractModeThe interaction mode for the entity.
handledEnumHandlingHow this event is handled.
OnLoadCollectibleMappings(IWorldAccessor, Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>, bool)
public virtual void OnLoadCollectibleMappings(IWorldAccessor worldForNewMappings, Dictionary<int, AssetLocation> oldBlockIdMapping, Dictionary<int, AssetLocation> oldItemIdMapping, bool resolveImports)
Parameters
worldForNewMappingsIWorldAccessoroldBlockIdMappingDictionary<int, AssetLocation>oldItemIdMappingDictionary<int, AssetLocation>resolveImportsbool
OnReceivedClientPacket(IServerPlayer, int, byte[], ref EnumHandling)
The event fired when the server receives a packet.
public virtual void OnReceivedClientPacket(IServerPlayer player, int packetid, byte[] data, ref EnumHandling handled)
Parameters
playerIServerPlayerThe server player.
packetidintthe packet id.
databyte[]The data contents.
handledEnumHandlingHow this event is handled.
OnReceivedServerPacket(int, byte[], ref EnumHandling)
The event fired when the client receives a packet.
public virtual void OnReceivedServerPacket(int packetid, byte[] data, ref EnumHandling handled)
Parameters
packetidintdatabyte[]handledEnumHandling
OnReceivedServerPos(bool, ref EnumHandling)
The event fired when the server position is changed.
public virtual void OnReceivedServerPos(bool isTeleport, ref EnumHandling handled)
Parameters
isTeleportboolWhether or not this entity was teleported.
handledEnumHandlingHow this event is handled.
OnStateChanged(EnumEntityState, ref EnumHandling)
The event fired when the state of the entity is changed.
public virtual void OnStateChanged(EnumEntityState beforeState, ref EnumHandling handling)
Parameters
beforeStateEnumEntityStateThe previous state.
handlingEnumHandlingHow this event was handled.
OnStoreCollectibleMappings(Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>)
public virtual void OnStoreCollectibleMappings(Dictionary<int, AssetLocation> blockIdMapping, Dictionary<int, AssetLocation> itemIdMapping)
Parameters
blockIdMappingDictionary<int, AssetLocation>itemIdMappingDictionary<int, AssetLocation>
OnTesselated()
public virtual void OnTesselated()
OnTesselation(ref Shape, string, ref bool, ref string[])
public virtual void OnTesselation(ref Shape entityShape, string shapePathForLogging, ref bool shapeIsCloned, ref string[] willDeleteElements)
Parameters
PropertyName()
The name of the property tied to this entity behavior.
public abstract string PropertyName()
Returns
ShouldEarlyLoadCollectibleMappings()
Returns true if this entity behavior needs to remap inventory items/blocks when placed as part of a schematic during world generation. If true, EarlyLoadCollectibleMappings() will be called, during schematic placement, instead of OnLoadCollectibleMappings()
public virtual bool ShouldEarlyLoadCollectibleMappings()
Returns
TestCommand(object)
Can be used by the /entity command or maybe other commands, to test behaviors
The argument will be an object provided by TextCommandCallingArgs, which can then be cast to the desired type e.g. int
public virtual void TestCommand(object arg)
Parameters
argobject
ToBytes(bool)
public virtual void ToBytes(bool forClient)
Parameters
forClientbool
ToleratesDamageFrom(Entity, ref EnumHandling)
If true, then this entity will not retaliate if attacked by the specified eOther If false, then this entity will always retaliate (disregarding subsequent)
public virtual bool ToleratesDamageFrom(Entity eOther, ref EnumHandling handling)
Parameters
eOtherEntityhandlingEnumHandling
Returns
TryEarlyLoadCollectibleMappings(IWorldAccessor, Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>, bool, EntityProperties, JsonObject)
For entities which need to load collectible mappings before Initialisation during worldgen (e.g. Armorstand)
Return true if the collectible mappings were loaded by this
public virtual bool TryEarlyLoadCollectibleMappings(IWorldAccessor worldForNewMappings, Dictionary<int, AssetLocation> oldBlockIdMapping, Dictionary<int, AssetLocation> oldItemIdMapping, bool resolveImports, EntityProperties entityProperties, JsonObject behaviorConfig)
Parameters
worldForNewMappingsIWorldAccessoroldBlockIdMappingDictionary<int, AssetLocation>oldItemIdMappingDictionary<int, AssetLocation>resolveImportsboolentityPropertiesEntityPropertiesbehaviorConfigJsonObject
Returns
TryGiveItemStack(ItemStack, ref EnumHandling)
public virtual bool TryGiveItemStack(ItemStack itemstack, ref EnumHandling handling)
Parameters
itemstackItemStackhandlingEnumHandling
Returns
UpdateColSelBoxes()
public virtual void UpdateColSelBoxes()