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
CurrentControls
public EnumEntityActivity CurrentControls
Field Value
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
alwaysRunIdle
protected bool alwaysRunIdle
Field Value
controls
protected EntityControls controls
Field Value
insideBlock
updated by GetWalkSpeedMultiplier()
protected Block insideBlock
Field Value
insidePos
updated by GetWalkSpeedMultiplier()
protected BlockPos insidePos
Field Value
servercontrols
protected EntityControls servercontrols
Field Value
sidewaysSwivelAngle
public float sidewaysSwivelAngle
Field Value
Properties
ActiveHandItemSlot
public virtual ItemSlot ActiveHandItemSlot { get; }
Property Value
BodyYaw
The yaw of the agents body
public virtual float BodyYaw { get; set; }
Property Value
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
Controls
The controls for this entity.
public EntityControls Controls { get; }
Property Value
HerdId
Unique identifier for a herd
public long HerdId { get; set; }
Property Value
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
LeftHandItemSlot
Item in the left hand slot of the entity agent.
public virtual ItemSlot LeftHandItemSlot { get; set; }
Property Value
MountedOn
public IMountableSeat MountedOn { get; protected set; }
Property Value
RightHandItemSlot
Item in the right hand slot of the entity agent.
public virtual ItemSlot RightHandItemSlot { get; set; }
Property Value
ServerControls
The server controls for this entity
public EntityControls ServerControls { get; }
Property Value
ShouldDespawn
Whether or not the entity should despawn.
public override bool ShouldDespawn { get; }
Property Value
Methods
DidAttack(DamageSource, EntityAgent)
public virtual void DidAttack(DamageSource source, EntityAgent targetEntity)
Parameters
source
DamageSourcetargetEntity
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
EnumDespawnReasondamageSourceForDeath
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
BinaryReaderforClient
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
doubleThe amount of drag provided by the current ground. (Default: 0.3)
Returns
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
EntityPropertiesapi
ICoreAPIInChunkIndex3d
long
IsEyesSubmerged()
Are the eyes of this entity submerged in liquid?
public bool IsEyesSubmerged()
Returns
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
EntityAgentslot
ItemSlothitPosition
Vec3dRelative position on the entites hitbox where the entity interacted at
mode
EnumInteractMode0 = 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
DamageSourcedamage
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
floatThe amount of saturation recieved.
foodCat
EnumFoodCategoryThe cat of food... err Category of food.
saturationLossDelay
floatThe 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
DamageSourcedamage
float
Returns
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
floatThe amount of saturation recieved.
foodCat
EnumFoodCategoryThe cat of food... err Category of food.
saturationLossDelay
floatThe delay before the loss of saturation
nutritionGainMultiplier
float
Returns
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
BinaryWriterforClient
bool
TryGiveItemStack(ItemStack)
Called when something tries to given an itemstack to this entity
public override bool TryGiveItemStack(ItemStack itemstack)
Parameters
itemstack
ItemStack
Returns
TryMount(IMountableSeat)
Attempts to mount this entity on a target.
public virtual bool TryMount(IMountableSeat onmount)
Parameters
onmount
IMountableSeatThe 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
boolWhether or not the action is cancelled or stopped.
cancelReason
EnumItemUseCancelReasonThe 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
OnInventorySlotthe 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
AnimationMetaDatawasActive
boolnowActive
bool
Returns
updateMountedState()
protected virtual void updateMountedState()