Skip to content

server.world.upgrader

Constants #

const state_kind_byte = world.state_kind_byte
const state_kind_string = world.state_kind_string
const state_kind_int = world.state_kind_int
const current_version = 18163713

current_version is the block state version Vedrock treats as up to date. Anything stored below this gets walked through the schemas. The value is the packed Bedrock version used across the codebase (matches the palette dumps).

fn byte_value #

fn byte_value(v u8) StateValue

fn default_upgrader #

fn default_upgrader() Upgrader

default_upgrader returns the upgrader seeded with a small but representative set of real Bedrock upgrade steps. This is a starting set - the full worldupgrader schema data is large, so only a handful of well-known transforms live here. Extend by adding more Schema entries with higher ids.

fn from_world #

fn from_world(name string, states []world.BlockState, version int) BlockState

from_world turns the decoded name + sorted state list into a BlockState.

fn int_value #

fn int_value(v int) StateValue

fn new_upgrader #

fn new_upgrader(schemas []Schema) Upgrader

fn string_value #

fn string_value(v string) StateValue

struct BlockState #

struct BlockState {
pub mut:
	name       string
	properties map[string]StateValue
	version    int
}

BlockState is the upgrader-facing model. It mirrors df-mc worldupgrader's BlockState{Name, Properties, Version}. Properties are keyed by name so schema transforms stay simple - order is irrelevant here since the final hash re-sorts states anyway.

fn (BlockState) to_world #

fn (b BlockState) to_world() []world.BlockState

to_world flattens the BlockState back into a world.BlockState list ready for hashing. Keys are emitted sorted so the output is deterministic.

struct Schema #

struct Schema {
pub:
	id                 int
	renamed_ids        map[string]string
	added_properties   map[string]map[string]StateValue
	removed_properties map[string][]string
	renamed_properties map[string]map[string]string
	remapped_values    map[string]map[string][]ValueRemap
	remapped_states    map[string][]StateRemap
}

Schema is one ordered upgrade step. Each map is keyed by block name. Only the transforms that a given step needs are filled in - the rest stay empty and are skipped. This matches worldupgrader's schema shape.

struct StateRemap #

struct StateRemap {
pub:
	old_properties    map[string]StateValue
	new_name          string
	new_properties    map[string]StateValue
	copied_properties []string
}

StateRemap replaces a whole block state when the old properties match. It mirrors df-mc's schemaBlockRemap - if old_properties is a subset of the current state, the block is rewritten with new_name and new_properties, keeping any copied_properties from the old state.

struct StateValue #

struct StateValue {
pub:
	kind       int
	byte_value u8
	string_val string
	int_value  int
}

StateValue is a single block property value. It keeps the kind so we can round-trip it back into the world.BlockState list without losing type info.

fn (StateValue) == #

fn (v StateValue) == (other StateValue) bool

struct Upgrader #

struct Upgrader {
mut:
	schemas []Schema
}

Upgrader holds the ordered schema list and applies them to old block states. It is the single public entry point - construct once with default_upgrader() and call upgrade() per palette entry.

fn (Upgrader) upgrade #

fn (u Upgrader) upgrade(state BlockState) BlockState

upgrade walks the schemas in id order, skipping any whose id the state has already passed. The block name and properties are rewritten in place and the version is bumped to current_version at the end. Already-current states are a pass-through no-op.

struct ValueRemap #

struct ValueRemap {
pub:
	old StateValue
	new StateValue
}