diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-04-14 11:24:18 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-04-14 11:24:18 +0300 |
commit | 9c5cc217bfe5a65d412b4b1d193689bc07d61b44 (patch) | |
tree | 091984fdc2d4b4d99b1d6dda0746cd85e4ff956f /doc | |
parent | 24603d7ad3421284246116656abb533098a24631 (diff) | |
download | minetest-9c5cc217bfe5a65d412b4b1d193689bc07d61b44.tar.gz minetest-9c5cc217bfe5a65d412b4b1d193689bc07d61b44.tar.bz2 minetest-9c5cc217bfe5a65d412b4b1d193689bc07d61b44.zip |
Add "Registered definitions of stuff" to doc/lua_api.txt
Diffstat (limited to 'doc')
-rw-r--r-- | doc/lua_api.txt | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 9bb0dfe98..d63fc9df7 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -192,6 +192,48 @@ eg. {} eg. {name="default_place_node"} eg. {name="default_place_node", gain=1.0} +Registered definitions of stuff +-------------------------------- +Anything added using certain minetest.register_* functions get added to +the global minetest.registered_* tables. + +minetest.register_entity(name, prototype table) + -> minetest.registered_entities[name] + +minetest.register_node(name, node definition) + -> minetest.registered_items[name] + -> minetest.registered_nodes[name] + +minetest.register_tool(name, item definition) + -> minetest.registered_items[name] + +minetest.register_craftitem(name, item definition) + -> minetest.registered_items[name] + +Note that in some cases you will stumble upon things that are not contained +in these tables (eg. when a mod has been removed). Always check for +existence before trying to access the fields. + +Example: If you want to check the drawtype of a node, you could do: + +local function get_nodedef_field(nodename, fieldname) + if not minetest.registered_nodes[nodename] then + return nil + end + return minetest.registered_nodes[nodename][fieldname] +end +local drawtype = get_nodedef_field(nodename, "drawtype") + +Example: minetest.get_item_group(name, group) has been implemented as: + +function minetest.get_item_group(name, group) + if not minetest.registered_items[name] or not + minetest.registered_items[name].groups[group] then + return 0 + end + return minetest.registered_items[name].groups[group] +end + Nodes ------ Nodes are the bulk data of the world: cubes and other things that take the @@ -200,9 +242,7 @@ are quite static. The definition of a node is stored and can be accessed by name in minetest.registered_nodes[node.name] - -Please note that for unknown nodes (eg. a node of an uninstalled mod) the -minetest.registered_nodes field for the node is nil. +See "Registered definitions of stuff". Nodes are passed by value between Lua and the engine. They are represented by a table: |