X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=doc%2Flua_api.txt;h=07ed27cdfcb2274650b82acc4efb92216bbcb336;hb=1137f469e2cec17708756d5263c3ffdbf6174099;hp=56f8dbaaef13f427240f9011766752283bff78cb;hpb=3caad3f3c9e319ca67d63231e8c64b2ace855fff;p=minetest.git diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 56f8dbaae..07ed27cdf 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1,22 +1,21 @@ -Minetest Lua Modding API Reference 0.4.16 -========================================= +Minetest Lua Modding API Reference +================================== * More information at * Developer Wiki: Introduction ------------ -Content and functionality can be added to Minetest 0.4 by using Lua -scripting in run-time loaded mods. +Content and functionality can be added to Minetest using Lua scripting +in run-time loaded mods. A mod is a self-contained bunch of scripts, textures and other related -things that is loaded by and interfaces with Minetest. +things, which is loaded by and interfaces with Minetest. Mods are contained and ran solely on the server side. Definitions and media files are automatically transferred to the client. If you see a deficiency in the API, feel free to attempt to add the -functionality in the engine and API. You can send such improvements as -source code patches to . +functionality in the engine and API, and to document it here. Programming in Lua ------------------ @@ -52,33 +51,36 @@ Games are looked up from: * `$path_share/games/gameid/` * `$path_user/games/gameid/` -where `gameid` is unique to each game. - -The game directory contains the file `game.conf`, which contains these fields: - - name = - -e.g. - - name = Minetest - -The game directory can contain the file minetest.conf, which will be used -to set default settings when running the particular game. -It can also contain a settingtypes.txt in the same format as the one in builtin. -This settingtypes.txt will be parsed by the menu and the settings will be displayed -in the "Games" category in the settings tab. +Where `gameid` is unique to each game. + +The game directory can contain the following files: + +* `game.conf`, which contains: + * `name = ` e.g. `name = Minetest` + * Optionally, game.conf can also contain + `disallowed_mapgens = ` + e.g. `disallowed_mapgens = v5,v6,flat` + These mapgens are removed from the list of mapgens for the game. +* `minetest.conf`: + Used to set default settings when running this game. +* `settingtypes.txt`: + In the same format as the one in builtin. + This settingtypes.txt will be parsed by the menu and the settings will be + displayed in the "Games" category in the advanced settings tab. +* If the subgame contains a folder called `textures` the server will load it + as a texturepack, overriding mod textures. + Any server texturepack will override mod textures and the game texturepack. ### Menu images -Games can provide custom main menu images. They are put inside a `menu` directory -inside the game directory. - -The images are named `$identifier.png`, where `$identifier` is -one of `overlay,background,footer,header`. -If you want to specify multiple images for one identifier, add additional images named -like `$identifier.$n.png`, with an ascending number $n starting with 1, and a random -image will be chosen from the provided ones. +Games can provide custom main menu images. They are put inside a `menu` +directory inside the game directory. +The images are named `$identifier.png`, where `$identifier` is one of +`overlay`, `background`, `footer`, `header`. +If you want to specify multiple images for one identifier, add additional +images named like `$identifier.$n.png`, with an ascending number $n starting +with 1, and a random image will be chosen from the provided ones. Mod load path ------------- @@ -139,6 +141,7 @@ Mod directory structure | | `-- modname_something_else.png | |-- sounds | |-- media + | |-- locale | `-- `-- another @@ -153,15 +156,15 @@ List of mods that have to be loaded before loading this mod. A single line contains a single modname. Optional dependencies can be defined by appending a question mark -to a single modname. Their meaning is that if the specified mod -is missing, that does not prevent this mod from being loaded. +to a single modname. This means that if the specified mod +is missing, it does not prevent this mod from being loaded. ### `screenshot.png` A screenshot shown in the mod manager within the main menu. It should have an aspect ratio of 3:2 and a minimum size of 300×200 pixels. ### `description.txt` -A File containing description to be shown within mainmenu. +A file containing a description to be shown in the Mods tab of the mainmenu. ### `settingtypes.txt` A file in the same format as the one in builtin. It will be parsed by the @@ -182,6 +185,9 @@ Models for entities or meshnodes. Media files (textures, sounds, whatever) that will be transferred to the client and will be available for use by the mod. +### `locale` +Translation files for the clients. (See `Translations`) + Naming convention for registered textual names ---------------------------------------------- Registered names should generally be in this format: @@ -211,12 +217,12 @@ when registering it. The `:` prefix can also be used for maintaining backwards compatibility. -### Aliases +Aliases +------- Aliases can be added by using `minetest.register_alias(name, convert_to)` or `minetest.register_alias_force(name, convert_to)`. -This will make Minetest to convert things called name to things called -`convert_to`. +This converts anything called `name` to `convert_to`. The only difference between `minetest.register_alias` and `minetest.register_alias_force` is that if an item called `name` exists, @@ -225,13 +231,82 @@ The only difference between `minetest.register_alias` and This can be used for maintaining backwards compatibility. -This can be also used for setting quick access names for things, e.g. if +This can also set quick access names for things, e.g. if you have an item called `epiclylongmodname:stuff`, you could do minetest.register_alias("stuff", "epiclylongmodname:stuff") and be able to use `/giveme stuff`. +Mapgen aliases +-------------- +In a game, a certain number of these must be set to tell core mapgens which +of the game's nodes are to be used by the core mapgens. For example: + + minetest.register_alias("mapgen_stone", "default:stone") + +### Aliases needed for all mapgens except Mapgen v6 + +Base terrain: + +"mapgen_stone" +"mapgen_water_source" +"mapgen_river_water_source" + +Caves: + +"mapgen_lava_source" + +Dungeons: + +Only needed for registered biomes where 'node_stone' is stone: +"mapgen_cobble" +"mapgen_stair_cobble" +"mapgen_mossycobble" +Only needed for registered biomes where 'node_stone' is desert stone: +"mapgen_desert_stone" +"mapgen_stair_desert_stone" +Only needed for registered biomes where 'node_stone' is sandstone: +"mapgen_sandstone" +"mapgen_sandstonebrick" +"mapgen_stair_sandstone_block" + +### Aliases needed for Mapgen v6 + +Terrain and biomes: + +"mapgen_stone" +"mapgen_water_source" +"mapgen_lava_source" +"mapgen_dirt" +"mapgen_dirt_with_grass" +"mapgen_sand" +"mapgen_gravel" +"mapgen_desert_stone" +"mapgen_desert_sand" +"mapgen_dirt_with_snow" +"mapgen_snowblock" +"mapgen_snow" +"mapgen_ice" + +Flora: + +"mapgen_tree" +"mapgen_leaves" +"mapgen_apple" +"mapgen_jungletree" +"mapgen_jungleleaves" +"mapgen_junglegrass" +"mapgen_pine_tree" +"mapgen_pine_needles" + +Dungeons: + +"mapgen_cobble" +"mapgen_stair_cobble" +"mapgen_mossycobble" +"mapgen_stair_desert_stone" + Textures -------- Mods should generally prefix their textures with `modname_`, e.g. given @@ -257,7 +332,7 @@ Example: default_dirt.png^default_grass_side.png -`default_grass_side.png` is overlayed over `default_dirt.png`. +`default_grass_side.png` is overlaid over `default_dirt.png`. The texture with the lower resolution will be automatically upscaled to the higher resolution texture. @@ -281,11 +356,19 @@ on top of `cobble.png`. ### Advanced texture modifiers -#### `[crack::

` +#### Crack +* `[crack::

` +* `[cracko::

` +* `[crack:::

` +* `[cracko:::

` + +Parameters: +* `` = tile count (in each direction) * `` = animation frame count * `

` = current animation frame Draw a step of the crack animation on the texture. +`crack` draws it normally, while `cracko` lays it over, keeping transparent pixels intact. Example: @@ -329,7 +412,7 @@ Only the channels that are mentioned in the mode string will be inverted. Example: - default_apple.png^[invert:rgb + default_apple.png^[invert:rgb #### `[brighten` Brightens the texture. @@ -471,6 +554,7 @@ stretched to contain exactly 256 pixels (after arranging the pixels to one line). The indexing starts from 0. Examples: + * 16x16 palette, index = 0: the top left corner * 16x16 palette, index = 4: the fifth pixel in the first row * 16x16 palette, index = 16: the pixel below the top left corner @@ -495,6 +579,7 @@ When registering a node, set the item definition's `palette` field to a texture. You can also use texture modifiers. The node's color depends on its `param2`, so you also must set an appropriate `drawtype`: + * `drawtype = "color"` for nodes which use their full `param2` for palette indexing. These nodes can have 256 different colors. The palette should contain 256 pixels. @@ -505,10 +590,10 @@ appropriate `drawtype`: palette). These nodes can have 32 different colors, and the palette should contain 32 pixels. Examples: - * `param2 = 17` is 2 * 8 + 1, so the rotation is 1 and the third (= 2 + 1) - pixel will be picked from the palette. - * `param2 = 35` is 4 * 8 + 3, so the rotation is 3 and the fifth (= 4 + 1) - pixel will be picked from the palette. + * `param2 = 17` is 2 * 8 + 1, so the rotation is 1 and the third (= 2 + 1) + pixel will be picked from the palette. + * `param2 = 35` is 4 * 8 + 3, so the rotation is 3 and the fifth (= 4 + 1) + pixel will be picked from the palette. * `drawtype = "colorfacedir"` for nodes which use the first three bits of `param2` for palette indexing. The remaining five bits are describing rotation, as in `facedir` draw type. @@ -516,10 +601,10 @@ appropriate `drawtype`: palette). These nodes can have 8 different colors, and the palette should contain 8 pixels. Examples: - * `param2 = 17` is 0 * 32 + 17, so the rotation is 17 and the - first (= 0 + 1) pixel will be picked from the palette. - * `param2 = 35` is 1 * 32 + 3, so the rotation is 3 and the - second (= 1 + 1) pixel will be picked from the palette. + * `param2 = 17` is 0 * 32 + 17, so the rotation is 17 and the + first (= 0 + 1) pixel will be picked from the palette. + * `param2 = 35` is 1 * 32 + 3, so the rotation is 3 and the + second (= 1 + 1) pixel will be picked from the palette. To colorize a node on the map, set its `param2` value (according to the node's draw type). @@ -536,6 +621,22 @@ automatically transferred between node and item forms by the engine, when a player digs or places a colored node. You can disable this feature by setting the `drop` field of the node to itself (without metadata). +To transfer the color to a special drop, you need a drop table. + +Example: + + minetest.register_node("mod:stone", { + description = "Stone", + tiles = {"default_stone.png"}, + paramtype2 = "color", + palette = "palette.png", + drop = { + items = { + -- assume that mod:cobblestone also has the same palette + {items = {"mod:cobblestone"}, inherit_color = true }, + } + } + }) ### Colored items in craft recipes Craft recipes only support item strings, but fortunately item strings @@ -569,7 +670,11 @@ other. This allows different hardware coloring, but also means that tiles with overlays are drawn slower. Using too much overlays might cause FPS loss. -To define an overlay, simply set the `overlay_tiles` field of the node +For inventory and wield images you can specify overlays which +hardware coloring does not modify. You have to set `inventory_overlay` +and `wield_overlay` fields to an image name. + +To define a node overlay, simply set the `overlay_tiles` field of the node definition. These tiles are defined in the same way as plain tiles: they can have a texture name, color etc. To skip one face, set that overlay tile to an empty string. @@ -692,6 +797,10 @@ the global `minetest.registered_*` tables. * added to `minetest.registered_biome` with the key of `biome.name` * if `biome.name` is nil, the key is the returned ID +* `minetest.unregister_biome(name)` + * Unregisters the biome name from engine, and deletes the entry with key + * `name` from `minetest.registered_biome` + * `minetest.register_ore(ore definition)` * returns an integer uniquely identifying the registered ore * added to `minetest.registered_ores` with the key of `ore.name` @@ -797,6 +906,15 @@ node definition: 0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y- facedir modulo 4 = rotation around that axis paramtype2 == "leveled" + ^ Only valid for "nodebox" with 'type = "leveled"', and "plantlike_rooted". + Leveled nodebox: + The level of the top face of the nodebox is stored in param2. + The other faces are defined by 'fixed = {}' like 'type = "fixed"' nodeboxes. + The nodebox height is (param2 / 64) nodes. + The maximum accepted value of param2 is 127. + Rooted plantlike: + The height of the 'plantlike' section is stored in param2. + The height is (param2 / 16) nodes. paramtype2 == "degrotate" ^ The rotation of this node is stored in param2. Plants are rotated this way. Values range 0 - 179. The value stored in param2 is multiplied by two to @@ -832,13 +950,14 @@ node definition: The palette should have 32 pixels. paramtype2 == "glasslikeliquidlevel" ^ Only valid for "glasslike_framed" or "glasslike_framed_optional" drawtypes. - param2 defines 64 levels of internal liquid. + param2 values 0-63 define 64 levels of internal liquid, 0 being empty and + 63 being full. Liquid texture is defined using `special_tiles = {"modname_tilename.png"},` Nodes can also contain extra data. See "Node Metadata". Node drawtypes ---------------- +-------------- There are a bunch of different looking node types. Look for examples in `games/minimal` or `games/minetest_game`. @@ -858,21 +977,18 @@ Look for examples in `games/minimal` or `games/minetest_game`. * `firelike` * `fencelike` * `raillike` -* `nodebox` -- See below. (**Experimental!**) -* `mesh` -- use models for nodes +* `nodebox` -- See below +* `mesh` -- Use models for nodes, see below +* `plantlike_rooted` -- See below `*_optional` drawtypes need less rendering time if deactivated (always client side). Node boxes ------------ +---------- Node selection boxes are defined using "node boxes" -The `nodebox` node drawtype allows defining visual of nodes consisting of -arbitrary number of boxes. It allows defining stuff like stairs. Only the -`fixed` and `leveled` box type is supported for these. - -Please note that this is still experimental, and may be incompatibly -changed in the future. +The `nodebox` node drawtype allows defining nodes consisting of an arbitrary +number of boxes. It allows defining stuff like stairs and slabs. A nodebox is defined as any of: @@ -881,10 +997,18 @@ A nodebox is defined as any of: type = "regular" } { - -- A fixed box (facedir param2 is used, if applicable) + -- A fixed box (or boxes) (facedir param2 is used, if applicable) type = "fixed", fixed = box OR {box1, box2, ...} } + { + -- A variable height box (or boxes) with the top face position defined by + -- the node parameter 'leveled = ', or if 'paramtype2 == "leveled"' by + -- param2. + -- Other faces are defined by 'fixed = {}' as with 'type = "fixed"'. + type = "leveled", + fixed = box OR {box1, box2, ...} + } { -- A box like the selection box for torches -- (wallmounted param2 is used, if applicable) @@ -904,6 +1028,17 @@ A nodebox is defined as any of: connect_left = box OR {box1, box2, ...} connect_back = box OR {box1, box2, ...} connect_right = box OR {box1, box2, ...} + -- The following `disconnected_*` boxes are the opposites of the + -- `connect_*` ones above, i.e. when a node has no suitable neighbour + -- on the respective side, the corresponding disconnected box is drawn. + disconnected_top = box OR {box1, box2, ...} + disconnected_bottom = box OR {box1, box2, ...} + disconnected_front = box OR {box1, box2, ...} + disconnected_left = box OR {box1, box2, ...} + disconnected_back = box OR {box1, box2, ...} + disconnected_right = box OR {box1, box2, ...} + disconnected = box OR {box1, box2, ...} -- when there is *no* neighbour + disconnected_sides = box OR {box1, box2, ...} -- when there are *no* neighbours to the sides } A `box` is defined as: @@ -914,16 +1049,24 @@ A box of a regular node would look like: {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -`type = "leveled"` is same as `type = "fixed"`, but `y2` will be automatically -set to level from `param2`. - - Meshes ------ If drawtype `mesh` is used, tiles should hold model materials textures. Only static meshes are implemented. For supported model formats see Irrlicht engine documentation. +Rooted plantlike drawtype +------------------------- +The `plantlike_rooted` drawtype was developed to enable underwater plants +without air bubbles around the plants. +It consists of a base cube at the co-ordinates of the node (the seabed / +lakebed / riverbed node) plus a 'plantlike' extension above with a height +defined by param2 (maximum height 16 nodes). This extension visually passes +through any nodes above the base cube without affecting them. +The node is dug by digging the base cube. +The base cube texture tiles are defined as normal, the plantlike extension +uses the defined 'special tile', for example: +`special_tiles = {{name = "default_papyrus.png", tileable_vertical = true}},` Noise Parameters ---------------- @@ -1024,7 +1167,7 @@ If `column_height_max` is not specified, this parameter defaults to `clust_size` for reverse compatibility. New code should prefer `column_height_max`. The `column_midpoint_factor` parameter controls the position of the column at which -ore eminates from. If 1, columns grow upward. If 0, columns grow downward. If 0.5, +ore emanates from. If 1, columns grow upward. If 0, columns grow downward. If 0.5, columns grow equally starting from each direction. `column_midpoint_factor` is a decimal number ranging in value from 0 to 1. If this parameter is not specified, the default is 0.5. @@ -1041,7 +1184,6 @@ within the currently generated chunk. The vertical top and bottom displacement of each puff are determined by the noise parameters `np_puff_top` and `np_puff_bottom`, respectively. - ### `blob` Creates a deformed sphere of ore according to 3d perlin noise described by `noise_params`. The maximum size of the blob is `clust_size`, and @@ -1049,28 +1191,62 @@ Creates a deformed sphere of ore according to 3d perlin noise described by ### `vein` Creates veins of ore varying in density by according to the intersection of two -instances of 3d perlin noise with diffferent seeds, both described by -`noise_params`. `random_factor` varies the influence random chance has on -placement of an ore inside the vein, which is `1` by default. Note that -modifying this parameter may require adjusting `noise_threshold`. +instances of 3d perlin noise with different seeds, both described by +`noise_params`. + +`random_factor` varies the influence random chance has on placement of an ore +inside the vein, which is `1` by default. Note that modifying this parameter may +require adjusting `noise_threshold`. + The parameters `clust_scarcity`, `clust_num_ores`, and `clust_size` are ignored -by this ore type. This ore type is difficult to control since it is sensitive -to small changes. The following is a decent set of parameters to work from: - - noise_params = { - offset = 0, - scale = 3, - spread = {x=200, y=200, z=200}, - seed = 5390, - octaves = 4, - persist = 0.5, - flags = "eased", - }, - noise_threshold = 1.6 +by this ore type. + +This ore type is difficult to control since it is sensitive to small changes. +The following is a decent set of parameters to work from: + + noise_params = { + offset = 0, + scale = 3, + spread = {x=200, y=200, z=200}, + seed = 5390, + octaves = 4, + persist = 0.5, + flags = "eased", + }, + noise_threshold = 1.6 **WARNING**: Use this ore type *very* sparingly since it is ~200x more computationally expensive than any other ore. +### `stratum` +Creates a single undulating ore stratum that is continuous across mapchunk +borders and horizontally spans the world. + +The 2D perlin noise described by `noise_params` defines the Y co-ordinate of the +stratum midpoint. The 2D perlin noise described by `np_stratum_thickness` +defines the stratum's vertical thickness (in units of nodes). Due to being +continuous across mapchunk borders the stratum's vertical thickness is +unlimited. + +If the noise parameter `noise_params` is omitted the ore will occur from y_min +to y_max in a simple horizontal stratum. + +A parameter `stratum_thickness` can be provided instead of the noise parameter +`np_stratum_thickness`, to create a constant thickness. + +Leaving out one or both noise parameters makes the ore generation less intensive, +useful when adding multiple strata. + +`y_min` and `y_max` define the limits of the ore generation and for performance +reasons should be set as close together as possible but without clipping the +stratum's Y variation. + +Each node in the stratum has a 1-in-`clust_scarcity` chance of being ore, so a +solid-ore stratum would require a `clust_scarcity` of 1. + +The parameters `clust_num_ores`, `clust_size`, `noise_threshold` and +`random_factor` are ignored by this ore type. + Ore attributes -------------- See section "Flag Specifier Format". @@ -1116,15 +1292,15 @@ in the form of a table. This table specifies the following fields: * The `size` field is a 3D vector containing the dimensions of the provided schematic. (required) * The `yslice_prob` field is a table of {ypos, prob} which sets the `ypos`th vertical slice - of the schematic to have a `prob / 256 * 100` chance of occuring. (default: 255) + of the schematic to have a `prob / 256 * 100` chance of occurring. (default: 255) * The `data` field is a flat table of MapNode tables making up the schematic, in the order of `[z [y [x]]]`. (required) Each MapNode table contains: - * `name`: the name of the map node to place (required) - * `prob` (alias `param1`): the probability of this node being placed (default: 255) - * `param2`: the raw param2 value of the node being placed onto the map (default: 0) - * `force_place`: boolean representing if the node should forcibly overwrite any - previous contents (default: false) + * `name`: the name of the map node to place (required) + * `prob` (alias `param1`): the probability of this node being placed (default: 255) + * `param2`: the raw param2 value of the node being placed onto the map (default: 0) + * `force_place`: boolean representing if the node should forcibly overwrite any + previous contents (default: false) About probability values: @@ -1423,6 +1599,9 @@ Another example: Make red wool from white wool and red dye: * `soil`: saplings will grow on nodes in this group * `connect_to_raillike`: makes nodes of raillike drawtype with same group value connect to each other +* `slippery`: Players and items will slide on the node. + Slipperiness rises steadily with `slippery` value, starting at 1. + ### Known damage and digging time defining groups * `crumbly`: dirt, sand @@ -1599,7 +1778,7 @@ the entity itself. * `direction` is a unit vector, pointing from the source of the punch to the punched object. * `damage` damage that will be done to entity -Return value of this function will determin if damage is done by this function +Return value of this function will determine if damage is done by this function (retval true) or shall be done by engine (retval false) To punch an entity/object in Lua, call: @@ -1666,7 +1845,7 @@ Some of the values in the key-value store are handled specially: * `description`: Set the item stack's description. Defaults to `idef.description` * `color`: A `ColorString`, which sets the stack's color. * `palette_index`: If the item has a palette, this is used to get the - current color from the palette. + current color from the palette. Example stuff: @@ -1714,14 +1893,23 @@ examples. * deprecated: `invsize[,;]` #### `position[,]` -* Define the position of the formspec -* A value between 0.0 and 1.0 represents a position inside the screen -* The default value is the center of the screen (0.5, 0.5) +* Must be used after `size` element. +* Defines the position on the game window of the formspec's `anchor` point. +* For X and Y, 0.0 and 1.0 represent opposite edges of the game window, for example: + * [0.0, 0.0] sets the position to the top left corner of the game window. + * [1.0, 1.0] sets the position to the bottom right of the game window. +* Defaults to the center of the game window [0.5, 0.5]. #### `anchor[,]` -* Define the anchor of the formspec -* A value between 0.0 and 1.0 represents an anchor inside the formspec -* The default value is the center of the formspec (0.5, 0.5) +* Must be used after both `size` and `position` (if present) elements. +* Defines the location of the anchor point within the formspec. +* For X and Y, 0.0 and 1.0 represent opposite edges of the formspec, for example: + * [0.0, 1.0] sets the anchor to the bottom left corner of the formspec. + * [1.0, 0.0] sets the anchor to the top right of the formspec. +* Defaults to the center of the formspec [0.5, 0.5]. + +* `position` and `anchor` elements need suitable values to avoid a formspec + extending off the game window due to particular game window sizes. #### `container[,]` * Start of a container block, moves all physical elements in the container by (X, Y) @@ -1840,6 +2028,8 @@ examples. #### `textarea[,;,;;