Skip to content

server.world.db

fn create_world_store #

fn create_world_store(worlds_dir string, name string, dim world.Dimension, generator string) !&WorldStore

create_world_store creates a fresh, empty world on disk under worlds_dir and returns its opened store. Errors if a world by that name already exists.

fn delete_world_files #

fn delete_world_files(worlds_dir string, name string) !

delete_world_files removes the on-disk folder for the named world. The caller is responsible for closing the LevelDB handle first - this only touches the filesystem. Refuses to delete anything outside worlds_dir or a world that isn't actually there.

fn discover_worlds #

fn discover_worlds(worlds_dir string) []string

discover_worlds returns the names of every subdirectory under worlds_dir that looks like a world (has a db folder).

fn load_named #

fn load_named(worlds_dir string, name string, generator_name string, dim world.Dimension) !&World

load_named opens the world stored under worlds_dir/name and pulls its overrides into memory.

fn new_stored_generator #

fn new_stored_generator(store &WorldStore, fallback world.Generator) StoredGenerator

fn new_world #

fn new_world(name string, store &WorldStore, generator_name string, dim world.Dimension) &World

fn open_leveldb #

fn open_leveldb(path string) !&LevelDB

fn open_world #

fn open_world(path string, dim world.Dimension) !&WorldStore

fn world_exists #

fn world_exists(worlds_dir string, name string) bool

world_exists reports whether a world folder with a db subdirectory is present under worlds_dir.

struct BlockOverride #

struct BlockOverride {
pub:
	x  int
	y  int
	z  int
	id int
}

struct LevelDB #

@[heap]
struct LevelDB {
mut:
	db &leveldb.DB
}

fn (LevelDB) put #

fn (l &LevelDB) put(key []u8, value []u8)

fn (LevelDB) get #

fn (l &LevelDB) get(key []u8) ?[]u8

fn (LevelDB) delete #

fn (l &LevelDB) delete(key []u8)

fn (LevelDB) each #

fn (l &LevelDB) each(cb fn (key []u8, value []u8))

fn (LevelDB) flush #

fn (l &LevelDB) flush()

flush forces pending writes down to disk without releasing the handle, so a crash after a flush cannot lose the flushed data. close() already syncs, so this is only needed for periodic mid-run durability.

fn (LevelDB) close #

fn (l &LevelDB) close()

struct StoredGenerator #

struct StoredGenerator {
	store    &WorldStore
	fallback world.Generator
	cache    &ChunkCache
}

fn (StoredGenerator) spawn_y #

fn (g StoredGenerator) spawn_y() int

fn (StoredGenerator) uses_blocks #

fn (g StoredGenerator) uses_blocks() bool

fn (StoredGenerator) generate #

fn (g StoredGenerator) generate(chunk_x int, chunk_z int) world.Chunk

fn (StoredGenerator) block_at #

fn (g StoredGenerator) block_at(x int, y int, z int) int

fn (StoredGenerator) biome_at #

fn (g StoredGenerator) biome_at(x int, z int) int

struct World #

@[heap]
struct World {
pub:
	name      string
	dimension world.Dimension = world.overworld
mut:
	store        &WorldStore = unsafe { nil }
	overrides    map[string]int
	mutex        &sync.Mutex = sync.new_mutex()
	current_tick i64
	scheduled    []ScheduledEntry
pub mut:
	generator_name string
}

World is a single loaded world - its persistent store plus the in-memory cache of block overrides layered on top of the generated/vanilla chunks.

fn (World) block_count #

fn (w &World) block_count() int

fn (World) block_id #

fn (w &World) block_id(x int, y int, z int) int

block_id returns the block at the given position. It first checks for an in memory override, then falls back to the world's configured generator.

This matches the override first lookup used by session.block_at().

fn (World) block_override #

fn (w &World) block_override(x int, y int, z int) ?int

fn (World) close #

fn (mut w World) close()

fn (World) flush #

fn (mut w World) flush()

flush persists this world's store to disk without unloading it. Safe to call while the world is live - it does not touch the in-memory override cache.

fn (World) load #

fn (mut w World) load()

load pulls every persisted block override into the in-memory cache.

fn (World) make_generator #

fn (w &World) make_generator(fallback world.Generator) world.Generator

make_generator wraps the given fallback with a StoredGenerator when this world has a backing store, so saved chunks are served before the fallback.

fn (World) overrides_in_chunk #

fn (w &World) overrides_in_chunk(cx int, cz int) []BlockOverride

fn (World) schedule_tick #

fn (mut w World) schedule_tick(x int, y int, z int, delay int)

schedule_tick queues one scheduled tick for the given position. ScheduledTicker.scheduled_tick callback runs after delay game ticks.

fn (World) set_block #

fn (mut w World) set_block(x int, y int, z int, runtime_id int)

fn (World) tick #

fn (mut w World) tick(registry &block.Registry) []BlockOverride

tick advances this world by one game tick: fires every scheduled entry whose delay has elapsed, then rolls the random tick chance (see block.random_tick_speed) for every currently overridden block position. Only overridden positions are considered.

Returns the positions changed by either pass. World has no session/network knowledge, so broadcasting these to connected players is the caller's responsibility.

struct WorldStore #

@[heap]
struct WorldStore {
	db        &LevelDB
	overrides &LevelDB
	dimension world.Dimension = world.overworld
}

fn (WorldStore) close #

fn (w &WorldStore) close()

fn (WorldStore) each_block #

fn (w &WorldStore) each_block(cb fn (x int, y int, z int, runtime_id int))

fn (WorldStore) flush #

fn (w &WorldStore) flush()

flush persists both backing databases without closing them.

fn (WorldStore) load_chunk #

fn (w &WorldStore) load_chunk(cx int, cz int) ?world.Chunk

fn (WorldStore) set_block #

fn (w &WorldStore) set_block(x int, y int, z int, runtime_id int)