Enable player animation when Right Click (#2622)
[oweals/minetest_game.git] / game_api.txt
index 90594e8fdf376c611aa94e0a9964435ffc694b76..6d8b08f70a97c0b4c88e838a2ce805478bef6450 100644 (file)
@@ -2,6 +2,7 @@ Minetest Game API
 =================
 GitHub Repo: https://github.com/minetest/minetest_game
 
+
 Introduction
 ------------
 
@@ -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
 --------
 
@@ -68,6 +71,7 @@ Beds API
                }
        }
 
+
 Bones API
 ---------
 
@@ -77,6 +81,7 @@ in `bones.player_inventory_lists`.
 
 e.g. `table.insert(bones.player_inventory_lists, "backpack")`
 
+
 Creative API
 ------------
 
@@ -98,6 +103,14 @@ 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
 ----------
 
@@ -148,11 +161,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
@@ -188,17 +208,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
 
@@ -206,11 +237,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
 
@@ -220,6 +260,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
 ----------------
@@ -240,7 +283,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
@@ -250,9 +293,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
 ---------
 
@@ -274,6 +319,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
 ---------
 
@@ -286,6 +332,7 @@ walls.register(name, desc, texture, mat, sounds)
 ^ mat = "default:stone". Used to auto-generate crafting recipe.
 ^ sounds = sounds: see [#Default sounds]
 
+
 Farming API
 -----------
 
@@ -319,6 +366,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)
@@ -326,9 +375,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)`
@@ -379,7 +431,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
@@ -412,6 +464,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
 
        {
@@ -422,7 +480,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
@@ -557,6 +615,7 @@ sfinv API by its author: https://rubenwardy.com/minetest_modding_book/en/chapter
 **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.
@@ -653,39 +712,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)
 
- * A wrapper for stairs.register_stair and stairs.register_slab
+`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)
+
+`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
 ----------
 
@@ -699,13 +786,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
 --------------------
 
@@ -739,6 +831,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
 -----------------
 
@@ -818,70 +911,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
 -----
@@ -919,6 +981,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
 -----
 
@@ -941,6 +1010,7 @@ Carts
        likely be called many times per second, so the function needs
        to make sure that the event is handled properly.
 
+
 Key API
 -------
 
@@ -998,3 +1068,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`.