Table of Contents

Interface IServerEventAPI

Namespace
Vintagestory.API.Server
Assembly
VintagestoryAPI.dll

Contains methods to hook into various server processes

public interface IServerEventAPI : IEventAPI
Inherited Members
Extension Methods

Methods

ChunkColumnGeneration(ChunkColumnGenerationDelegate, EnumWorldGenPass, string)

Vintagestory uses this method to generate the basic terrain (base terrain + rock strata + caves) in full columns. Only called once in pass EnumWorldGenPass.TerrainNoise. Register to this event if you need acces to a whole chunk column during inital generation.

void ChunkColumnGeneration(ChunkColumnGenerationDelegate handler, EnumWorldGenPass pass, string forWorldType)

Parameters

handler ChunkColumnGenerationDelegate
pass EnumWorldGenPass
forWorldType string

For which world types to use this generator

GetRegisteredWorldGenHandlers(string)

Returns the list of currently registered map chunk generator handlers for given world type. Returns an array of handler lists. Each element in the array represents all the handlers for one worldgenpass (see EnumWorldGenPass) When world type is null, all handlers are returned

IWorldGenHandler GetRegisteredWorldGenHandlers(string worldType)

Parameters

worldType string

"standard" for the vanilla world generator

Returns

IWorldGenHandler

GetWorldgenBlockAccessor(WorldGenThreadDelegate)

If you require neighbour chunk data during world generation, you have to register to this event to receive access to the chunk generator thread. This method is only called once during server startup.

void GetWorldgenBlockAccessor(WorldGenThreadDelegate handler)

Parameters

handler WorldGenThreadDelegate

InitWorldGenerator(Action, string)

Triggered before the first chunk, map chunk or map region is generated, given that the passed on world type has been selected. Called right after the save game has been loaded.

void InitWorldGenerator(Action handler, string forWorldType)

Parameters

handler Action
forWorldType string

MapChunkGeneration(MapChunkGeneratorDelegate, string)

Event that is triggered whenever a new column of chunks is being generated. It is always called before the ChunkGenerator event

void MapChunkGeneration(MapChunkGeneratorDelegate handler, string forWorldType)

Parameters

handler MapChunkGeneratorDelegate
forWorldType string

For which world types to use this generator

MapRegionGeneration(MapRegionGeneratorDelegate, string)

Event that is triggered whenever a new 16x16 section of column of chunks is being generated. It is always called before the ChunkGenerator and before the MapChunkGeneration event

void MapRegionGeneration(MapRegionGeneratorDelegate handler, string forWorldType)

Parameters

handler MapRegionGeneratorDelegate
forWorldType string

For which world types to use this generator

ServerRunPhase(EnumServerRunPhase, Action)

Triggered whenever the server enters a new run phase. Since mods are only loaded during run phase "LoadGamePre" registering to any earlier event will get triggered.

void ServerRunPhase(EnumServerRunPhase runPhase, Action handler)

Parameters

runPhase EnumServerRunPhase
handler Action

Timer(Action, double)

Registers a method to be called every given interval

void Timer(Action handler, double interval)

Parameters

handler Action
interval double

TriggerTrySpawnEntity(IBlockAccessor, ref EntityProperties, Vec3d, long)

bool TriggerTrySpawnEntity(IBlockAccessor blockAccessor, ref EntityProperties properties, Vec3d position, long herdId)

Parameters

blockAccessor IBlockAccessor
properties EntityProperties
position Vec3d
herdId long

Returns

bool

TriggerWorldgenHook(string, IBlockAccessor, BlockPos, string)

Trigger the special worldgen hook, with the name "hook", if it exists

void TriggerWorldgenHook(string hook, IBlockAccessor blockAccessor, BlockPos pos, string param)

Parameters

hook string
blockAccessor IBlockAccessor
pos BlockPos
param string

WorldgenHook(WorldGenHookDelegate, string, string)

Registers a method to be called by certain special worldgen triggers, for example Resonance Archives entrance staircase

void WorldgenHook(WorldGenHookDelegate handler, string forWorldType, string hook)

Parameters

handler WorldGenHookDelegate
forWorldType string
hook string

Events

AfterActiveSlotChanged

Fired after a player changes their active slot (such as selected hotbar slot).

event Action<IServerPlayer, ActiveSlotChangeEventArgs> AfterActiveSlotChanged

Event Type

Action<IServerPlayer, ActiveSlotChangeEventArgs>

AssetsFinalizers

Triggered after assets have been loaded and parsed and registered, but before they are declared to be ready - e.g. you can add more behaviors here, or make other code-based changes to properties read from JSONs
Note: modsystems should register for this in a Start() method not StartServerSide(): the AssetsFinalizer event is fired before StartServerSide() is reached

[Obsolete("Override Method Modsystem.AssetsFinalize instead")]
event Action AssetsFinalizers

Event Type

Action

BeforeActiveSlotChanged

Fired before a player changes their active slot (such as selected hotbar slot). Allows for the event to be cancelled depending on the return value.

event Func<IServerPlayer, ActiveSlotChangeEventArgs, EnumHandling> BeforeActiveSlotChanged

Event Type

Func<IServerPlayer, ActiveSlotChangeEventArgs, EnumHandling>

BeginChunkColumnLoadChunkThread

Called when just loaded (or generated) a full chunkcolumn

event ChunkColumnBeginLoadChunkThread BeginChunkColumnLoadChunkThread

Event Type

ChunkColumnBeginLoadChunkThread

BreakBlock

Called when a block should got broken now (that has been broken by a player). Set handling to PreventDefault to handle the block breaking yourself. Otherwise the engine will break the block (= either call heldItemstack.Collectible.OnBlockBrokenWith when player holds something in his hands or block.OnBlockBroken).

event BlockBreakDelegate BreakBlock

Event Type

BlockBreakDelegate

CanPlaceOrBreakBlock

Registers a handler to be called every time a player places a block. The methods return value determines if the player may place/break this block. When returning false the client will be notified and the action reverted

event CanPlaceOrBreakDelegate CanPlaceOrBreakBlock

Event Type

CanPlaceOrBreakDelegate

CanUseBlock

Registers a handler to be called every time a player uses a block. The methods return value determines if the player may place/break this block.

event CanUseDelegate CanUseBlock

Event Type

CanUseDelegate

ChunkColumnLoaded

Called whenever the server loaded from disk or fully generated a chunkcolumn

event ChunkColumnLoadedDelegate ChunkColumnLoaded

Event Type

ChunkColumnLoadedDelegate

ChunkColumnUnloaded

Called just before a chunk column is about to get unloaded. On shutdown this method is called for all loaded chunks, so this method can get called tens of thousands of times there, beware

event ChunkColumnUnloadDelegate ChunkColumnUnloaded

Event Type

ChunkColumnUnloadDelegate

DidBreakBlock

Registers a method to be called every time a player deletes a block. Called after the block was already broken

event BlockBrokenDelegate DidBreakBlock

Event Type

BlockBrokenDelegate

DidPlaceBlock

Registers a method to be called every time a player places a block

event BlockPlacedDelegate DidPlaceBlock

Event Type

BlockPlacedDelegate

DidUseBlock

Registers a method to be called every time a player uses a block

event BlockUsedDelegate DidUseBlock

Event Type

BlockUsedDelegate

GameWorldSave

Triggered before the game world data is being saved to disk

event Action GameWorldSave

Event Type

Action

OnPlayerInteractEntity

Called when a player interacts with an entity

event OnInteractDelegate OnPlayerInteractEntity

Event Type

OnInteractDelegate

OnTrySpawnEntity

Called when the server attempts to spawn given entity. Return false to deny spawning.

event TrySpawnEntityDelegate OnTrySpawnEntity

Event Type

TrySpawnEntityDelegate

PlayerChat

Called when a player wrote a chat message

event PlayerChatDelegate PlayerChat

Event Type

PlayerChatDelegate

PlayerCreate

Called when a new player joins

event PlayerDelegate PlayerCreate

Event Type

PlayerDelegate

PlayerDeath

Called when a player died

event PlayerDeathDelegate PlayerDeath

Event Type

PlayerDeathDelegate

PlayerDisconnect

Called whenever a player disconnects (timeout, leave, disconnect, kick, etc.).

event PlayerDelegate PlayerDisconnect

Event Type

PlayerDelegate

PlayerJoin

Called when a player joins

event PlayerDelegate PlayerJoin

Event Type

PlayerDelegate

PlayerLeave

Called when a player intentionally leaves

event PlayerDelegate PlayerLeave

Event Type

PlayerDelegate

PlayerNowPlaying

Called when a player joins and his client is now fully loaded and ready to play

event PlayerDelegate PlayerNowPlaying

Event Type

PlayerDelegate

PlayerRespawn

Called when a player got respawned

event PlayerDelegate PlayerRespawn

Event Type

PlayerDelegate

PlayerSwitchGameMode

Whenever a player switched his game mode or has it switched for him

event PlayerDelegate PlayerSwitchGameMode

Event Type

PlayerDelegate

SaveGameCreated

Triggered after a savegame has been created - i.e. when a new world was created

event Action SaveGameCreated

Event Type

Action

SaveGameLoaded

Triggered after the game world data has been loaded. At this point all blocks are loaded and the Map size is known.

In 1.17+ do NOT use this server event to add or update behaviors or attributes or other fixed properties of any block, item or entity, in code (additional to what is read from JSON). Instead, code which needs to do that should be registered for event sapi.Event.AssetsFinalizers. See VSSurvivalMod system BlockReinforcement.cs for an example.

event Action SaveGameLoaded

Event Type

Action

ServerResume

Called when something wants to resume execution of the server, e.g. the autosave system

event ResumeServerDelegate ServerResume

Event Type

ResumeServerDelegate

ServerSuspend

Called when something wants to pause the server, e.g. the autosave system. This method will be called every 50ms until all delegates return Ready state. Timeout is 60 seconds.

event SuspendServerDelegate ServerSuspend

Event Type

SuspendServerDelegate

WorldgenStartup

Triggered when starting up worldgen during server startup (as the final stage of the WorldReady EnumServerRunPhase)

event Action WorldgenStartup

Event Type

Action