Skip to main content

Module storage

Module storage 

Source
Expand description

Where the mod keeps its data — typed values in stores scoped the way web storage is (yog-storage), opened for this mod in the right folder:

ⓘ
use yog_api::storage;

storage::game().set("theme", &theme);              // the install, whatever world
if let Some(world) = storage::world() {            // this world, saved with it
    world.update("visits", |n: &mut u32| *n += 1);
}
storage::session().set("last_screen", &screen);    // while the game runs

Or a value kept for the mod, loaded when first used and saved with the world (WorldData, PlayerData, GameData):

ⓘ
static LABELS: WorldData<Vec<Label>> = WorldData::new("labels");
LABELS.with_mut(|labels| labels.push(label));

What’s kept with the world is written as the world is saved (server::life::Saving: an autosave, /save-all, the server stopping), so it’s saved with the world it belongs to.

A value kept for each owner — PlayerData, BlockData (gone as it’s broken) — is in the owner’s store, at the keys a Yog Script object’s saved members have; one kept on an entity (EntityData) or a stack (ItemData) is the game’s, travelling with it.

Structs§

BlockData
A value kept for each block, by dimension and place (its chunk’s store, as <x>_<y>_<z>.<key> within the chunk): removed as it’s broken or another is put there.
EntityData
A value kept on each entity, by uuid, at its key (the mod’s own: <mod>:<key>); its default where the entity has none yet.
GameData
A value kept for the install, whatever world (<game>/yog-data/<mod>/game.ydata): written as it changes.
ItemData
A value kept in the data of the stack a player holds, at its key (the mod’s own: <mod>:<key>); its default where the stack has none yet.
PlayerData
A value kept for each player of the world, by uuid (<world>/yog-data/<mod>/player/<uuid>.ydata, at its key); synced, to that player alone.
Store
A mod’s store of a scope: values of any Schema type by key, kept in memory and written when it’s flushed. Handles to one store share it.
WorldData
A value kept with the world (<world>/yog-data/<mod>/world.ydata, at its key): its default where there’s none yet; with no world open (a client of another’s server) it’s kept in memory only. Synced, to everyone.

Enums§

Scope
What a store belongs to — under a root: the game’s folder for Scope::Game, the world’s for the rest (see the crate docs).

Functions§

chunk
This mod’s store for chunk cx, cz of dimension dim in the open world.
close_under
Writes and closes every store under root (the world closed: the next one opened reads its own).
dimension
This mod’s store for dimension dim of the open world.
entity
This mod’s store for entity uuid in the open world.
flush_all
Writes every store changed since it was last written; the first failure.
game
This mod’s store for the install, whatever world.
player
This mod’s store for player uuid in the open world.
session
This mod’s session store: kept while the game runs, never written.
world
This mod’s store for the open world.