DATACRAFT V2

NBT

Open compiler

NBT compounds

The nbt type stores JSON-style compound data in the namespace's Minecraft command storage. It may contain integers, booleans, strings, lists, and nested NBT compounds. Minecraft NBT has no null value, so None and entities cannot be embedded in a compound.

Literals

profile: nbt = {"name": "Alex", "health": 20, "active": True, "position": [10, 64, -4], "settings": {"particles": False}}
empty: nbt = {}

NBT arrays may contain different NBT-compatible value kinds. Keys must be string literals.

Bracket access

profile["health"] = 18
health: int = profile["health"]
settings: nbt = profile["settings"]
particles: bool = profile["settings"]["particles"]

NBT does not support property syntax: use profile["health"], never profile.health. Field reads need an expected type, normally supplied by a typed variable declaration.

Functions

def update(profile: nbt) -> nbt:
    profile["active"] = True
    return profile

Whole NBT variables can be passed to and returned from functions. Structured return data uses runtime storage because Minecraft /return itself only carries an integer result.

Output and length

say(profile) displays the compound, while say(profile["name"]) displays a selected field. len(profile) returns the number of keys in the compound.