From 3899f83da879e11cf531c88514772b890d060721 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 2 Jun 2012 11:01:28 +0300 Subject: NodeMetaRef:{to,from}_table and lua_api.txt additions --- doc/lua_api.txt | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'doc/lua_api.txt') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index f8615b130..70ba82dc7 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -278,6 +278,8 @@ param2 is reserved for the engine when any of these are used: ^ The rotation of the node is stored in param2. Furnaces and chests are rotated this way. Can be made by using minetest.dir_to_facedir(). +Nodes can also contain extra data. See "Node Metadata". + Representations of simple things -------------------------------- Position/vector: @@ -548,6 +550,91 @@ time_from_last_punch, tool_capabilities, direction)''. * If ''direction'' is nil and ''puncher'' is not nil, ''direction'' will be automatically filled in based on the location of ''puncher''. +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". + +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 stuff: + +local meta = minetest.env:get_meta(pos) +meta:set_string("formspec", + "invsize[8,9;]".. + "list[current_name;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 = "invsize[8,9;]list[current_name;main;0,0;8,4;]list[current_player;main;0,5;8,4;]", + infotext = "Chest" + } +}) + +Formspec +-------- +Formspec defines a menu. Currently not much else than inventories are +supported. It is a string, with a somewhat strange format. + +Spaces and newlines can be inserted between the blocks, as is used in the +examples. + +Examples: +- Chest: + invsize[8,9;] + list[current_name;main;0,0;8,4;] + list[current_player;main;0,5;8,4;] +- Furnace: + invsize[8,9;] + list[current_name;fuel;2,3;1,1;] + list[current_name;src;2,1;1,1;] + list[current_name;dst;5,1;2,2;] + list[current_player;main;0,5;8,4;] + +Elements: + +invsize[,;] +^ Define the size of the menu in inventory slots + +list[;;,;,;] +^ Show an inventory list + +image[,;,;] +^ Show an image +^ Position and size units are inventory slots +^ Not implemented + +field[,;,;;