Table of Contents

Class EntityBehavior

Namespace
Vintagestory.API.Common.Entities
Assembly
VintagestoryAPI.dll

Defines a basic entity behavior that can be attached to entities

public abstract class EntityBehavior
Inheritance
EntityBehavior
Derived
Inherited Members
Extension Methods

Constructors

EntityBehavior(Entity)

public EntityBehavior(Entity entity)

Parameters

entity Entity

Fields

entity

public Entity entity

Field Value

Entity

Properties

ProfilerName

public string ProfilerName { get; }

Property Value

string

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

onFirstSpawn bool

DidAttack(DamageSource, EntityAgent, ref EnumHandling)

public virtual void DidAttack(DamageSource source, EntityAgent targetEntity, ref EnumHandling handled)

Parameters

source DamageSource
targetEntity EntityAgent
handled EnumHandling

FromBytes(bool)

This method is not called on the server side

public virtual void FromBytes(bool isSync)

Parameters

isSync bool

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

world IWorldAccessor

The world of this entity

pos BlockPos

The block position of the entity.

byPlayer IPlayer

The player this entity was killed by.

handling EnumHandling

How 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

infotext StringBuilder

The 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

world IClientWorldAccessor
es EntitySelection
player IClientPlayer
handled EnumHandling

Returns

WorldInteraction[]

GetTextureSource(ref EnumHandling)

public virtual ITexPositionSource GetTextureSource(ref EnumHandling handling)

Parameters

handling EnumHandling

Returns

ITexPositionSource

GetTouchDistance(ref EnumHandling)

public virtual float GetTouchDistance(ref EnumHandling handling)

Parameters

handling EnumHandling

Returns

float

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

properties EntityProperties

The properties of this entity.

attributes JsonObject

The 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

ray Ray
interesectionTester AABBIntersectionTest
intersectionDistance double
selectionBoxIndex int
handled EnumHandling

Returns

bool

Notify(string, object)

The notify method bubbled up from entity.Notify()

public virtual void Notify(string key, object data)

Parameters

key string
data object

OnEntityDeath(DamageSource)

The event fired when the entity dies.

public virtual void OnEntityDeath(DamageSource damageSourceForDeath)

Parameters

damageSourceForDeath DamageSource

The source of damage for the entity.

OnEntityDespawn(EntityDespawnData)

The event fired when the entity is despawned.

public virtual void OnEntityDespawn(EntityDespawnData despawn)

Parameters

despawn EntityDespawnData

The 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

damageSource DamageSource

The source of the damage

damage float

The 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

saturation float

The amount of saturation recieved.

foodCat EnumFoodCategory

The category of food recieved.

saturationLossDelay float

The delay before the loss of saturation.

nutritionGainMultiplier float

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

lastTerrainContact Vec3d

the point which the entity was previously on the ground.

withYMotion double

The 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

deltaTime float

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

byEntity EntityAgent

The entity it was interacted with.

itemslot ItemSlot

The item slot involved (if any)

hitPosition Vec3d

The hit position of the entity.

mode EnumInteractMode

The interaction mode for the entity.

handled EnumHandling

How 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

worldForNewMappings IWorldAccessor
oldBlockIdMapping Dictionary<int, AssetLocation>
oldItemIdMapping Dictionary<int, AssetLocation>
resolveImports bool

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

player IServerPlayer

The server player.

packetid int

the packet id.

data byte[]

The data contents.

handled EnumHandling

How 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

packetid int
data byte[]
handled EnumHandling

OnReceivedServerPos(bool, ref EnumHandling)

The event fired when the server position is changed.

public virtual void OnReceivedServerPos(bool isTeleport, ref EnumHandling handled)

Parameters

isTeleport bool

Whether or not this entity was teleported.

handled EnumHandling

How 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

beforeState EnumEntityState

The previous state.

handling EnumHandling

How this event was handled.

OnStoreCollectibleMappings(Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>)

public virtual void OnStoreCollectibleMappings(Dictionary<int, AssetLocation> blockIdMapping, Dictionary<int, AssetLocation> itemIdMapping)

Parameters

blockIdMapping Dictionary<int, AssetLocation>
itemIdMapping Dictionary<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

entityShape Shape
shapePathForLogging string
shapeIsCloned bool
willDeleteElements string[]

PropertyName()

The name of the property tied to this entity behavior.

public abstract string PropertyName()

Returns

string

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

arg object

ToBytes(bool)

public virtual void ToBytes(bool forClient)

Parameters

forClient bool

TryGiveItemStack(ItemStack, ref EnumHandling)

public virtual bool TryGiveItemStack(ItemStack itemstack, ref EnumHandling handling)

Parameters

itemstack ItemStack
handling EnumHandling

Returns

bool

UpdateColSelBoxes()

public virtual void UpdateColSelBoxes()