πΎ Data and NBT API¶
Want data that is still there after a restart? Use the key-value database; keys and values are strings. Event payloads, items and entity snapshots are SNBT text, and every language has a parser with the same rules.
The key-value database¶
Opening a database¶
Rust: KvDb::open(path)
Go: levilamina.OpenKvDb(path, create)
Zig: levilamina.slot("kvdb_open")
- Parameters:
- path : string
the database's name, under your mod's data directory - create : boolean
(Go, Zig) whether to create it when missing. Rust'sopencreates,open_existingdoes not
- path : string
- Return value: the database
- Return type: Rust
Result<KvDb>, Go(*KvDb, error) - Slot:
kvdb_open -
Example:
- Rust
Rust - Go
- Zig
Reading a key¶
Rust: db.get(key)
Go: db.Get(key)
Zig: levilamina.slot("kvdb_get")
- Parameters:
- key : string
the key
- key : string
- Return value: the key's value; a missing key reads as absent, which is not an error
- Return type: Rust
Option<String>, Go(string, bool, error) - Slot:
kvdb_get -
Example:
- Rust
- Go
Go
Writing a key¶
Rust: db.set(key, value)
Go: db.Set(key, value)
Zig: levilamina.slot("kvdb_set")
- Parameters:
- key : string
the key - value : string
the value; serialize structured data to JSON or SNBT first
- key : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool - Slot:
kvdb_set -
Example:
- Rust
Rust - Go
Go - Zig
Deleting a key¶
Rust: db.del(key)
Go: db.Delete(key)
Zig: levilamina.slot("kvdb_del")
- Parameters:
- key : string
the key
- key : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror - Slot:
kvdb_del -
Example:
- Rust
Rust - Go
Go
Every entry¶
Rust: db.iter()
Go: db.Iter()
Zig: levilamina.slot("kvdb_iter")
- Return value: every key and value
- Return type: Rust
Vec<(String, String)>, Go([]KeyValue, error) - Slot:
kvdb_iter -
Example:
- Rust
- Go
Go
SNBT¶
Parsing SNBT¶
Rust: NbtValue::parse(text)
Go: levilamina.ParseSNBT(text)
Zig: levilamina.nbt.parse(arena, text)
- Parameters:
- text : string
the SNBT text
- text : string
- Return value: the parsed value; read fields by dotted path: Rust
opt_str,opt_i32, GoOptString,OptInt, ZiggetString,getInt - Return type: Rust
Result<NbtValue, ParseError>, Go(*Nbt, error), Zignbt.ParseError!nbt.Value- An integer without a suffix is an int, a long when too big, a double with a decimal point; a suffix
b,s,L,fordfixes the type;trueandfalseare bytes. A missing field or one of another type reads as absent. Nesting stops at 512 levels with an error.
- An integer without a suffix is an int, a long when too big, a double with a decimal point; a suffix
-
Example:
- Rust
- Go
- Zig