NodeMetaRef

From Minetest Developer Wiki
Revision as of 22:02, 1 December 2012 by Xyz (talk | contribs) (Created page with "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 call...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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".

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

Can be gotten via minetest.env:get_meta(pos).

Methods

  • set_string(name, value)
  • get_string(name)
  • set_int(name, value)
  • get_int(name)
  • set_float(name, value)
  • get_float(name)
  • [NodeMetaRef]get_inventory() — returns InvRef
  • [NodeMetaRef]to_table() — returns nil or {fields = {...}, inventory = {list1 = {}, ...}}
  • from_table(nil or {})

Example

local meta = minetest.env:get_meta(pos) meta:set_string("formspec", "invsize[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:[NodeMetaRef]get_inventory() inv:set_size("main", 8*4) print(dump(meta:[NodeMetaRef]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 = "invsize[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]", infotext = "Chest" } })