sethome: Do not write empty homes file
[oweals/minetest_game.git] / game_api.txt
index bc5a8c7a5a189e062daf9ce8786a7c9e7fc15c26..3f311336a351343cc59f3de763b94977e7dfcadb 100644 (file)
@@ -2,10 +2,11 @@ Minetest Game API
 =================
 GitHub Repo: https://github.com/minetest/minetest_game
 
+
 Introduction
 ------------
 
-The Minetest Game subgame offers multiple new possibilities in addition to the Minetest engine's built-in API,
+The Minetest Game game offers multiple new possibilities in addition to the Minetest engine's built-in API,
 allowing you to add new plants to farming mod, buckets for new liquids, new stairs and custom panes.
 For information on the Minetest API, visit https://github.com/minetest/minetest/blob/master/doc/lua_api.txt
 Please note:
@@ -14,6 +15,7 @@ Please note:
  * [#ABC] refers to a section in this document
  * [pos] refers to a position table `{x = -5, y = 0, z = 200}`
 
+
 Bucket API
 ----------
 
@@ -34,6 +36,7 @@ The bucket API allows registering new types of buckets for non-default liquids.
 The filled bucket item is returned to the player that uses an empty bucket pointing to the given liquid source.
 When punching with an empty bucket pointing to an entity or a non-liquid node, the on_punch of the entity or node will be triggered.
 
+
 Beds API
 --------
 
@@ -42,6 +45,7 @@ Beds API
                def            -- See [#Bed definition]
        )
 
+ * `beds.can_dig(bed_pos)` Returns a boolean whether the bed at `bed_pos` may be dug
  * `beds.read_spawns() `   Returns a table containing players respawn positions
  * `beds.kick_players()`  Forces all players to leave bed
  * `beds.skip_night()`   Sets world time to morning and saves respawn position of all players currently sleeping
@@ -67,6 +71,17 @@ Beds API
                }
        }
 
+
+Bones API
+---------
+
+An ordered list of listnames (default: "main", "craft") of the player inventory,
+that will be placed into bones or dropped on player death can be looked up or changed
+in `bones.player_inventory_lists`.
+
+e.g. `table.insert(bones.player_inventory_lists, "backpack")`
+
+
 Creative API
 ------------
 
@@ -78,16 +93,22 @@ For example,
 is used to show all tools. Name is used in the sfinv page name, title is the
 human readable title.
 
-`is_enabled_for` is used to check whether a player is in creative mode:
-
-    creative.is_enabled_for(name)
-
-Override this to allow per-player game modes.
+Creative provides `creative.is_enabled_for(name)`, which is identical in
+functionality to the engine's `minetest.creative_is_enabled(name)`.
+Its use is deprecated and it should also not be overriden.
 
 The contents of `creative.formspec_add` is appended to every creative inventory
 page. Mods can use it to add additional formspec elements onto the default
 creative inventory formspec to be drawn after each update.
 
+Group overrides can be used for any registered item, node or tool. Use one of
+the groups stated below to pick which category it will appear in.
+
+       node = 1      -- Appears in the Nodes category
+       tool = 1      -- Appears in the Tools category
+       craftitem = 1 -- Appears in the Items category
+
+
 Chests API
 ----------
 
@@ -113,12 +134,12 @@ The chests API allows the creation of chests, which have their own inventories f
  * A table indexed by player name to keep track of who opened what chest.
  * Key: The name of the player.
  * Value: A table containing information about the chest the player is looking at.
-   e.g `{ pos = {1, 1, 1}, sound = null, swap = "chest" }`
+   e.g `{ pos = {1, 1, 1}, sound = null, swap = "default:chest" }`
 
 `default.chest.register_chest(name, def)`
 
  * Registers new chest
- * `name` Name for chest
+ * `name` Name for chest e.g. "default:chest"
  * `def`  See [#Chest Definition]
 
 ### Chest Definition
@@ -138,11 +159,18 @@ The chests API allows the creation of chests, which have their own inventories f
        groups = {choppy = 2, oddly_breakable_by_hand = 2},
        protected = false, -- If true, only placer can modify chest.
 
+
 Doors API
 ---------
 
 The doors mod allows modders to register custom doors and trapdoors.
 
+`doors.registered_doors[name] = Door definition` 
+ * Table of registered doors, indexed by door name 
+
+`doors.registered_trapdoors[name] = Trapdoor definition` 
+ * Table of registered trap doors, indexed by trap door name 
+
 `doors.register_door(name, def)`
 
  * Registers new door
@@ -178,17 +206,28 @@ The doors mod allows modders to register custom doors and trapdoors.
     has the permissions needed to open this door. If omitted then no
     permission checks are performed.
 
+`doors.door_toggle(pos, node, clicker)`
+
+ * Toggle door open or shut
+ * `pos` Position of the door
+ * `node` Node definition
+ * `clicker` Player definition for the player that clicked on the door
 ### Door definition
 
        description = "Door description",
        inventory_image = "mod_door_inv.png",
        groups = {choppy = 2},
        tiles = {"mod_door.png"}, -- UV map.
+       -- The front and back of the door must be identical in appearence as they swap on
+       -- open/close.
        recipe = craftrecipe,
        sounds = default.node_sound_wood_defaults(), -- optional
        sound_open = sound play for open door, -- optional
        sound_close = sound play for close door, -- optional
        protected = false, -- If true, only placer can open the door (locked for others)
+       on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) 
+       -- optional function containing the on_rightclick callback, defaults to a doors.door_toggle-wrapper
 
 ### Trapdoor definition
 
@@ -196,11 +235,20 @@ The doors mod allows modders to register custom doors and trapdoors.
        inventory_image = "mod_trapdoor_inv.png",
        groups = {choppy = 2},
        tile_front = "doors_trapdoor.png", -- the texture for the front and back of the trapdoor
-       tile_side = "doors_trapdoor_side.png", -- the tiles of the four side parts of the trapdoor
+       tile_side = "doors_trapdoor_side.png",
+       -- The texture for the four sides of the trapdoor.
+       -- The texture should have the trapdoor side drawn twice, in the lowest and highest
+       -- 1/8ths of the texture, both upright. The area between is not used.
+       -- The lower 1/8th will be used for the closed trapdoor, the higher 1/8th will be used
+       -- for the open trapdoor.
        sounds = default.node_sound_wood_defaults(), -- optional
        sound_open = sound play for open door, -- optional
        sound_close = sound play for close door, -- optional
        protected = false, -- If true, only placer can open the door (locked for others)
+       on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) 
+       -- function containing the on_rightclick callback
+       on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) 
+       -- function containing the on_rightclick callback
 
 ### Fence gate definition
 
@@ -210,6 +258,9 @@ The doors mod allows modders to register custom doors and trapdoors.
        material = "default:wood",
        groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
        sounds = default.node_sound_wood_defaults(), -- optional
+       on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) 
+       -- function containing the on_rightclick callback
+
 
 Dungeon Loot API
 ----------------
@@ -230,7 +281,7 @@ The mod that places chests with loot in dungeons provides an API to register add
        name = "item:name",
        chance = 0.5,
        -- ^ chance value from 0.0 to 1.0 that the item will appear in the chest when chosen
-       --   due to an extra step in the selection process, 0.5 does not(!) mean that
+       --   Due to an extra step in the selection process, 0.5 does not(!) mean that
        --   on average every second chest will have this item
        count = {1, 4},
        -- ^ table with minimum and maximum amounts of this item
@@ -240,9 +291,11 @@ The mod that places chests with loot in dungeons provides an API to register add
        --   optional, defaults to no height restrictions
        types = {"desert"},
        -- ^ table with types of dungeons this item can be found in
-       --   supported types: "normal" (the cobble/mossycobble one), "sandstone", "desert"
+       --   supported types: "normal" (the cobble/mossycobble one), "sandstone"
+       --   "desert" and "ice"
        --   optional, defaults to no type restrictions
 
+
 Fence API
 ---------
 
@@ -264,6 +317,7 @@ Allows creation of new fences with "fencelike" drawtype.
        groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
        sounds = default.node_sound_wood_defaults(),
 
+
 Walls API
 ---------
 
@@ -276,6 +330,7 @@ walls.register(name, desc, texture, mat, sounds)
 ^ mat = "default:stone". Used to auto-generate crafting recipe.
 ^ sounds = sounds: see [#Default sounds]
 
+
 Farming API
 -----------
 
@@ -309,6 +364,8 @@ The farming API allows you to easily register plants and hoes.
 
        {
                description = "",                      -- Description of seed item
+               harvest_description = "",              -- Description of harvest item
+                                                      -- (optional, derived automatically if not provided)
                inventory_image = "unknown_item.png",  -- Image to be used as seed's wield- and inventory image
                steps = 8,                             -- How many steps the plant has to grow, until it can be harvested
                -- ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
@@ -316,9 +373,12 @@ The farming API allows you to easily register plants and hoes.
                maxlight = default.LIGHT_MAX           -- Maximum light to grow
        }
 
+
 Fire API
 --------
 
+Add group flammable when registering a node to make fire seek for it.
+Add it to an item to make it burn up when dropped in lava or fire.
 New node def property:
 
 `on_burn(pos)`
@@ -369,7 +429,7 @@ Give Initial Stuff API
 Players API
 -----------
 
-The player API can register player models and update the player's appearence
+The player API can register player models and update the player's appearance.
 
 * `player_api.register_model(name, def)`
        * Register a new model to be used by players
@@ -402,6 +462,12 @@ The player API can register player models and update the player's appearence
        * Any of the fields of the returned table may be nil.
        * player: PlayerRef
 
+* `player_api.player_attached`
+       * A table that maps a player name to a boolean.
+       * If the value for a given player is set to true, the default player
+       animations (walking, digging, ...) will no longer be updated.
+       Knockback from damage is also prevented for that player.
+
 ### Model Definition
 
        {
@@ -412,7 +478,7 @@ The player API can register player models and update the player's appearence
                        -- <anim_name> = {x = <start_frame>, y = <end_frame>},
                        foo = {x = 0, y = 19},
                        bar = {x = 20, y = 39},
-               -- ...
+                       -- ...
                },
                collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, -- In nodes from feet position
                stepheight = 0.6, -- In nodes
@@ -539,11 +605,15 @@ set a players home position and teleport a player to home position.
 Sfinv API
 ---------
 
+It is recommended that you read this link for a good introduction to the
+sfinv API by its author: https://rubenwardy.com/minetest_modding_book/en/chapters/sfinv.html
+
 ### sfinv Methods
 
 **Pages**
 
 * sfinv.set_page(player, pagename) - changes the page
+* sfinv.get_page(player) - get the current page name. Will never return nil
 * sfinv.get_homepage_name(player) - get the page name of the first page to show to a player
 * sfinv.register_page(name, def) - register a page, see section below
 * sfinv.override_page(name, def) - overrides fields of an page registered with register_page.
@@ -640,39 +710,67 @@ And override this function to change the layout:
                return table.concat(tmp, "")
        end
 
+
 Stairs API
 ----------
 
 The stairs API lets you register stairs and slabs and ensures that they are registered the same way as those
 delivered with Minetest Game, to keep them compatible with other mods.
 
-`stairs.register_stair(subname, recipeitem, groups, images, description, sounds)`
+`stairs.register_stair(subname, recipeitem, groups, images, description, sounds, worldaligntex)`
 
- * Registers a stair.
+ * Registers a stair
  * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
  * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil`
- * `groups`: see [Known damage and digging time defining groups]
- * `images`: see [Tile definition]
- * `description`: used for the description field in the stair's definition
- * `sounds`: see [#Default sounds]
+ * `groups`: See [Known damage and digging time defining groups]
+ * `images`: See [Tile definition]
+ * `description`: Used for the description field in the stair's definition
+ * `sounds`: See [#Default sounds]
+ * `worldaligntex`: A bool to set all textures world-aligned. Default false. See [Tile definition]
 
-`stairs.register_slab(subname, recipeitem, groups, images, description, sounds)`
+`stairs.register_slab(subname, recipeitem, groups, images, description, sounds, worldaligntex)`
 
- * Registers a slabs
- * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
+ * Registers a slab
+ * `subname`: Basically the material name (e.g. cobble) used for the slab name. Nodename pattern: "stairs:slab_subname"
  * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble"
- * `groups`: see [Known damage and digging time defining groups]
- * `images`: see [Tile definition]
- * `description`: used for the description field in the stair's definition
- * `sounds`: see [#Default sounds]
+ * `groups`: See [Known damage and digging time defining groups]
+ * `images`: See [Tile definition]
+ * `description`: Used for the description field in the slab's definition
+ * `sounds`: See [#Default sounds]
+ * `worldaligntex`: A bool to set all textures world-aligned. Default false. See [Tile definition]
 
-`stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)`
+`stairs.register_stair_inner(subname, recipeitem, groups, images, description, sounds, worldaligntex, full_description)`
+
+ * Registers an inner corner stair
+ * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_inner_subname"
+ * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil`
+ * `groups`: See [Known damage and digging time defining groups]
+ * `images`: See [Tile definition]
+ * `description`: Used for the description field in the stair's definition with "Inner" prepended
+ * `sounds`: See [#Default sounds]
+ * `worldaligntex`: A bool to set all textures world-aligned. Default false. See [Tile definition]
+ * `full_description`: Overrides the description, bypassing string concatenation. This is useful for translation. (optional)
+
+`stairs.register_stair_outer(subname, recipeitem, groups, images, description, sounds, worldaligntex, full_description)`
+
+ * Registers an outer corner stair
+ * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_outer_subname"
+ * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil`
+ * `groups`: See [Known damage and digging time defining groups]
+ * `images`: See [Tile definition]
+ * `description`: Used for the description field in the stair's definition with "Outer" prepended
+ * `sounds`: See [#Default sounds]
+ * `worldaligntex`: A bool to set all textures world-aligned. Default false. See [Tile definition]
+ * `full_description`: Overrides the description, bypassing string concatenation. This is useful for translation. (optional)
 
- * A wrapper for stairs.register_stair and stairs.register_slab
+`stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds, worldaligntex)`
+
+ * A wrapper for stairs.register_stair, stairs.register_slab, stairs.register_stair_inner, stairs.register_stair_outer
  * Uses almost the same arguments as stairs.register_stair
- * `desc_stair`: Description for stair node
+ * `desc_stair`: Description for stair nodes. For corner stairs 'Inner' or 'Outer' will be prefixed
  * `desc_slab`: Description for slab node
 
+
 Xpanes API
 ----------
 
@@ -686,12 +784,18 @@ Creates panes that automatically connect to each other
 ### Pane definition
 
        {
-               textures = {"texture for sides", (unused), "texture for top and bottom"}, -- More tiles aren't supported
+               textures = {
+                       "texture for front and back",
+                       (unused),
+                       "texture for the 4 edges"
+               }, -- More tiles aren't supported
                groups = {group = rating}, -- Uses the known node groups, see [Known damage and digging time defining groups]
                sounds = SoundSpec,        -- See [#Default sounds]
                recipe = {{"","","","","","","","",""}}, -- Recipe field only
+               use_texture_alpha = true, -- Optional boolean (default: `false`) for colored glass panes
        }
 
+
 Raillike definitions
 --------------------
 
@@ -725,6 +829,7 @@ Sounds inside the default table can be used within the sounds field of node defi
  * `default.node_sound_glass_defaults()`
  * `default.node_sound_metal_defaults()`
 
+
 Default constants
 -----------------
 
@@ -742,15 +847,15 @@ GUI and formspecs
 
 `default.gui_bg`
 
- * Background color formspec element
+ * Deprecated, remove from mods.
 
 `default.gui_bg_img`
 
- * Image overlay formspec element for the background to use in formspecs
+ * Deprecated, remove from mods.
 
 `default.gui_slots`
 
- * `listcolors` formspec element that is used to format the slots in formspecs
+ * Deprecated, remove from mods.
 
 `default.gui_survival_form`
 
@@ -804,70 +909,39 @@ callback overridden. All the nodes listed in `leaves` have their
 Dyes
 ----
 
-To make recipes that will work with any dye ever made by anybody, define
-them based on groups. You can select any group of groups, based on your need for
-amount of colors.
-
-### Color groups
-
-Base color groups:
-
- * `basecolor_white`
- * `basecolor_grey`
- * `basecolor_black`
- * `basecolor_red`
- * `basecolor_yellow`
- * `basecolor_green`
- * `basecolor_cyan`
- * `basecolor_blue`
- * `basecolor_magenta`
-
-Extended color groups ( * means also base color )
-
- * `excolor_white` *
- * `excolor_lightgrey`
- * `excolor_grey` *
- * `excolor_darkgrey`
- * `excolor_black` *
- * `excolor_red` *
- * `excolor_orange`
- * `excolor_yellow` *
- * `excolor_lime`
- * `excolor_green` *
- * `excolor_aqua`
- * `excolor_cyan` *
- * `excolor_sky_blue`
- * `excolor_blue` *
- * `excolor_violet`
- * `excolor_magenta` *
- * `excolor_red_violet`
-
-The whole unifieddyes palette as groups:
-
- * `unicolor_<excolor>`
-
-For the following, no white/grey/black is allowed:
-
- * `unicolor_medium_<excolor>`
- * `unicolor_dark_<excolor>`
- * `unicolor_light_<excolor>`
- * `unicolor_<excolor>_s50`
- * `unicolor_medium_<excolor>_s50`
- * `unicolor_dark_<excolor>_s50`
-
-Example of one shapeless recipe using a color group:
+Minetest Game dyes are registered with:
+
+    groups = {dye = 1, color_<color> = 1},
+
+To make recipes that will work with dyes from many mods, define them using the
+dye group and the color groups.
+
+Dye color groups:
+
+ * `color_white`
+ * `color_grey`
+ * `color_dark_grey`
+ * `color_black`
+ * `color_red`
+ * `color_pink`
+ * `color_orange`
+ * `color_brown`
+ * `color_yellow`
+ * `color_green`
+ * `color_dark_green`
+ * `color_blue`
+ * `color_cyan`
+ * `color_violet`
+ * `color_magenta`
+
+Example of one shapeless recipe using the dye group and a color group:
 
        minetest.register_craft({
                type = "shapeless",
-               output = '<mod>:item_yellow',
-               recipe = {'<mod>:item_no_color', 'group:basecolor_yellow'},
+               output = "<mod>:item_yellow",
+               recipe = {"<mod>:item_no_color", "group:dye,color_yellow"},
        })
 
-### Color lists
-
- * `dye.basecolors` are an array containing the names of available base colors
-
- * `dye.excolors` are an array containing the names of the available extended colors
 
 Trees
 -----
@@ -905,6 +979,13 @@ Trees
  * `default.grow_acacia_bush(pos)`
   * Grows an acaia bush at pos
 
+ * `default.grow_pine_bush(pos)`
+  * Grows a pine bush at pos
+
+ * `default.grow_blueberry_bush(pos)`
+  * Grows a blueberry bush at pos
+
+
 Carts
 -----
 
@@ -927,6 +1008,7 @@ Carts
        likely be called many times per second, so the function needs
        to make sure that the event is handled properly.
 
+
 Key API
 -------
 
@@ -984,3 +1066,11 @@ for the wielded skeleton key.
 
 if `nil` is returned, it is assumed that the wielder did not have
 permissions to create a key for this node, and no key is created.
+
+`default.register_craft_metadata_copy(ingredient, result)`
+----------------------------------------------------------
+
+This function registers a shapeless recipe that takes `ingredient`
+and `result` as input and outputs `result`.
+
+The metadata of the input `result` is copied to the output `result`.