X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=doc%2Flua_api.txt;h=07ed27cdfcb2274650b82acc4efb92216bbcb336;hb=1137f469e2cec17708756d5263c3ffdbf6174099;hp=2a3ecf3b6eabc112a4fe39db155700336293129d;hpb=b312ab44558b793a07621689834d3ae78a388adc;p=minetest.git diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 2a3ecf3b6..07ed27cdf 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 ------------------ @@ -51,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 ------------- @@ -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 @@ -219,8 +222,7 @@ 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, @@ -229,7 +231,7 @@ 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") @@ -330,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. @@ -552,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 @@ -576,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. @@ -586,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. @@ -597,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). @@ -618,6 +622,7 @@ 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", { @@ -1023,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: @@ -1151,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. @@ -1280,11 +1296,11 @@ in the form of a table. This table specifies the following fields: * 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: @@ -1829,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: @@ -1877,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) @@ -2041,8 +2066,8 @@ examples. #### `item_image_button[,;,;;;