]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - doc/lua_api.txt
Merge pull request #243 from xyzz/liquid_renewable
[dragonfireclient.git] / doc / lua_api.txt
index ef7726e0f7e5e1d71580862d95be624f290a9a22..3018326189f3d9c9f07f37e60853cd974927c19c 100644 (file)
@@ -254,9 +254,9 @@ Nodes are passed by value between Lua and the engine.
 They are represented by a table:
   {name="name", param1=num, param2=num}
 
-param1 and param2 are 8 bit and 4 bit integers, respectively. The engine
-uses them for certain automated functions. If you don't use these
-functions, you can use them to store arbitrary values.
+param1 and param2 are 8 bit integers. The engine uses them for certain
+automated functions. If you don't use these functions, you can use them to
+store arbitrary values.
 
 The functions of param1 and param2 are determined by certain fields in the
 node definition:
@@ -423,7 +423,7 @@ effective towards.
 
 Groups in crafting recipes
 ---------------------------
-An example:
+An example: Make meat soup from any meat, any water and any bowl
 {
     output = 'food:meat_soup_raw',
     recipe = {
@@ -431,7 +431,13 @@ An example:
         {'group:water'},
         {'group:bowl'},
     },
-    preserve = {'group:bowl'}, -- Not implemented yet (TODO)
+    -- preserve = {'group:bowl'}, -- Not implemented yet (TODO)
+}
+An another example: Make red wool from white wool and red dye
+{
+       type = 'shapeless',
+    output = 'wool:red',
+    recipe = {'wool:white', 'group:dye,basecolor_red'},
 }
 
 Special groups
@@ -447,6 +453,10 @@ Special groups
   - 2: node is removed without tool wear after 0.5 seconds or so
        (rail, sign)
   - 3: node is removed without tool wear immediately (torch)
+- disable_jump: Player (and possibly other things) cannot jump from node
+- fall_damage_add_percent: damage speed = speed * (1 + value/100)
+- bouncy: value is bounce speed in percent
+- falling_node: if there is no walkable block under the node it will fall
 
 Known damage and digging time defining groups
 ----------------------------------------------
@@ -677,6 +687,7 @@ size[<W>,<H>]
 ^ deprecated: invsize[<W>,<H>;]
 
 list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]
+list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]
 ^ Show an inventory list
 
 image[<X>,<Y>;<W>,<H>;<texture name>]
@@ -726,10 +737,12 @@ image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
 ^ When clicked, fields will be sent and the form will quit.
 
 Inventory location:
+
 - "context": Selected node metadata (deprecated: "current_name")
 - "current_player": Player to whom the menu is shown
 - "player:<name>": Any player
 - "nodemeta:<X>,<Y>,<Z>": Any node metadata
+- "detached:<name>": A detached inventory
 
 Helper functions
 -----------------
@@ -774,11 +787,11 @@ minetest.register_craft(recipe)
 Global callback registration functions: (Call these only at load time)
 minetest.register_globalstep(func(dtime))
 ^ Called every server step, usually interval of 0.05s
-minetest.register_on_placenode(func(pos, newnode, placer))
+minetest.register_on_placenode(func(pos, newnode, placer, oldnode))
 ^ Called when a node has been placed
 ^ Deprecated: Use on_construct or after_place_node in node definition instead
 minetest.register_on_dignode(func(pos, oldnode, digger))
-^ Called when a node has been dug. digger can be nil.
+^ Called when a node has been dug.
 ^ Deprecated: Use on_destruct or after_dig_node in node definition instead
 minetest.register_on_punchnode(func(pos, node, puncher))
 ^ Called when a node is punched
@@ -847,6 +860,10 @@ Inventory:
 minetest.get_inventory(location) -> InvRef
 ^ location = eg. {type="player", name="celeron55"}
                  {type="node", pos={x=, y=, z=}}
+                 {type="detached", name="creative"}
+minetest.create_detached_inventory(name, callbacks) -> InvRef
+^ callbacks: See "Detached inventory callbacks"
+^ Creates a detached inventory. If it already exists, it is cleared.
 
 Item handling:
 minetest.inventorycube(img1, img2, img3)
@@ -875,6 +892,20 @@ minetest.get_craft_recipe(output) -> input
 ^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
                               stack 5, stack 6, stack 7, stack 8, stack 9 }
 ^ input.items = nil if no recipe found
+minetest.handle_node_drops(pos, drops, digger)
+^ drops: list of itemstrings
+^ Handles drops from nodes after digging: Default action is to put them into
+  digger's inventory
+^ Can be overridden to get different functionality (eg. dropping items on
+  ground)
+
+Rollbacks:
+minetest.rollback_get_last_node_actor(p, range, seconds) -> actor, p, seconds
+^ Find who has done something to a node, or near a node
+^ actor: "player:<name>", also "liquid".
+minetest.rollback_revert_actions_by(actor, seconds) -> bool, log messages
+^ Revert latest actions of someone
+^ actor: "player:<name>", also "liquid".
 
 Defaults for the on_* item definition functions:
 (These return the leftover itemstack)
@@ -907,6 +938,16 @@ minetest.after(time, func, param)
 ^ Call function after time seconds
 ^ param is optional; to pass multiple parameters, pass a table.
 
+Server:
+minetest.request_shutdown() -> request for server shutdown
+minetest.get_server_status() -> server status string
+
+Bans:
+minetest.get_ban_list() -> ban list (same as minetest.get_ban_description(""))
+minetest.get_ban_description(ip_or_name) -> ban description (string)
+minetest.ban_player(name) -> ban a player
+minetest.unban_player_or_ip(name) -> unban player or IP address
+
 Random:
 minetest.get_connected_players() -> list of ObjectRefs
 minetest.hash_node_position({x=,y=,z=}) -> 48-bit integer
@@ -996,6 +1037,8 @@ methods:
   ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
 - get_perlin(seeddiff, octaves, persistence, scale)
   ^ Return world-specific perlin noise (int(worldseed)+seeddiff)
+- clear_objects()
+  ^ clear all objects in the environments 
 Deprecated:
 - add_rat(pos): Add C++ rat object (no-op)
 - add_firefly(pos): Add C++ firefly object (no-op)
@@ -1045,6 +1088,7 @@ methods:
 - punch(puncher, time_from_last_punch, tool_capabilities, direction)
   ^ puncher = an another ObjectRef,
   ^ time_from_last_punch = time since last punch action of the puncher
+  ^ direction: can be nil
 - right_click(clicker); clicker = an another ObjectRef
 - get_hp(): returns number of hitpoints (2 * number of hearts)
 - set_hp(hp): set number of hitpoints (2 * number of hearts)
@@ -1085,6 +1129,8 @@ methods:
 - is_empty(listname): return true if list is empty
 - get_size(listname): get size of a list
 - set_size(listname, size): set size of a list
+- get_width(listname): get width of a list
+- set_width(listname, width): set width of list; currently used for crafting
 - get_stack(listname, i): get a copy of stack index i in list
 - set_stack(listname, i, stack): copy stack to index i in list
 - get_list(listname): return full list
@@ -1192,7 +1238,7 @@ Entity definition (register_entity)
     
     initial_properties = <initial object properties>,
 
-    on_activate = function(self, staticdata),
+    on_activate = function(self, staticdata, dtime_s),
     on_step = function(self, dtime),
     on_punch = function(self, hitter),
     on_rightclick = function(self, clicker),
@@ -1280,30 +1326,31 @@ Node definition (register_node)
     drawtype = "normal", -- See "Node drawtypes"
     visual_scale = 1.0,
     tiles = {tile definition 1, def2, def3, def4, def5, def6},
+       ^ Textures of node; +Y, -Y, +X, -X, +Z, -Z (old field name: tile_images)
     ^ List can be shortened to needed length
-    ^ Old field name: tile_images
     special_tiles = {tile definition 1, Tile definition 2},
+       ^ Special textures of node; used rarely (old field name: special_materials)
     ^ List can be shortened to needed length
-    ^ Old field name: special_materials
     alpha = 255,
-    post_effect_color = {a=0, r=0, g=0, b=0},
-    paramtype = "none",
-    paramtype2 = "none",
-    is_ground_content = false,
-    sunlight_propagates = false,
-    walkable = true,
-    pointable = true,
-    diggable = true,
-    climbable = false,
-    buildable_to = false,
-    drop = "",
-    -- alternatively drop = { max_items = ..., items = { ... } }
-    liquidtype = "none",
-    liquid_alternative_flowing = "",
-    liquid_alternative_source = "",
-    liquid_viscosity = 0,
-    light_source = 0,
-    damage_per_second = 0,
+    post_effect_color = {a=0, r=0, g=0, b=0}, -- If player is inside node
+    paramtype = "none", -- See "Nodes"
+    paramtype2 = "none", -- See "Nodes"
+    is_ground_content = false, -- Currently not used for anything
+    sunlight_propagates = false, -- If true, sunlight will go infinitely through this
+    walkable = true, -- If true, objects collide with node
+    pointable = true, -- If true, can be pointed at
+    diggable = true, -- If false, can never be dug
+    climbable = false, -- If true, can be climbed on (ladder)
+    buildable_to = false, -- If true, placed nodes can replace this node
+    drop = "", -- alternatively drop = { max_items = ..., items = { ... } }
+    liquidtype = "none", -- "none"/"source"/"flowing"
+    liquid_alternative_flowing = "", -- Flowing version of source liquid
+    liquid_alternative_source = "", -- Source version of flowing liquid
+    liquid_viscosity = 0, -- Higher viscosity = slower flow (max. 7)
+    liquid_renewable = true, -- Can new liquid source be created by placing
+    two or more sources nearly?
+    light_source = 0, -- Amount of light emitted by node
+    damage_per_second = 0, -- If player is inside node, this damage is caused
     node_box = {type="regular"}, -- See "Node boxes"
     selection_box = {type="regular"}, -- See "Node boxes"
     legacy_facedir_simple = false, -- Support maps made in and before January 2012
@@ -1356,35 +1403,32 @@ Node definition (register_node)
     ^ Called when an UI form (eg. sign text input) returns data
     ^ default: nil
 
-    on_metadata_inventory_move = func(pos, from_list, from_index,
-                                      to_list, to_index, count, player),
-    ^ Called when a player wants to move items inside the metadata
-    ^ Should move items, or some items, if permitted. If not, should do
-      nothing.
-    ^ The engine ensures the action is valid, i.e. the stack fits at the
-      given position
-    ^ default: minetest.node_metadata_inventory_move_allow_all
-
-    on_metadata_inventory_offer = func(pos, listname, index, stack, player),
-    ^ Called when a player wants to put something into the metadata
-      inventory
-    ^ Should check if the action is permitted (the engine ensures the
-      action is valid, i.e. the stack fits at the given position)
-      ^ If permitted, modify the metadata inventory and return the
-        "leftover" stack (normally nil).
-      ^ If not permitted, return itemstack.
-    ^ default: minetest.node_metadata_inventory_offer_allow_all
-
-    on_metadata_inventory_take = func(pos, listname, index, count, player),
-    ^ Called when a player wants to take something out of the metadata
-      inventory
-    ^ Should check if the action is permitted (the engine ensures the
-      action is valid, i.e. there's a stack of at least “count” items at
-      that position)
-      ^ If permitted, modify the metadata inventory and return the
-        stack of items
-      ^ If not permitted, return nil.
-    ^ default: minetest.node_metadata_inventory_take_allow_all
+       allow_metadata_inventory_move = func(pos, from_list, from_index,
+                       to_list, to_index, count, player),
+       ^ Called when a player wants to move items inside the inventory
+       ^ Return value: number of items allowed to move
+       
+       allow_metadata_inventory_put = func(pos, listname, index, stack, player),
+       ^ Called when a player wants to put something into the inventory
+       ^ Return value: number of items allowed to put
+       ^ Return value: -1: Allow and don't modify item count in inventory
+  
+       allow_metadata_inventory_take = func(pos, listname, index, stack, player),
+       ^ Called when a player wants to take something out of the inventory
+       ^ Return value: number of items allowed to take
+       ^ Return value: -1: Allow and don't modify item count in inventory
+
+       on_metadata_inventory_move = func(pos, from_list, from_index,
+                       to_list, to_index, count, player),
+       on_metadata_inventory_put = func(pos, listname, index, stack, player),
+       on_metadata_inventory_take = func(pos, listname, index, stack, player),
+       ^ Called after the actual action has happened, according to what was allowed.
+       ^ No return value
+    
+       on_blast = func(pos, intensity),
+       ^ intensity: 1.0 = mid range of regular TNT
+       ^ If defined, called when an explosion touches the node, instead of
+         removing the node
 }
 
 Recipe for register_craft: (shaped)
@@ -1441,3 +1485,26 @@ Chatcommand definition (register_chatcommand)
     func = function(name, param), -- called when command is run
 }
 
+Detached inventory callbacks
+{
+       allow_move = func(inv, from_list, from_index, to_list, to_index, count, player),
+    ^ Called when a player wants to move items inside the inventory
+       ^ Return value: number of items allowed to move
+       
+    allow_put = func(inv, listname, index, stack, player),
+    ^ Called when a player wants to put something into the inventory
+       ^ Return value: number of items allowed to put
+       ^ Return value: -1: Allow and don't modify item count in inventory
+   
+    allow_take = func(inv, listname, index, stack, player),
+    ^ Called when a player wants to take something out of the inventory
+       ^ Return value: number of items allowed to take
+       ^ Return value: -1: Allow and don't modify item count in inventory
+       
+       on_move = func(inv, from_list, from_index, to_list, to_index, count, player),
+    on_put = func(inv, listname, index, stack, player),
+    on_take = func(inv, listname, index, stack, player),
+       ^ Called after the actual action has happened, according to what was allowed.
+       ^ No return value
+}
+