X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=doc%2Flua_api.txt;h=eb30608250a8991e57ae25662c6ca6e7e89cea16;hb=0f015b28a30f77e006528a36c8d5b7705b0d6423;hp=91ea900d0ce9f366e51e851402cdc9f93d68b62b;hpb=75320e7e88ab5088a46c9e42c1e789cbdacb13b0;p=minetest.git diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 91ea900d0..eb3060825 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1,21 +1,21 @@ -Minetest Lua Modding API Reference 0.5.0 -========================================= +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. +functionality in the engine and API, and to document it here. Programming in Lua ------------------ @@ -47,37 +47,41 @@ Paths Games ----- 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. + * `$path_share/games/gameid/` + * `$path_user/games/gameid/` +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 ------------- @@ -153,15 +157,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 @@ -214,12 +218,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, @@ -228,13 +232,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 @@ -260,7 +333,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. @@ -340,7 +413,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. @@ -516,10 +589,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. @@ -527,10 +600,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). @@ -953,6 +1026,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: @@ -1081,7 +1165,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. @@ -1105,7 +1189,7 @@ 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 +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 @@ -1118,16 +1202,16 @@ 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 + 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. @@ -1136,20 +1220,25 @@ computationally expensive than any other ore. 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` varies the Y co-ordinate of the +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` -varies the stratum's vertical thickness (in units of nodes). Due to being +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. -If either of the 2 noise parameters are omitted the ore will occur from y_min -to y_max in a simple horizontal stratum. As this does not compute noise -performance improves, and is ideal for placing many layers. - 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. @@ -1201,15 +1290,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: @@ -1687,7 +1776,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: @@ -1754,7 +1843,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: @@ -1802,14 +1891,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) @@ -1966,8 +2064,8 @@ examples. #### `item_image_button[,;,;;;