X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=doc%2Flua_api.txt;h=b045f640223040139380eecd3eb024d471e4ca32;hb=68c6494af08c5a9b5b1f9169753d9ba8c106db23;hp=152da5985241bb89ac1d16521f2e143f7bb6fc05;hpb=5a6618cc57097e1e7205ad6b1d967a3ad79d016e;p=oweals%2Fminetest.git diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 152da5985..b045f6402 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1,22 +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. 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 game 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 ------------- @@ -154,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 @@ -215,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, @@ -229,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 @@ -261,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. @@ -285,11 +356,20 @@ 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: @@ -333,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. @@ -378,7 +458,8 @@ Example: default_stone.png^[transformFXR90 #### `[inventorycube{{{` -Escaping does not apply here and `^` is replaced by `&` in texture names instead. +Escaping does not apply here and `^` is replaced by `&` in texture names +instead. Create an inventory cube texture using the side textures. @@ -431,8 +512,8 @@ texture pixel. Multiplies texture colors with the given color. `` is specified as a `ColorString`. Result is more like what you'd expect if you put a color on top of another -color. Meaning white surfaces get a lot of your new color while black parts don't -change very much. +color. Meaning white surfaces get a lot of your new color while black parts +don't change very much. Hardware coloring ----------------- @@ -475,6 +556,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 @@ -498,35 +580,36 @@ index of the pixel to use. 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 +appropriate `paramtype2`: + +* `paramtype2 = "color"` for nodes which use their full `param2` for palette indexing. These nodes can have 256 different colors. The palette should contain 256 pixels. -* `drawtype = "colorwallmounted"` for nodes which use the first +* `paramtype2 = "colorwallmounted"` for nodes which use the first five bits (most significant) of `param2` for palette indexing. The remaining three bits are describing rotation, as in `wallmounted` - draw type. Division by 8 yields the palette index (without stretching the + paramtype2. Division by 8 yields the palette index (without stretching the 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. -* `drawtype = "colorfacedir"` for nodes which use the first + * `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. +* `paramtype2 = "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. + five bits are describing rotation, as in `facedir` paramtype2. Division by 32 yields the palette index (without stretching the 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). +to the node's paramtype2). ### Conversion between nodes in the inventory and the on the map Static coloring is the same for both cases, there is no need @@ -541,6 +624,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", { @@ -715,6 +799,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` @@ -722,16 +810,19 @@ the global `minetest.registered_*` tables. * `minetest.register_decoration(decoration definition)` * returns an integer uniquely identifying the registered decoration - * added to `minetest.registered_decorations` with the key of `decoration.name` + * added to `minetest.registered_decorations` with the key of + `decoration.name`. * if `decoration.name` is nil, the key is the returned ID * `minetest.register_schematic(schematic definition)` * returns an integer uniquely identifying the registered schematic * added to `minetest.registered_schematic` with the key of `schematic.name` * if `schematic.name` is nil, the key is the returned ID - * if the schematic is loaded from a file, schematic.name is set to the filename - * if the function is called when loading the mod, and schematic.name is a relative - path, then the current mod path will be prepended to the schematic filename + * if the schematic is loaded from a file, schematic.name is set to the + filename. + * if the function is called when loading the mod, and schematic.name is a + relative path, then the current mod path will be prepended to the + schematic filename. * `minetest.clear_registered_biomes()` * clears all biomes currently registered @@ -820,14 +911,25 @@ 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. + ^ Only valid for "plantlike". The rotation of the node is stored in param2. Values range 0 - 179. The value stored in param2 is multiplied by two to - get the actual rotation of the node. + get the actual rotation in degrees of the node. paramtype2 == "meshoptions" - ^ Only valid for "plantlike". The value of param2 becomes a bitfield which can - be used to change how the client draws plantlike nodes. Bits 0, 1 and 2 form - a mesh selector. Currently the following meshes are choosable: + ^ Only valid for "plantlike". The value of param2 becomes a bitfield which + can be used to change how the client draws plantlike nodes. + Bits 0, 1 and 2 form a mesh selector. + Currently the following meshes are choosable: 0 = a "x" shaped plant (ordinary plant) 1 = a "+" shaped plant (just rotated 45 degrees) 2 = a "*" shaped plant with 3 faces instead of 2 @@ -854,49 +956,107 @@ node definition: is picked from the palette. 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. + ^ Only valid for "glasslike_framed" or "glasslike_framed_optional" + drawtypes. + 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`. * `normal` + * A node-sized cube. * `airlike` + * Invisible, uses no texture. * `liquid` + * The cubic source node for a liquid. * `flowingliquid` + * The flowing version of a liquid, appears with various heights and slopes. * `glasslike` + * Often used for partially-transparent nodes. + * Only external sides of textures are visible. * `glasslike_framed` + * All face-connected nodes are drawn as one volume within a surrounding + frame. + * The frame appearence is generated from the edges of the first texture + specified in `tiles`. The width of the edges used are 1/16th of texture + size: 1 pixel for 16x16, 2 pixels for 32x32 etc. + * The glass 'shine' (or other desired detail) on each node face is supplied + by the second texture specified in `tiles`. * `glasslike_framed_optional` + * This switches between the above 2 drawtypes according to the menu setting + 'Connected Glass'. * `allfaces` + * Often used for partially-transparent nodes. + * External and internal sides of textures are visible. * `allfaces_optional` + * Often used for leaves nodes. + * This switches between `normal`, `glasslike` and `allfaces` according to + the menu setting: Opaque Leaves / Simple Leaves / Fancy Leaves. + * With 'Simple Leaves' selected, the texture specified in `special_tiles` + is used instead, if present. This allows a visually thicker texture to be + used to compensate for how `glasslike` reduces visual thickness. * `torchlike` + * A single vertical texture. + * If placed on top of a node, uses the first texture specified in `tiles`. + * If placed against the underside of a node, uses the second texture + specified in `tiles`. + * If placed on the side of a node, uses the third texture specified in + `tiles` and is perpendicular to that node. * `signlike` + * A single texture parallel to, and mounted against, the top, underside or + side of a node. * `plantlike` + * Two vertical and diagonal textures at right-angles to each other. + * See `paramtype2 == "meshoptions"` above for other options. * `firelike` + * When above a flat surface, appears as 6 textures, the central 2 as + `plantlike` plus 4 more surrounding those. + * If not above a surface the central 2 do not appear, but the texture + appears against the faces of surrounding nodes if they are present. * `fencelike` + * A 3D model suitable for a wooden fence. + * One placed node appears as a single vertical post. + * Adjacently-placed nodes cause horizontal bars to appear between them. * `raillike` -* `nodebox` -- See below. (**Experimental!**) -* `mesh` -- use models for nodes + * Often used for tracks for mining carts. + * Requires 4 textures to be specified in `tiles`, in order: Straight, + curved, t-junction, crossing. + * Each placed node automatically switches to a suitable rotated texture + determined by the adjacent `raillike` nodes, in order to create a + continuous track network. + * Becomes a sloping node if placed against stepped nodes. +* `nodebox` + * Often used for stairs and slabs. + * Allows defining nodes consisting of an arbitrary number of boxes. + * See 'Node boxes' below for more information. +* `mesh` + * Uses models for nodes. + * Tiles should hold model materials textures. + * Only static meshes are implemented. + * For supported model formats see Irrlicht engine documentation. * `plantlike_rooted` - -`*_optional` drawtypes need less rendering time if deactivated (always client side). + * Enables underwater `plantlike` without air bubbles around the nodes. + * Consists of a base cube at the co-ordinates of the node plus a + `plantlike` extension above with a height of `param2 / 16` nodes. + * The `plantlike` extension visually passes through any nodes above the + base cube without affecting them. + * 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}},` + +`*_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. +---------- +Node selection boxes are defined using "node boxes". A nodebox is defined as any of: @@ -905,10 +1065,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) @@ -928,6 +1096,18 @@ 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: @@ -938,17 +1118,6 @@ 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. - - Noise Parameters ---------------- Noise Parameters, or commonly called "`NoiseParams`", define the properties of @@ -961,14 +1130,16 @@ Offset that the noise is translated by (i.e. added) after calculation. Factor that the noise is scaled by (i.e. multiplied) after calculation. ### `spread` -Vector containing values by which each coordinate is divided by before calculation. +Vector containing values by which each coordinate is divided by before +calculation. Higher spread values result in larger noise features. A value of `{x=250, y=250, z=250}` is common. ### `seed` -Random seed for the noise. Add the world seed to a seed offset for world-unique noise. -In the case of `minetest.get_perlin()`, this value has the world seed automatically added. +Random seed for the noise. Add the world seed to a seed offset for world-unique +noise. In the case of `minetest.get_perlin()`, this value has the world seed +automatically added. ### `octaves` Number of times the noise gradient is accumulated into the noise. @@ -978,10 +1149,11 @@ Increase this number to increase the amount of detail in the resulting noise. A value of `6` is common. ### `persistence` -Factor by which the effect of the noise gradient function changes with each successive octave. +Factor by which the effect of the noise gradient function changes with each +successive octave. -Values less than `1` make the details of successive octaves' noise diminish, while values -greater than `1` make successive octaves stronger. +Values less than `1` make the details of successive octaves' noise diminish, +while values greater than `1` make successive octaves stronger. A value of `0.6` is common. @@ -996,13 +1168,15 @@ Leave this field unset for no special handling. Currently supported are `defaults`, `eased` and `absvalue`. #### `defaults` -Specify this if you would like to keep auto-selection of eased/not-eased while specifying -some other flags. +Specify this if you would like to keep auto-selection of eased/not-eased while +specifying some other flags. #### `eased` -Maps noise gradient values onto a quintic S-curve before performing interpolation. -This results in smooth, rolling noise. Disable this (`noeased`) for sharp-looking noise. -If no flags are specified (or defaults is), 2D noise is eased and 3D noise is not eased. +Maps noise gradient values onto a quintic S-curve before performing +interpolation. This results in smooth, rolling noise. +Disable this (`noeased`) for sharp-looking noise. +If no flags are specified (or defaults is), 2D noise is eased and 3D noise is +not eased. #### `absvalue` Accumulates the absolute value of each noise gradient result. @@ -1032,9 +1206,9 @@ All default ores are of the uniformly-distributed scatter type. ### `scatter` Randomly chooses a location and generates a cluster of ore. -If `noise_params` is specified, the ore will be placed if the 3D perlin noise at -that point is greater than the `noise_threshold`, giving the ability to create -a non-equal distribution of ore. +If `noise_params` is specified, the ore will be placed if the 3D perlin noise +at that point is greater than the `noise_threshold`, giving the ability to +create a non-equal distribution of ore. ### `sheet` Creates a sheet of ore in a blob shape according to the 2D perlin noise @@ -1045,56 +1219,91 @@ This sheet consists of vertical columns of uniform randomly distributed height, varying between the inclusive range `column_height_min` and `column_height_max`. If `column_height_min` is not specified, this parameter defaults to 1. If `column_height_max` is not specified, this parameter defaults to `clust_size` -for reverse compatibility. New code should prefer `column_height_max`. +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, -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. +The `column_midpoint_factor` parameter controls the position of the column at +which 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. -The ore parameters `clust_scarcity` and `clust_num_ores` are ignored for this ore type. +The ore parameters `clust_scarcity` and `clust_num_ores` are ignored for this +ore type. ### `puff` Creates a sheet of ore in a cloud-like puff shape. As with the `sheet` ore type, the size and shape of puffs are described by -`noise_params` and `noise_threshold` and are placed at random vertical positions -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. +`noise_params` and `noise_threshold` and are placed at random vertical +positions 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 +`noise_params`. The maximum size of the blob is `clust_size`, and `clust_scarcity` has the same meaning as with the `scatter` type. ### `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". @@ -1103,15 +1312,16 @@ Currently supported flags: `puff_cliffs`, `puff_additive_composition`. ### `puff_cliffs` -If set, puff ore generation will not taper down large differences in displacement -when approaching the edge of a puff. This flag has no effect for ore types other -than `puff`. +If set, puff ore generation will not taper down large differences in +displacement when approaching the edge of a puff. This flag has no effect for +ore types other than `puff`. ### `puff_additive_composition` -By default, when noise described by `np_puff_top` or `np_puff_bottom` results in a -negative displacement, the sub-column at that point is not generated. With this -attribute set, puff ore generation will instead generate the absolute difference in -noise displacement values. This flag has no effect for ore types other than `puff`. +By default, when noise described by `np_puff_top` or `np_puff_bottom` results +in a negative displacement, the sub-column at that point is not generated. With +this attribute set, puff ore generation will instead generate the absolute +difference in noise displacement values. This flag has no effect for ore types +other than `puff`. Decoration types ---------------- @@ -1138,22 +1348,28 @@ A schematic specifier identifies a schematic by either a filename to a Minetest Schematic file (`.mts`) or through raw data supplied through Lua, 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) +* 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 + 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: -* A probability value of `0` or `1` means that node will never appear (0% chance). -* A probability value of `254` or `255` means the node will always appear (100% chance). +* A probability value of `0` or `1` means that node will never appear + (0% chance). +* A probability value of `254` or `255` means the node will always appear + (100% chance). * If the probability value `p` is greater than `1`, then there is a `(p / 256 * 100)` percent chance that node will appear when the schematic is placed on the map. @@ -1169,15 +1385,16 @@ Currently supported flags: `place_center_x`, `place_center_y`, `place_center_z`, * `place_center_x`: Placement of this decoration is centered along the X axis. * `place_center_y`: Placement of this decoration is centered along the Y axis. * `place_center_z`: Placement of this decoration is centered along the Z axis. -* `force_placement`: Schematic nodes other than "ignore" will replace existing nodes. +* `force_placement`: Schematic nodes other than "ignore" will replace existing + nodes. HUD element types ----------------- The position field is used for all element types. -To account for differing resolutions, the position coordinates are the percentage -of the screen, ranging in value from `0` to `1`. +To account for differing resolutions, the position coordinates are the +percentage of the screen, ranging in value from `0` to `1`. The name field is not yet used, but should contain a description of what the HUD element represents. The direction field is the direction in which something @@ -1186,20 +1403,22 @@ is drawn. `0` draws from left to right, `1` draws from right to left, `2` draws from top to bottom, and `3` draws from bottom to top. -The `alignment` field specifies how the item will be aligned. It ranges from `-1` to `1`, -with `0` being the center, `-1` is moved to the left/up, and `1` is to the right/down. -Fractional values can be used. +The `alignment` field specifies how the item will be aligned. It ranges from +`-1` to `1`, with `0` being the center. `-1` is moved to the left/up, and `1` +is to the right/down. Fractional values can be used. -The `offset` field specifies a pixel offset from the position. Contrary to position, -the offset is not scaled to screen size. This allows for some precisely-positioned -items in the HUD. +The `offset` field specifies a pixel offset from the position. Contrary to +position, the offset is not scaled to screen size. This allows for some +precisely positioned items in the HUD. -**Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling factor! +**Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling +factor! -Below are the specific uses for fields in each type; fields not listed for that type are ignored. +Below are the specific uses for fields in each type; fields not listed for that +type are ignored. -**Note**: Future revisions to the HUD API may be incompatible; the HUD API is still -in the experimental stages. +**Note**: Future revisions to the HUD API may be incompatible; the HUD API is +still in the experimental stages. ### `image` Displays an image on the HUD. @@ -1218,8 +1437,8 @@ Displays text on the HUD. * `scale`: Defines the bounding rectangle of the text. A value such as `{x=100, y=100}` should work. * `text`: The text to be displayed in the HUD element. -* `number`: An integer containing the RGB value of the color used to draw the text. - Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on. +* `number`: An integer containing the RGB value of the color used to draw the + text. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on. * `alignment`: The alignment of the text. * `offset`: offset in pixels from position. @@ -1231,7 +1450,8 @@ Displays a horizontal bar made up of half-images. If odd, will end with a vertically center-split texture. * `direction` * `offset`: offset in pixels from position. -* `size`: If used, will force full-image size to this value (override texture pack image size) +* `size`: If used, will force full-image size to this value (override texture + pack image size) ### `inventory` * `text`: The name of the inventory list to be displayed. @@ -1245,7 +1465,8 @@ Displays distance to selected world position. * `name`: The name of the waypoint. * `text`: Distance suffix. Can be blank. -* `number:` An integer containing the RGB value of the color used to draw the text. +* `number:` An integer containing the RGB value of the color used to draw the + text. * `world_pos`: World position of the waypoint. Representations of simple things @@ -1264,8 +1485,8 @@ For helper functions see "Vector helpers". Flag Specifier Format --------------------- -Flags using the standardized flag specifier format can be specified in either of -two ways, by string or table. +Flags using the standardized flag specifier format can be specified in either +of two ways, by string or table. The string format is a comma-delimited set of flag names; whitespace and unrecognized flag fields are ignored. Specifying a flag in the string sets the @@ -1448,7 +1669,7 @@ Another example: Make red wool from white wool and red dye: * `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. - Only use `slippery = 3` for now to ensure forwards compatibility. + Slipperiness rises steadily with `slippery` value, starting at 1. ### Known damage and digging time defining groups @@ -1614,7 +1835,7 @@ a non-tool item, so that it can do something else than take damage. On the Lua side, every punch calls: - entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction, damage) + entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction, damage) This should never be called directly, because damage is usually not handled by the entity itself. @@ -1626,17 +1847,17 @@ 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: - object:punch(puncher, time_from_last_punch, tool_capabilities, direction) + object:punch(puncher, time_from_last_punch, tool_capabilities, direction) * Return value is tool wear. * Parameters are equal to the above callback. -* If `direction` equals `nil` and `puncher` does not equal `nil`, - `direction` will be automatically filled in based on the location of `puncher`. +* If `direction` equals `nil` and `puncher` does not equal `nil`, `direction` + will be automatically filled in based on the location of `puncher`. Node Metadata ------------- @@ -1690,10 +1911,11 @@ Item metadata only contains a key-value store. Some of the values in the key-value store are handled specially: -* `description`: Set the item stack's description. Defaults to `idef.description` +* `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: @@ -1741,23 +1963,36 @@ 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) +* Start of a container block, moves all physical elements in the container by + (X, Y). * Must have matching `container_end` * Containers can be nested, in which case the offsets are added (child containers are relative to parent containers) #### `container_end[]` -* End of a container, following elements are no longer relative to this container +* End of a container, following elements are no longer relative to this + container. #### `list[;;,;,;]` * Show an inventory list @@ -1807,7 +2042,8 @@ examples. #### `bgcolor[;]` * Sets background color of formspec as `ColorString` -* If `true`, the background color is drawn fullscreen (does not effect the size of the formspec) +* If `true`, the background color is drawn fullscreen (does not effect the size + of the formspec). #### `background[,;,;]` * Use a background. Inventory rectangles are not drawn then. @@ -1825,8 +2061,8 @@ examples. #### `pwdfield[,;,;;