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
Properties
ProfilerName
public string ProfilerName { 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
onFirstSpawn
bool
DidAttack(DamageSource, EntityAgent, ref EnumHandling)
public virtual void DidAttack(DamageSource source, EntityAgent targetEntity, ref EnumHandling handled)
Parameters
source
DamageSourcetargetEntity
EntityAgenthandled
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
IWorldAccessorThe world of this entity
pos
BlockPosThe block position of the entity.
byPlayer
IPlayerThe player this entity was killed by.
handling
EnumHandlingHow 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
StringBuilderThe 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
IClientWorldAccessores
EntitySelectionplayer
IClientPlayerhandled
EnumHandling
Returns
GetTextureSource(ref EnumHandling)
public virtual ITexPositionSource GetTextureSource(ref EnumHandling handling)
Parameters
handling
EnumHandling
Returns
GetTouchDistance(ref EnumHandling)
public virtual float GetTouchDistance(ref EnumHandling handling)
Parameters
handling
EnumHandling
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
properties
EntityPropertiesThe properties of this entity.
attributes
JsonObjectThe 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
RayinteresectionTester
AABBIntersectionTestintersectionDistance
doubleselectionBoxIndex
inthandled
EnumHandling
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
damageSourceForDeath
DamageSourceThe source of damage for the entity.
OnEntityDespawn(EntityDespawnData)
The event fired when the entity is despawned.
public virtual void OnEntityDespawn(EntityDespawnData despawn)
Parameters
despawn
EntityDespawnDataThe 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
DamageSourceThe source of the damage
damage
floatThe 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
floatThe amount of saturation recieved.
foodCat
EnumFoodCategoryThe category of food recieved.
saturationLossDelay
floatThe 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
Vec3dthe point which the entity was previously on the ground.
withYMotion
doubleThe 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
EntityAgentThe entity it was interacted with.
itemslot
ItemSlotThe item slot involved (if any)
hitPosition
Vec3dThe hit position of the entity.
mode
EnumInteractModeThe interaction mode for the entity.
handled
EnumHandlingHow 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
IWorldAccessoroldBlockIdMapping
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
IServerPlayerThe server player.
packetid
intthe packet id.
data
byte[]The data contents.
handled
EnumHandlingHow 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
intdata
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
boolWhether or not this entity was teleported.
handled
EnumHandlingHow 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
EnumEntityStateThe previous state.
handling
EnumHandlingHow 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
PropertyName()
The name of the property tied to this entity behavior.
public abstract string PropertyName()
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
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
ItemStackhandling
EnumHandling
Returns
UpdateColSelBoxes()
public virtual void UpdateColSelBoxes()