Table of Contents

Class EntityAgent

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

A goal-directed entity which observes and acts upon an environment

public class EntityAgent : Entity
Inheritance
EntityAgent
Derived
Inherited Members

Constructors

EntityAgent()

public EntityAgent()

Fields

AllowDespawn

Whether or not the entity is allowed to despawn (Default: true)

public bool AllowDespawn

Field Value

bool

CurrentControls

public EnumEntityActivity CurrentControls

Field Value

EnumEntityActivity

DeadNotify

True if all clients have to be informed about this entities death. Set to false once all clients have been notified

public bool DeadNotify

Field Value

bool

controls

protected EntityControls controls

Field Value

EntityControls

hideClothing

public bool hideClothing

Field Value

bool

insideBlock

updated by GetWalkSpeedMultiplier()

protected Block insideBlock

Field Value

Block

insidePos

updated by GetWalkSpeedMultiplier()

protected BlockPos insidePos

Field Value

BlockPos

servercontrols

protected EntityControls servercontrols

Field Value

EntityControls

Properties

ActiveHandItemSlot

public virtual ItemSlot ActiveHandItemSlot { get; }

Property Value

ItemSlot

BodyYaw

The yaw of the agents body

public virtual float BodyYaw { get; set; }

Property Value

float

BodyYawServer

The yaw of the agents body on the client, retrieved from the server (BehaviorInterpolatePosition lerps this value and sets BodyYaw)

public virtual float BodyYawServer { get; set; }

Property Value

float

Controls

The controls for this entity.

public EntityControls Controls { get; }

Property Value

EntityControls

GearInventory

The inventory of the entity agent.

public virtual IInventory GearInventory { get; set; }

Property Value

IInventory

HerdId

Unique identifier for a herd

public long HerdId { get; set; }

Property Value

long

IsCreature

Used by AItasks for perfomance. When searching for nearby entities we distinguish between (A) Creatures and (B) Inanimate entitie. Inanimate entities are items on the ground, projectiles, armor stands, rafts, falling blocks etc
Note 1: Dead creatures / corpses count as a Creature. EntityPlayer is a Creature of course.
Note 2: Straw Dummy we count as a Creature, because weapons can target it and bees can attack it. In contrast, Armor Stand we count as Inanimate, because nothing should ever attack or target it.

public override bool IsCreature { get; }

Property Value

bool

LeftHandItemSlot

Item in the left hand slot of the entity agent.

public virtual ItemSlot LeftHandItemSlot { get; set; }

Property Value

ItemSlot

MountedOn

public IMountable MountedOn { get; protected set; }

Property Value

IMountable

RightHandItemSlot

Item in the right hand slot of the entity agent.

public virtual ItemSlot RightHandItemSlot { get; set; }

Property Value

ItemSlot

ServerControls

The server controls for this entity

public EntityControls ServerControls { get; }

Property Value

EntityControls

ShouldDespawn

Whether or not the entity should despawn.

public override bool ShouldDespawn { get; }

Property Value

bool

Methods

DidAttack(DamageSource, EntityAgent)

public virtual void DidAttack(DamageSource source, EntityAgent targetEntity)

Parameters

source DamageSource
targetEntity EntityAgent

Die(EnumDespawnReason, DamageSource)

Makes the entity despawn. Entities only drop something on EnumDespawnReason.Death

public override void Die(EnumDespawnReason reason = EnumDespawnReason.Death, DamageSource damageSourceForDeath = null)

Parameters

reason EnumDespawnReason
damageSourceForDeath DamageSource

FromBytes(BinaryReader, bool)

Loads the entity from a stored byte array from the SaveGame

public override void FromBytes(BinaryReader reader, bool forClient)

Parameters

reader BinaryReader
forClient bool

GetHeadPositionFromWatchedAttributes()

Relevant only for entities with heads, implemented in EntityAgent. Other sub-classes of Entity (if not EntityAgent) should similarly override this if the headYaw/headPitch are relevant to them

protected override void GetHeadPositionFromWatchedAttributes()

GetWalkSpeedMultiplier(double)

Gets the walk speed multiplier.

public virtual double GetWalkSpeedMultiplier(double groundDragFactor = 0.3)

Parameters

groundDragFactor double

The amount of drag provided by the current ground. (Default: 0.3)

Returns

double

HandleHandAnimations(float)

protected virtual void HandleHandAnimations(float dt)

Parameters

dt float

Initialize(EntityProperties, ICoreAPI, long)

Called when this entity got created or loaded

public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)

Parameters

properties EntityProperties
api ICoreAPI
InChunkIndex3d long

IsEyesSubmerged()

Are the eyes of this entity submerged in liquid?

public bool IsEyesSubmerged()

Returns

bool

OnGameTick(float)

Called every 1/75 second

public override void OnGameTick(float dt)

Parameters

dt float

OnInteract(EntityAgent, ItemSlot, Vec3d, EnumInteractMode)

Called when an entity has interacted with this entity

public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode)

Parameters

byEntity EntityAgent
slot ItemSlot
hitPosition Vec3d

Relative position on the entites hitbox where the entity interacted at

mode EnumInteractMode

0 = attack, 1 = interact

OnLoadCollectibleMappings(IWorldAccessor, Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>, int, bool)

Called by the blockschematic loader so that you may fix any blockid/itemid mappings against the mapping of the savegame, if you store any collectibles in this blockentity. Note: Some vanilla blocks resolve randomized contents in this method. Hint: Use itemstack.FixMapping() to do the job for you.

public override void OnLoadCollectibleMappings(IWorldAccessor worldForResolve, Dictionary<int, AssetLocation> oldBlockIdMapping, Dictionary<int, AssetLocation> oldItemIdMapping, int schematicSeed, bool resolveImports)

Parameters

worldForResolve IWorldAccessor
oldBlockIdMapping Dictionary<int, AssetLocation>
oldItemIdMapping Dictionary<int, AssetLocation>
schematicSeed int

If you need some sort of randomness consistency accross an imported schematic, you can use this value

resolveImports bool

Turn it off to spawn structures as they are. For example, in this mode, instead of traders, their meta spawners will spawn

OnNoPath(Vec3d)

Called when the path finder does not find a path to given target

public void OnNoPath(Vec3d target)

Parameters

target Vec3d

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

Called by the worldedit schematic exporter so that it can also export the mappings of items/blocks stored inside blockentities

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

Parameters

blockIdMapping Dictionary<int, AssetLocation>
itemIdMapping Dictionary<int, AssetLocation>

OnTesselation(ref Shape, string)

Called by EntityShapeRenderer.cs before tesselating the entity shape

public override void OnTesselation(ref Shape entityShape, string shapePathForLogging)

Parameters

entityShape Shape
shapePathForLogging string

ReceiveDamage(DamageSource, float)

Called when the entity should be receiving damage from given source

public override bool ReceiveDamage(DamageSource damageSource, float damage)

Parameters

damageSource DamageSource
damage float

Returns

bool

True if the entity actually received damage

ReceiveSaturation(float, EnumFoodCategory, float, float)

Recieves the saturation from a food source.

public virtual void ReceiveSaturation(float saturation, EnumFoodCategory foodCat = EnumFoodCategory.Unknown, float saturationLossDelay = 10, float nutritionGainMultiplier = 1)

Parameters

saturation float

The amount of saturation recieved.

foodCat EnumFoodCategory

The cat of food... err Category of food.

saturationLossDelay float

The delay before the loss of saturation

nutritionGainMultiplier float

SetHeadPositionToWatchedAttributes()

Relevant only for entities with heads, implemented in EntityAgent. Other sub-classes of Entity (if not EntityAgent) should similarly override this if the headYaw/headPitch are relevant to them

protected override void SetHeadPositionToWatchedAttributes()

ShouldReceiveDamage(DamageSource, float)

Should return true if the entity can get damaged by given damageSource. Is called by ReceiveDamage.

public override bool ShouldReceiveDamage(DamageSource damageSource, float damage)

Parameters

damageSource DamageSource
damage float

Returns

bool

ShouldReceiveSaturation(float, EnumFoodCategory, float, float)

Whether or not the target should recieve saturation.

public virtual bool ShouldReceiveSaturation(float saturation, EnumFoodCategory foodCat = EnumFoodCategory.Unknown, float saturationLossDelay = 10, float nutritionGainMultiplier = 1)

Parameters

saturation float

The amount of saturation recieved.

foodCat EnumFoodCategory

The cat of food... err Category of food.

saturationLossDelay float

The delay before the loss of saturation

nutritionGainMultiplier float

Returns

bool

SpawnFloatingSediment(IAsyncParticleManager)

protected virtual void SpawnFloatingSediment(IAsyncParticleManager manager)

Parameters

manager IAsyncParticleManager

SpawnSnowStepParticles()

protected virtual void SpawnSnowStepParticles()

ToBytes(BinaryWriter, bool)

Serializes the slots contents to be stored in the SaveGame

public override void ToBytes(BinaryWriter writer, bool forClient)

Parameters

writer BinaryWriter
forClient bool

TryGiveItemStack(ItemStack)

Called when something tries to given an itemstack to this entity

public override bool TryGiveItemStack(ItemStack itemstack)

Parameters

itemstack ItemStack

Returns

bool

TryMount(IMountable)

Attempts to mount the player on a target.

public virtual bool TryMount(IMountable onmount)

Parameters

onmount IMountable

The mount to mount

Returns

bool

Whether it was mounted or not.

TryStopHandAction(bool, EnumItemUseCancelReason)

Attempts to stop the hand action.

public virtual bool TryStopHandAction(bool isCancel, EnumItemUseCancelReason cancelReason = EnumItemUseCancelReason.ReleasedMouse)

Parameters

isCancel bool

Whether or not the action is cancelled or stopped.

cancelReason EnumItemUseCancelReason

The reason for stopping the action.

Returns

bool

Whether the stop was cancelled or not.

TryUnmount()

Attempts to un-mount the player.

public bool TryUnmount()

Returns

bool

Whether or not unmounting was successful

UpdateDebugAttributes()

Updates the DebugAttributes tree

public override void UpdateDebugAttributes()

WalkInventory(OnInventorySlot)

This walks the inventory for the entity agent.

public virtual void WalkInventory(OnInventorySlot handler)

Parameters

handler OnInventorySlot

the event to fire while walking the inventory.

addGearToShape(ItemSlot, Shape, string)

protected virtual Shape addGearToShape(ItemSlot slot, Shape entityShape, string shapePathForLogging)

Parameters

slot ItemSlot
entityShape Shape
shapePathForLogging string

Returns

Shape

addGearToShape(ref Shape, string)

protected Shape addGearToShape(ref Shape entityShape, string shapePathForLogging)

Parameters

entityShape Shape
shapePathForLogging string

Returns

Shape

doMount(IMountable)

protected virtual void doMount(IMountable mountable)

Parameters

mountable IMountable

onAnimControls(AnimationMetaData, bool, bool)

protected virtual bool onAnimControls(AnimationMetaData anim, bool wasActive, bool nowActive)

Parameters

anim AnimationMetaData
wasActive bool
nowActive bool

Returns

bool

updateMountedState()

protected virtual void updateMountedState()