Modding:Synchronization: Difference between revisions
(→Blocks: Add link to Modding:Right_click_events) |
|||
Line 10: | Line 10: | ||
=== Blocks === | === Blocks === | ||
Code for block interactions are called on the client and server side, however when you implement <code>OnBlockInteractStart</code> you must return true if you want the action to also get executed on the server. | Code for block interactions are called on the client and server side, however when you implement [[Modding:Right_click_events|<code>OnBlockInteractStart</code>]] you must return true if you want the action to also get executed on the server. | ||
=== Entities === | === Entities === |
Latest revision as of 09:54, 27 June 2024
As a modder, if haven't had experience with multiplayer environments, the learning curve can be a bit steep at first. This document is here to help you with common pitfalls. As a general rule of thumb, the Vintage Story Client<->Server Architecture is server authoritative. That means the server has the sole authority over drops, crafting, entity simulation, chunk loading, and so on... which allows for some baseline of hacking protection.
Client to Server
Player
The game client automatically sends player position and player controls, i.e. EntityControls
to the server. This object can tell you if the player currently walks, sneaks, is using a held item and more.
Blocks
Code for block interactions are called on the client and server side, however when you implement OnBlockInteractStart
you must return true if you want the action to also get executed on the server.
Entities
Entity interactions are always synced to the server and the same is called there.
Inventory
If the player has any opened inventory, all relevant inventory code must be executed on the client and the server. inventory.Open()
and .Close()
must also be called on both sides when the gui is opened/closed.
Server to Client
If you run code on the server alone, some of it may need to be explicity synchronized to the client.
Blocks
A call to SetBlock()
and ExchangeBlock()
is automatically synced.
If you change any data on a block entity, you usualay have to call MarkDirty()
inside the block entity. It will resend all block entity data to all nearby clients.
Inventory
Changing inventory contents usually requires you to call slot.MarkDirty()
so that the client sees the change.
Sound&Particles
Playing sounds and spawning particles on the server side is possible! These are automatically synced to all nearby clients.