Metadata

Node Metadata

The instance of a node in the world normally only contains the three values mentioned in [Nodes]. However, it is possible to insert extra data into a node. It is called "node metadata"; See NodeMetaRef.

Node metadata contains two things:

  • A key-value store
  • An inventory

Some of the values in the key-value store are handled specially:

  • formspec: Defines a right-click inventory menu. See [Formspec].
  • infotext: Text shown on the screen when the node is pointed at

Example:

local meta = minetest.get_meta(pos)
meta:set_string("formspec",
        "size[8,9]"..
        "list[context;main;0,0;8,4;]"..
        "list[current_player;main;0,5;8,4;]")
meta:set_string("infotext", "Chest");
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
print(dump(meta:to_table()))
meta:from_table({
    inventory = {
        main = {[1] = "default:dirt", [2] = "", [3] = "", [4] = "",
                [5] = "", [6] = "", [7] = "", [8] = "", [9] = "",
                [10] = "", [11] = "", [12] = "", [13] = "",
                [14] = "default:cobble", [15] = "", [16] = "", [17] = "",
                [18] = "", [19] = "", [20] = "default:cobble", [21] = "",
                [22] = "", [23] = "", [24] = "", [25] = "", [26] = "",
                [27] = "", [28] = "", [29] = "", [30] = "", [31] = "",
                [32] = ""}
    },
    fields = {
        formspec = "size[8,9]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]",
        infotext = "Chest"
    }
})

Item Metadata

Item stacks can store metadata too. See [ItemStackMetaRef].

Item metadata only contains a key-value store.

Some of the values in the key-value store are handled specially:

  • description: Set the item stack's description. Defaults to idef.description.
  • color: A ColorString, which sets the stack's color.
  • palette_index: If the item has a palette, this is used to get the current color from the palette.

Example:

local meta = stack:get_meta()
meta:set_string("key", "value")
print(dump(meta:to_table()))