Interface IEventAPI
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
Events that are available on the server and the client
public interface IEventAPI
- Extension Methods
Methods
EnqueueMainThreadTask(Action, string)
Can be used to execute supplied method a frame later or can be called from a seperate thread to ensure some code is executed in the main thread. Calling this method is thread safe.
void EnqueueMainThreadTask(Action action, string code)
Parameters
PushEvent(string, IAttribute)
There's 2 global event busses, 1 on the client and 1 on the server. This pushes an event onto the bus.
void PushEvent(string eventName, IAttribute data = null)
Parameters
eventName
stringdata
IAttribute
RegisterCallback(Action<float>, int)
Calls given method after supplied amount of milliseconds. The engine may call your method slightly later since these event are handled only during fixed interval game ticks.
long RegisterCallback(Action<float> OnTimePassed, int millisecondDelay)
Parameters
Returns
- long
listenerId
RegisterCallback(Action<float>, int, bool)
Calls given method after supplied amount of milliseconds. The engine may call your method slightly later since these event are handled only during fixed interval game ticks. This overload can be used to signify callbacks which do no harm if registered while the game is paused (otherwise, registering a callback while paused will produce an error in logs, or an intentional exception in Developer Mode)
long RegisterCallback(Action<float> OnTimePassed, int millisecondDelay, bool permittedWhilePaused)
Parameters
Returns
- long
listenerId
RegisterCallback(Action<IWorldAccessor, BlockPos, float>, BlockPos, int)
Calls given method after supplied amount of milliseconds, lets you supply a block position to be passed to the method. The engine may call your method slightly later since these event are handled only during fixed interval game ticks.
long RegisterCallback(Action<IWorldAccessor, BlockPos, float> OnTimePassed, BlockPos pos, int millisecondDelay)
Parameters
Returns
- long
listenerId
RegisterEventBusListener(EventBusListenerDelegate, double, string)
Registers a listener on the event bus. This is intended for mods as the game engine itself does not push any events.
void RegisterEventBusListener(EventBusListenerDelegate OnEvent, double priority = 0.5, string filterByEventName = null)
Parameters
OnEvent
EventBusListenerDelegateThe handler for the events
priority
doubleSet this to a different value if you want to catch an event before/after another mod catches it
filterByEventName
stringIf set, events only with given eventName are received
RegisterGameTickListener(Action<float>, Action<Exception>, int, int)
Calls given method after every given interval until unregistered. The engine may call your method slightly later since these event are handled only during fixed interval game ticks. This overload includes an ErrorHandler callback, triggered if calling onGameTick throws an exception
long RegisterGameTickListener(Action<float> onGameTick, Action<Exception> errorHandler, int millisecondInterval, int initialDelayOffsetMs = 0)
Parameters
onGameTick
Action<float>errorHandler
Action<Exception>millisecondInterval
intinitialDelayOffsetMs
int
Returns
- long
listenerId
RegisterGameTickListener(Action<float>, int, int)
Calls given method after every given interval until unregistered. The engine may call your method slightly later since these event are handled only during fixed interval game ticks.
long RegisterGameTickListener(Action<float> onGameTick, int millisecondInterval, int initialDelayOffsetMs = 0)
Parameters
Returns
- long
listenerId
RegisterGameTickListener(Action<IWorldAccessor, BlockPos, float>, BlockPos, int, int)
Calls given method after every given interval until unregistered. The engine may call your method slightly later since these event are handled only during fixed interval game ticks.
long RegisterGameTickListener(Action<IWorldAccessor, BlockPos, float> onGameTick, BlockPos pos, int millisecondInterval, int initialDelayOffsetMs = 0)
Parameters
onGameTick
Action<IWorldAccessor, BlockPos, float>pos
BlockPosmillisecondInterval
intinitialDelayOffsetMs
int
Returns
- long
listenerId
TriggerEntityDeath(Entity, DamageSource)
void TriggerEntityDeath(Entity entity, DamageSource damageSourceForDeath)
Parameters
entity
EntitydamageSourceForDeath
DamageSource
TriggerMatchesRecipe(IPlayer, GridRecipe, ItemSlot[], int)
bool TriggerMatchesRecipe(IPlayer forPlayer, GridRecipe gridRecipe, ItemSlot[] ingredients, int gridWidth)
Parameters
forPlayer
IPlayergridRecipe
GridRecipeingredients
ItemSlot[]gridWidth
int
Returns
UnregisterCallback(long)
Removes a delayed callback
void UnregisterCallback(long listenerId)
Parameters
listenerId
long
UnregisterGameTickListener(long)
Removes a game tick listener
void UnregisterGameTickListener(long listenerId)
Parameters
listenerId
long
Events
ChunkDirty
Called whenever a chunk was marked dirty (as in, its blocks or light values have been modified or it got newly loaded or newly created)
event ChunkDirtyDelegate ChunkDirty
Event Type
MapRegionLoaded
Called whenever the server loaded from disk or newly generated a map region
event MapRegionLoadedDelegate MapRegionLoaded
Event Type
MapRegionUnloaded
Called just before a map region is about to get unloaded. On shutdown this method is called for all loaded map regions.
event MapRegionUnloadDelegate MapRegionUnloaded
Event Type
MatchesGridRecipe
Called when a player tries to gridcraft something
event MatchGridRecipeDelegate MatchesGridRecipe
Event Type
OnEntityDeath
event EntityDeathDelegate OnEntityDeath
Event Type
OnEntityDespawn
Triggered when a new entity despawned
event EntityDespawnDelegate OnEntityDespawn
Event Type
OnEntityLoaded
Triggered when a new entity got loaded (either spawned or loaded from disk)
event EntityDelegate OnEntityLoaded
Event Type
OnEntitySpawn
Triggered when a new entity spawned
event EntityDelegate OnEntitySpawn
Event Type
OnGetClimate
Called whenever any method calls world.BlockAccessor.GetClimateAt(). Used by the survival mod to modify the rainfall and temperature values to adjust for seasonal and day/night temperature variations. Be sure to also register to OnGetClimateForDate.
event OnGetClimateDelegate OnGetClimate
Event Type
OnGetWindSpeed
Called whenever any method calls world.BlockAccessor.GetWindSpeedAt(). Used by the survival mod to set the wind speed
event OnGetWindSpeedDelegate OnGetWindSpeed
Event Type
OnTestBlockAccess
Triggered when block access is tested, allows you to override the engine response
event TestBlockAccessDelegate OnTestBlockAccess