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
Extension Methods

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

alwaysRunIdle

protected bool alwaysRunIdle

Field Value

bool

controls

protected EntityControls controls

Field Value

EntityControls

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

sidewaysSwivelAngle

public float sidewaysSwivelAngle

Field Value

float

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

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 IMountableSeat MountedOn { get; protected set; }

Property Value

IMountableSeat

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

OnEntityDespawn(EntityDespawnData)

Called when the entity despawns

public override void OnEntityDespawn(EntityDespawnData despawn)

Parameters

despawn EntityDespawnData

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

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(IMountableSeat)

Attempts to mount this entity on a target.

public virtual bool TryMount(IMountableSeat onmount)

Parameters

onmount IMountableSeat

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.

doMount(IMountableSeat)

protected virtual void doMount(IMountableSeat mountable)

Parameters

mountable IMountableSeat

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()