Table of Contents

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

action Action
code string

Task category identifier for the frame profiler

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 string
data 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

OnTimePassed Action<float>
millisecondDelay int

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

OnTimePassed Action<float>
millisecondDelay int
permittedWhilePaused bool

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

OnTimePassed Action<IWorldAccessor, BlockPos, float>
pos BlockPos
millisecondDelay int

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 EventBusListenerDelegate

The handler for the events

priority double

Set this to a different value if you want to catch an event before/after another mod catches it

filterByEventName string

If 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 int
initialDelayOffsetMs 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

onGameTick Action<float>
millisecondInterval int
initialDelayOffsetMs int

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 BlockPos
millisecondInterval int
initialDelayOffsetMs int

Returns

long

listenerId

TriggerEntityDeath(Entity, DamageSource)

void TriggerEntityDeath(Entity entity, DamageSource damageSourceForDeath)

Parameters

entity Entity
damageSourceForDeath DamageSource

TriggerMatchesRecipe(IPlayer, GridRecipe, ItemSlot[], int)

bool TriggerMatchesRecipe(IPlayer forPlayer, GridRecipe gridRecipe, ItemSlot[] ingredients, int gridWidth)

Parameters

forPlayer IPlayer
gridRecipe GridRecipe
ingredients ItemSlot[]
gridWidth int

Returns

bool

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

ChunkDirtyDelegate

MapRegionLoaded

Called whenever the server loaded from disk or newly generated a map region

event MapRegionLoadedDelegate MapRegionLoaded

Event Type

MapRegionLoadedDelegate

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

MapRegionUnloadDelegate

MatchesGridRecipe

Called when a player tries to gridcraft something

event MatchGridRecipeDelegate MatchesGridRecipe

Event Type

MatchGridRecipeDelegate

OnEntityDeath

event EntityDeathDelegate OnEntityDeath

Event Type

EntityDeathDelegate

OnEntityDespawn

Triggered when a new entity despawned

event EntityDespawnDelegate OnEntityDespawn

Event Type

EntityDespawnDelegate

OnEntityLoaded

Triggered when a new entity got loaded (either spawned or loaded from disk)

event EntityDelegate OnEntityLoaded

Event Type

EntityDelegate

OnEntitySpawn

Triggered when a new entity spawned

event EntityDelegate OnEntitySpawn

Event Type

EntityDelegate

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

OnGetClimateDelegate

OnGetWindSpeed

Called whenever any method calls world.BlockAccessor.GetWindSpeedAt(). Used by the survival mod to set the wind speed

event OnGetWindSpeedDelegate OnGetWindSpeed

Event Type

OnGetWindSpeedDelegate

OnTestBlockAccess

Triggered when block access is tested, allows you to override the engine response

event TestBlockAccessDelegate OnTestBlockAccess

Event Type

TestBlockAccessDelegate