X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=doc%2Flua_api.txt;h=a07356d00ad8a3012f8e4be45b72346991069c1a;hb=faa358e797128ab07bb5644ce305a832d59e5596;hp=da4655682c1436f8e15a07fcaeb8ee4d0a614e41;hpb=4c0d4e4105d2f2e63b9a43bb83fecf92288f63b3;p=oweals%2Fminetest.git diff --git a/doc/lua_api.txt b/doc/lua_api.txt index da4655682..a07356d00 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1,10 +1,13 @@ Minetest Lua Modding API Reference ================================== + * More information at * Developer Wiki: + Introduction ------------- +============ + Content and functionality can be added to Minetest using Lua scripting in run-time loaded mods. @@ -19,60 +22,63 @@ functionality in the engine and API, and to document it here. Programming in Lua ------------------ + If you have any difficulty in understanding this, please read [Programming in Lua](http://www.lua.org/pil/). Startup ------- + Mods are loaded during server startup from the mod load paths by running the `init.lua` scripts in a shared environment. Paths ----- + * `RUN_IN_PLACE=1` (Windows release, local build) - * `$path_user`: - * Linux: `` - * Windows: `` - * `$path_share` - * Linux: `` - * Windows: `` + * `$path_user`: `` + * `$path_share`: `` * `RUN_IN_PLACE=0`: (Linux release) - * `$path_share` + * `$path_share`: * Linux: `/usr/share/minetest` * Windows: `/minetest-0.4.x` * `$path_user`: * Linux: `$HOME/.minetest` * Windows: `C:/users//AppData/minetest` (maybe) + + + Games ------ +===== + Games are looked up from: - * `$path_share/games/gameid/` - * `$path_user/games/gameid/` -Where `gameid` is unique to each game. + +* `$path_share/games//` +* `$path_user/games//` + +Where `` 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 + +* `game.conf`, with the following keys: + * `name`: Required, human readable name e.g. `name = Minetest` + * `description`: Short description to be shown in the content tab + * `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. @@ -83,75 +89,89 @@ 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 -------------- -Generic: -* `$path_share/games/gameid/mods/` -* `$path_share/mods/` -* `$path_user/games/gameid/mods/` -* `$path_user/mods/` (User-installed mods) -* `$worldpath/worldmods/` -In a run-in-place version (e.g. the distributed windows version): -* `minetest-0.4.x/games/gameid/mods/` -* `minetest-0.4.x/mods/` (User-installed mods) -* `minetest-0.4.x/worlds/worldname/worldmods/` +Mods +==== -On an installed version on Linux: +Mod load path +------------- -* `/usr/share/minetest/games/gameid/mods/` -* `$HOME/.minetest/mods/` (User-installed mods) -* `$HOME/.minetest/worlds/worldname/worldmods` +Paths are relative to the directories listed in the [Paths] section above. -Mod load path for world-specific games --------------------------------------- -It is possible to include a game in a world; in this case, no mods or -games are loaded or checked from anywhere else. +* `games//mods/` +* `mods/` +* `worlds//worldmods/` -This is useful for e.g. adventure worlds. +World-specific games +-------------------- -This happens if the following directory exists: +It is possible to include a game in a world; in this case, no mods or +games are loaded or checked from anywhere else. - $world/game/ +This is useful for e.g. adventure worlds and happens if the `/game/` +directory exists. -Mods should be then be placed in: +Mods should then be placed in `/game/mods/`. - $world/game/mods/ +Modpacks +-------- -Modpack support ----------------- Mods can be put in a subdirectory, if the parent directory, which otherwise should be a mod, contains a file named `modpack.txt`. This file shall be empty, except for lines starting with `#`, which are comments. Mod directory structure ------------------------- +----------------------- mods - |-- modname - | |-- depends.txt - | |-- screenshot.png - | |-- description.txt - | |-- settingtypes.txt - | |-- init.lua - | |-- models - | |-- textures - | | |-- modname_stuff.png - | | `-- modname_something_else.png - | |-- sounds - | |-- media - | |-- locale - | `-- - `-- another - + ├── modname + │   ├── mod.conf + │   ├── screenshot.png + │   ├── settingtypes.txt + │   ├── init.lua + │   ├── models + │   ├── textures + │   │   ├── modname_stuff.png + │   │   └── modname_something_else.png + │   ├── sounds + │   ├── media + │   ├── locale + │   └── + └── another ### modname + The location of this directory can be fetched by using `minetest.get_modpath(modname)`. +### mod.conf + +A key-value store of mod details. + +* `name`: The mod name. Allows Minetest to determine the mod name even if the + folder is wrongly named. +* `description`: Description of mod to be shown in the Mods tab of the main + menu. +* `depends`: A comma separated list of dependencies. These are mods that must be + loaded before this mod. +* `optional_depends`: A comma separated list of optional dependencies. + Like a dependency, but no error if the mod doesn't exist. + +Note: to support 0.4.x, please also provide depends.txt. + +### `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. + ### `depends.txt` + +**Deprecated:** you should use mod.conf instead. + +This file is used if there are no dependencies in mod.conf. + List of mods that have to be loaded before loading this mod. A single line contains a single modname. @@ -160,40 +180,47 @@ Optional dependencies can be defined by appending a question mark 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 a description to be shown in the Mods tab of the mainmenu. + +**Deprecated:** you should use mod.conf instead. + +This file is used if there is no description in mod.conf. + +A file containing a description to be shown in the Mods tab of the main menu. ### `settingtypes.txt` + A file in the same format as the one in builtin. It will be parsed by the settings menu and the settings will be displayed in the "Mods" category. ### `init.lua` + The main Lua script. Running this script should register everything it wants to register. Subsequent execution depends on minetest calling the registered callbacks. `minetest.settings` can be used to read custom or existing settings at load -time, if necessary. (See `Settings`) +time, if necessary. (See [`Settings`]) ### `models` + Models for entities or meshnodes. ### `textures`, `sounds`, `media` + 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 ----------------------------------------------- +Translation files for the clients. (See [Translations]) + +Naming conventions +------------------ + Registered names should generally be in this format: - `modname:` + modname: `` can have these characters: @@ -202,24 +229,29 @@ Registered names should generally be in this format: This is to prevent conflicting names from corrupting maps and is enforced by the mod loader. +Registered names can be overridden by prefixing the name with `:`. This can +be used for overriding the registrations of some other mod. + +The `:` prefix can also be used for maintaining backwards compatibility. + ### Example + In the mod `experimental`, there is the ideal item/node/entity name `tnt`. So the name should be `experimental:tnt`. -Enforcement can be overridden by prefixing the name with `:`. This can -be used for overriding the registrations of some other mod. - -Example: Any mod can redefine `experimental:tnt` by using the name +Any mod can redefine `experimental:tnt` by using the name :experimental:tnt -when registering it. -(also that mod is required to have `experimental` as a dependency) +when registering it. That mod is required to have `experimental` as a +dependency. + + -The `:` prefix can also be used for maintaining backwards compatibility. Aliases -------- +======= + Aliases can be added by using `minetest.register_alias(name, convert_to)` or `minetest.register_alias_force(name, convert_to)`. @@ -241,75 +273,88 @@ 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 +### Aliases needed for all mapgens except Mapgen V6 + +#### Base terrain -Base terrain: +* mapgen_stone +* mapgen_water_source +* mapgen_river_water_source -"mapgen_stone" -"mapgen_water_source" -"mapgen_river_water_source" +#### Caves -Caves: +Not required if cave liquid nodes are set in biome definitions. -"mapgen_lava_source" +* mapgen_lava_source -Dungeons: +#### 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" +Not required if dungeon nodes are set in biome definitions. -### Aliases needed for Mapgen v6 +* mapgen_cobble +* mapgen_stair_cobble +* mapgen_mossycobble +* mapgen_desert_stone +* mapgen_stair_desert_stone +* mapgen_sandstone +* mapgen_sandstonebrick +* mapgen_stair_sandstone_block -Terrain and biomes: +### Aliases needed for Mapgen V6 -"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" +#### Terrain and biomes -Flora: +* 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 + +### Setting the node used in Mapgen Singlenode + +By default the world is filled with air nodes. To set a different node use, for +example: + + minetest.register_alias("mapgen_singlenode", "default:stone") -"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 the mod name `foomod`, a texture could be called: @@ -323,10 +368,12 @@ stripping out the file extension: Texture modifiers ----------------- + There are various texture modifiers that can be used to generate textures on-the-fly. ### Texture overlaying + Textures can be overlaid by putting a `^` between them. Example: @@ -338,6 +385,7 @@ The texture with the lower resolution will be automatically upscaled to the higher resolution texture. ### Texture grouping + Textures can be grouped together by enclosing them in `(` and `)`. Example: `cobble.png^(thing1.png^thing2.png)` @@ -346,6 +394,7 @@ A texture for `thing1.png^thing2.png` is created and the resulting texture is overlaid on top of `cobble.png`. ### Escaping + Modifiers that accept texture names (e.g. `[combine`) accept escaping to allow passing complex texture names as arguments. Escaping is done with backslash and is required for `^` and `:`. @@ -358,29 +407,33 @@ on top of `cobble.png`. ### Advanced texture modifiers #### Crack + * `[crack::

` * `[cracko::

` * `[crack:::

` * `[cracko:::

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

` = current animation frame + +* ``: 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. +`crack` draws it normally, while `cracko` lays it over, keeping transparent +pixels intact. Example: default_cobble.png^[crack:10:1 #### `[combine:x:,=:,=:...` -* `` = width -* `` = height -* `` = x position -* `` = y position -* `` = texture to combine + +* ``: width +* ``: height +* ``: x position +* ``: y position +* ``: texture to combine Creates a texture of size `` times `` and blits the listed files to their specified coordinates. @@ -390,6 +443,7 @@ Example: [combine:16x32:0,0=default_cobble.png:0,16=default_wood.png #### `[resize:x` + Resizes the texture to the given dimensions. Example: @@ -397,16 +451,17 @@ Example: default_sandstone.png^[resize:16x16 #### `[opacity:` + Makes the base image transparent according to the given ratio. -`r` must be between 0 and 255. -0 means totally transparent. 255 means totally opaque. +`r` must be between 0 (transparent) and 255 (opaque). Example: default_sandstone.png^[opacity:127 #### `[invert:` + Inverts the given channels of the base image. Mode may contain the characters "r", "g", "b", "a". Only the channels that are mentioned in the mode string will be inverted. @@ -416,6 +471,7 @@ Example: default_apple.png^[invert:rgb #### `[brighten` + Brightens the texture. Example: @@ -423,6 +479,7 @@ Example: tnt_tnt_side.png^[brighten #### `[noalpha` + Makes the texture completely opaque. Example: @@ -430,6 +487,7 @@ Example: default_leaves.png^[noalpha #### `[makealpha:,,` + Convert one color to transparency. Example: @@ -437,7 +495,8 @@ Example: default_cobble.png^[makealpha:128,128,128 #### `[transform` -* `` = transformation(s) to apply + +* ``: transformation(s) to apply Rotates and/or flips the image. @@ -458,7 +517,9 @@ 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. @@ -470,6 +531,7 @@ Creates an inventorycube with `grass.png`, `dirt.png^grass_side.png` and `dirt.png^grass_side.png` textures #### `[lowpart::` + Blit the lower ``% part of `` on the texture. Example: @@ -477,8 +539,9 @@ Example: base.png^[lowpart:25:overlay.png #### `[verticalframe::` -* `` = animation frame count -* `` = current animation frame + +* ``: animation frame count +* ``: current animation frame Crops the texture to a frame of a vertical animation. @@ -487,16 +550,18 @@ Example: default_torch_animated.png^[verticalframe:16:8 #### `[mask:` + Apply a mask to the base image. The mask is applied using binary AND. #### `[sheet:x:,` + Retrieves a tile at position x,y from the base image which it assumes to be a tilesheet with dimensions w,h. - #### `[colorize::` + Colorize the textures with the given color. `` is specified as a `ColorString`. `` is an int ranging from 0 to 255 or the word "`alpha`". If @@ -508,14 +573,16 @@ the word "`alpha`", then each texture pixel will contain the RGB of texture pixel. #### `[multiply:` + 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 ----------------- + The goal of hardware coloring is to simplify the creation of colorful nodes. If your textures use the same pattern, and they only differ in their color (like colored wool blocks), you can use hardware @@ -524,30 +591,35 @@ All of these methods use color multiplication (so a white-black texture with red coloring will result in red-black color). ### Static coloring + This method is useful if you wish to create nodes/items with the same texture, in different colors, each in a new node/item definition. #### Global color + When you register an item or node, set its `color` field (which accepts a `ColorSpec`) to the desired color. -An `ItemStack`s static color can be overwritten by the `color` metadata +An `ItemStack`'s static color can be overwritten by the `color` metadata field. If you set that field to a `ColorString`, that color will be used. #### Tile color + Each tile may have an individual static color, which overwrites every -other coloring methods. To disable the coloring of a face, +other coloring method. To disable the coloring of a face, set its color to white (because multiplying with white does nothing). You can set the `color` property of the tiles in the node's definition if the tile is in table format. ### Palettes + For nodes and items which can have many colors, a palette is more suitable. A palette is a texture, which can contain up to 256 pixels. Each pixel is one possible color for the node/item. You can register one node/item, which can have up to 256 colors. #### Palette indexing + When using palettes, you always provide a pixel index for the given node or `ItemStack`. The palette is read from left to right and from top to bottom. If the palette has less than 256 pixels, then it is @@ -555,18 +627,20 @@ 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 * 16x16 palette, index = 255: the bottom right corner -* 2 (width)x4 (height) palette, index=31: the top left corner. +* 2 (width) x 4 (height) palette, index = 31: the top left corner. The palette has 8 pixels, so each pixel is stretched to 32 pixels, to ensure the total 256 pixels. -* 2x4 palette, index=32: the top right corner -* 2x4 palette, index=63: the top right corner -* 2x4 palette, index=64: the pixel below the top left corner +* 2x4 palette, index = 32: the top right corner +* 2x4 palette, index = 63: the top right corner +* 2x4 palette, index = 64: the pixel below the top left corner #### Using palettes with items + When registering an item, set the item definition's `palette` field to a texture. You can also use texture modifiers. @@ -575,17 +649,19 @@ stack's metadata. `palette_index` is an integer, which specifies the index of the pixel to use. #### Linking palettes with nodes + 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: @@ -593,9 +669,9 @@ appropriate `drawtype`: 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 +* `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. @@ -606,9 +682,10 @@ appropriate `drawtype`: 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 on the map -### Conversion between nodes in the inventory and the on the map Static coloring is the same for both cases, there is no need for conversion. @@ -621,6 +698,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", { @@ -637,6 +715,7 @@ Example: }) ### Colored items in craft recipes + Craft recipes only support item strings, but fortunately item strings can also contain metadata. Example craft recipe registration: @@ -656,6 +735,7 @@ so the craft output is independent of the color of the ingredients. Soft texture overlay -------------------- + Sometimes hardware coloring is not enough, because it affects the whole tile. Soft texture overlays were added to Minetest to allow the dynamic coloring of only specific parts of the node's texture. @@ -696,8 +776,12 @@ Example (colored grass block): palette = "default_foilage.png", }) + + + Sounds ------- +====== + Only Ogg Vorbis files are supported. For positional playing of sounds, only single-channel (mono) files are @@ -725,41 +809,43 @@ Examples of sound parameter tables: -- Play locationless on all clients { - gain = 1.0, -- default - fade = 0.0, -- default, change to a value > 0 to fade the sound in - pitch = 1.0, -- default + gain = 1.0, -- default + fade = 0.0, -- default, change to a value > 0 to fade the sound in + pitch = 1.0, -- default } -- Play locationless to one player { to_player = name, - gain = 1.0, -- default - fade = 0.0, -- default, change to a value > 0 to fade the sound in - pitch = 1.0, -- default + gain = 1.0, -- default + fade = 0.0, -- default, change to a value > 0 to fade the sound in + pitch = 1.0, -- default } -- Play locationless to one player, looped { to_player = name, - gain = 1.0, -- default + gain = 1.0, -- default loop = true, } -- Play in a location { pos = {x = 1, y = 2, z = 3}, - gain = 1.0, -- default - max_hear_distance = 32, -- default, uses an euclidean metric + gain = 1.0, -- default + max_hear_distance = 32, -- default, uses an euclidean metric } -- Play connected to an object, looped { object = , - gain = 1.0, -- default - max_hear_distance = 32, -- default, uses an euclidean metric + gain = 1.0, -- default + max_hear_distance = 32, -- default, uses an euclidean metric loop = true, } Looped sounds must either be connected to an object or played locationless to one player using `to_player = name,` -### `SimpleSoundSpec` +`SimpleSoundSpec` +----------------- + * e.g. `""` * e.g. `"default_place_node"` * e.g. `{}` @@ -767,12 +853,16 @@ one player using `to_player = name,` * e.g. `{name = "default_place_node", gain = 1.0}` * e.g. `{name = "default_place_node", gain = 1.0, pitch = 1.0}` -Registered definitions of stuff -------------------------------- -Anything added using certain `minetest.register_*` functions get added to + + + +Registered definitions +====================== + +Anything added using certain `minetest.register_*` functions gets added to the global `minetest.registered_*` tables. -* `minetest.register_entity(name, prototype table)` +* `minetest.register_entity(name, entity definition)` * added to `minetest.registered_entities[name]` * `minetest.register_node(name, node definition)` @@ -787,8 +877,8 @@ the global `minetest.registered_*` tables. * `minetest.unregister_item(name)` * Unregisters the item name from engine, and deletes the entry with key - * `name` from `minetest.registered_items` and from the associated item - * table according to its nature: `minetest.registered_nodes[]` etc + `name` from `minetest.registered_items` and from the associated item + table according to its nature: `minetest.registered_nodes[]` etc * `minetest.register_biome(biome definition)` * returns an integer uniquely identifying the registered biome @@ -797,7 +887,7 @@ the global `minetest.registered_*` tables. * `minetest.unregister_biome(name)` * Unregisters the biome name from engine, and deletes the entry with key - * `name` from `minetest.registered_biome` + `name` from `minetest.registered_biome` * `minetest.register_ore(ore definition)` * returns an integer uniquely identifying the registered ore @@ -806,16 +896,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 @@ -843,27 +936,21 @@ Example: If you want to check the drawtype of a node, you could do: end local drawtype = get_nodedef_field(nodename, "drawtype") -Example: `minetest.get_item_group(name, group)` has been implemented as: - function minetest.get_item_group(name, group) - if not minetest.registered_items[name] or not - minetest.registered_items[name].groups[group] then - return 0 - end - return minetest.registered_items[name].groups[group] - end + Nodes ------ +===== + Nodes are the bulk data of the world: cubes and other things that take the space of a cube. Huge amounts of them are handled efficiently, but they are quite static. -The definition of a node is stored and can be accessed by name in +The definition of a node is stored and can be accessed by using minetest.registered_nodes[node.name] -See "Registered definitions of stuff". +See [Registered definitions]. Nodes are passed by value between Lua and the engine. They are represented by a table: @@ -874,119 +961,196 @@ They are represented by a table: them for certain automated functions. If you don't use these functions, you can use them to store arbitrary values. +Node paramtypes +--------------- + The functions of `param1` and `param2` are determined by certain fields in the -node definition: +node definition. `param1` is reserved for the engine when `paramtype != "none"`: - paramtype = "light" - ^ The value stores light with and without sun in its upper and lower 4 bits - respectively. Allows light to propagate from or through the node with - light value falling by 1 per node. This is essential for a light source - node to spread its light. +* `paramtype = "light"` + * The value stores light with and without sun in its upper and lower 4 bits + respectively. + * Required by a light source node to enable spreading its light. + * Required by the following drawtypes as they determine their visual + brightness from their internal light value: + * torchlike + * signlike + * firelike + * fencelike + * raillike + * nodebox + * mesh + * plantlike + * plantlike_rooted `param2` is reserved for the engine when any of these are used: - liquidtype == "flowing" - ^ The level and some flags of the liquid is stored in param2 - drawtype == "flowingliquid" - ^ The drawn liquid level is read from param2 - drawtype == "torchlike" - drawtype == "signlike" - paramtype2 == "wallmounted" - ^ The rotation of the node is stored in param2. You can make this value - by using minetest.dir_to_wallmounted(). - paramtype2 == "facedir" - ^ The rotation of the node is stored in param2. Furnaces and chests are - rotated this way. Can be made by using minetest.dir_to_facedir(). - Values range 0 - 23 - facedir / 4 = axis direction: - 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 - get the actual rotation 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: - 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 - 3 = a "#" shaped plant with 4 faces instead of 2 - 4 = a "#" shaped plant with 4 faces that lean outwards - 5-7 are unused and reserved for future meshes. - Bits 3 through 7 are optional flags that can be combined and give these +* `liquidtype = "flowing"` + * The level and some flags of the liquid is stored in `param2` +* `drawtype = "flowingliquid"` + * The drawn liquid level is read from `param2` +* `drawtype = "torchlike"` +* `drawtype = "signlike"` +* `paramtype2 = "wallmounted"` + * The rotation of the node is stored in `param2`. You can make this value + by using `minetest.dir_to_wallmounted()`. +* `paramtype2 = "facedir"` + * The rotation of the node is stored in `param2`. Furnaces and chests are + rotated this way. Can be made by using `minetest.dir_to_facedir()`. + * Values range 0 - 23 + * facedir / 4 = axis direction: + 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"` + * 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 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: + * 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 + * 3 = a "#" shaped plant with 4 faces instead of 2 + * 4 = a "#" shaped plant with 4 faces that lean outwards + * 5-7 are unused and reserved for future meshes. + * Bits 3 through 7 are optional flags that can be combined and give these effects: - bit 3 (0x08) - Makes the plant slightly vary placement horizontally - bit 4 (0x10) - Makes the plant mesh 1.4x larger - bit 5 (0x20) - Moves each face randomly a small bit down (1/8 max) - bits 6-7 are reserved for future use. - paramtype2 == "color" - ^ `param2` tells which color is picked from the palette. + * bit 3 (0x08) - Makes the plant slightly vary placement horizontally + * bit 4 (0x10) - Makes the plant mesh 1.4x larger + * bit 5 (0x20) - Moves each face randomly a small bit down (1/8 max) + * bits 6-7 are reserved for future use. +* `paramtype2 = "color"` + * `param2` tells which color is picked from the palette. The palette should have 256 pixels. - paramtype2 == "colorfacedir" - ^ Same as `facedir`, but with colors. - The first three bits of `param2` tells which color - is picked from the palette. - The palette should have 8 pixels. - paramtype2 == "colorwallmounted" - ^ Same as `wallmounted`, but with colors. - The first five bits of `param2` tells which color - is picked from the palette. - The palette should have 32 pixels. - paramtype2 == "glasslikeliquidlevel" - ^ 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". +* `paramtype2 = "colorfacedir"` + * Same as `facedir`, but with colors. + * The first three bits of `param2` tells which color is picked from the + palette. The palette should have 8 pixels. +* `paramtype2 = "colorwallmounted"` + * Same as `wallmounted`, but with colors. + * The first five bits of `param2` tells which color is picked from the + palette. The palette should have 32 pixels. +* `paramtype2 = "glasslikeliquidlevel"` + * 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 appearance 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 -* `mesh` -- Use models for nodes, see below -* `plantlike_rooted` -- See below - -`*_optional` drawtypes need less rendering time if deactivated (always client side). + * 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` + * 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 nodes consisting of an arbitrary -number of boxes. It allows defining stuff like stairs and slabs. +Node selection boxes are defined using "node boxes". A nodebox is defined as any of: @@ -1000,9 +1164,9 @@ A nodebox is defined as any of: 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. + -- 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, ...} @@ -1036,7 +1200,8 @@ A nodebox is defined as any of: 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 + disconnected_sides = box OR {box1, box2, ...} -- when there are *no* + -- neighbours to the sides } A `box` is defined as: @@ -1047,380 +1212,138 @@ A box of a regular node would look like: {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -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 ----------------- -Noise Parameters, or commonly called "`NoiseParams`", define the properties of -perlin noise. -### `offset` -Offset that the noise is translated by (i.e. added) after calculation. +HUD +=== -### `scale` -Factor that the noise is scaled by (i.e. multiplied) after calculation. +HUD element types +----------------- -### `spread` -Vector containing values by which each coordinate is divided by before calculation. -Higher spread values result in larger noise features. +The position field is used for all element types. -A value of `{x=250, y=250, z=250}` is common. +To account for differing resolutions, the position coordinates are the +percentage of the screen, ranging in value from `0` to `1`. -### `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. +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 +is drawn. -### `octaves` -Number of times the noise gradient is accumulated into the noise. +`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. -Increase this number to increase the amount of detail in the resulting noise. +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. -A value of `6` is common. +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. -### `persistence` -Factor by which the effect of the noise gradient function changes with each successive octave. +**Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling +factor! -Values less than `1` make the details of successive octaves' noise diminish, while values -greater than `1` make successive octaves stronger. +Below are the specific uses for fields in each type; fields not listed for that +type are ignored. -A value of `0.6` is common. +### `image` +Displays an image on the HUD. -### `lacunarity` -Factor by which the noise feature sizes change with each successive octave. +* `scale`: The scale of the image, with 1 being the original texture size. + Only the X coordinate scale is used (positive values). + Negative values represent that percentage of the screen it + should take; e.g. `x=-100` means 100% (width). +* `text`: The name of the texture that is displayed. +* `alignment`: The alignment of the image. +* `offset`: offset in pixels from position. -A value of `2.0` is common. +### `text` -### `flags` -Leave this field unset for no special handling. +Displays text on the HUD. -Currently supported are `defaults`, `eased` and `absvalue`. +* `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. +* `alignment`: The alignment of the text. +* `offset`: offset in pixels from position. -#### `defaults` -Specify this if you would like to keep auto-selection of eased/not-eased while specifying -some other flags. +### `statbar` -#### `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. +Displays a horizontal bar made up of half-images. -#### `absvalue` -Accumulates the absolute value of each noise gradient result. +* `text`: The name of the texture that is used. +* `number`: The number of half-textures that are displayed. + 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) -Noise parameters format example for 2D or 3D perlin noise or perlin noise maps: +### `inventory` - np_terrain = { - offset = 0, - scale = 1, - spread = {x=500, y=500, z=500}, - seed = 571347, - octaves = 5, - persist = 0.63, - lacunarity = 2.0, - flags = "defaults, absvalue" - } - ^ A single noise parameter table can be used to get 2D or 3D noise, - when getting 2D noise spread.z is ignored. +* `text`: The name of the inventory list to be displayed. +* `number`: Number of items in the inventory to be displayed. +* `item`: Position of item that is selected. +* `direction` +* `offset`: offset in pixels from position. +### `waypoint` -Ore types ---------- -These tell in what manner the ore is generated. +Displays distance to selected world position. -All default ores are of the uniformly-distributed scatter type. +* `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. +* `world_pos`: World position of the waypoint. -### `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. -### `sheet` -Creates a sheet of ore in a blob shape according to the 2D perlin noise -described by `noise_params` and `noise_threshold`. This is essentially an -improved version of the so-called "stratus" ore seen in some unofficial mods. -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`. +Representations of simple things +================================ -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. +Position/vector +--------------- -The ore parameters `clust_scarcity` and `clust_num_ores` are ignored for this ore type. + {x=num, y=num, z=num} -### `puff` -Creates a sheet of ore in a cloud-like puff shape. +For helper functions see [Spatial Vectors]. -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. +`pointed_thing` +--------------- -The vertical top and bottom displacement of each puff are determined by the noise -parameters `np_puff_top` and `np_puff_bottom`, respectively. +* `{type="nothing"}` +* `{type="node", under=pos, above=pos}` +* `{type="object", ref=ObjectRef}` -### `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 -`clust_scarcity` has the same meaning as with the `scatter` type. +Exact pointing location (currently only `Raycast` supports these fields): +* `pointed_thing.intersection_point`: The absolute world coordinates of the + point on the selection box which is pointed at. May be in the selection box + if the pointer is in the box too. +* `pointed_thing.box_id`: The ID of the pointed selection box (counting starts + from 1). +* `pointed_thing.intersection_normal`: Unit vector, points outwards of the + selected selection box. This specifies which face is pointed at. + Is a null vector `{x = 0, y = 0, z = 0}` when the pointer is inside the + selection box. -### `vein` -Creates veins of ore varying in density by according to the intersection of two -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: +Flag Specifier Format +===================== - 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 +Flags using the standardized flag specifier format can be specified in either +of two ways, by string or table. -**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". - -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`. - -### `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`. - -Decoration types ----------------- -The varying types of decorations that can be placed. - -### `simple` -Creates a 1 times `H` times 1 column of a specified node (or a random node from -a list, if a decoration list is specified). Can specify a certain node it must -spawn next to, such as water or lava, for example. Can also generate a -decoration of random height between a specified lower and upper bound. -This type of decoration is intended for placement of grass, flowers, cacti, -papyri, waterlilies and so on. - -### `schematic` -Copies a box of `MapNodes` from a specified schematic file (or raw description). -Can specify a probability of a node randomly appearing when placed. -This decoration type is intended to be used for multi-node sized discrete -structures, such as trees, cave spikes, rocks, and so on. - - -Schematic specifier --------------------- -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 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) - -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). -* 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. - - -Schematic attributes --------------------- -See section "Flag Specifier Format". - -Currently supported flags: `place_center_x`, `place_center_y`, `place_center_z`, - `force_placement`. - -* `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. - - -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`. - -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 -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 `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! - -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. - -### `image` -Displays an image on the HUD. - -* `scale`: The scale of the image, with 1 being the original texture size. - Only the X coordinate scale is used (positive values). - Negative values represent that percentage of the screen it - should take; e.g. `x=-100` means 100% (width). -* `text`: The name of the texture that is displayed. -* `alignment`: The alignment of the image. -* `offset`: offset in pixels from position. - -### `text` -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. -* `alignment`: The alignment of the text. -* `offset`: offset in pixels from position. - -### `statbar` -Displays a horizontal bar made up of half-images. - -* `text`: The name of the texture that is used. -* `number`: The number of half-textures that are displayed. - 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) - -### `inventory` -* `text`: The name of the inventory list to be displayed. -* `number`: Number of items in the inventory to be displayed. -* `item`: Position of item that is selected. -* `direction` -* `offset`: offset in pixels from position. - -### `waypoint` -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. -* `world_pos`: World position of the waypoint. - -Representations of simple things --------------------------------- - -### Position/vector - - {x=num, y=num, z=num} - -For helper functions see "Vector helpers". - -### `pointed_thing` -* `{type="nothing"}` -* `{type="node", under=pos, above=pos}` -* `{type="object", ref=ObjectRef}` - -Flag Specifier Format ---------------------- -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 -flag, and specifying a flag prefixed by the string `"no"` explicitly -clears the flag from whatever the default may be. +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 +flag, and specifying a flag prefixed by the string `"no"` explicitly +clears the flag from whatever the default may be. In addition to the standard string flag format, the schematic flags field can also be a table of flag names to boolean values representing whether or not the @@ -1445,31 +1368,44 @@ or even since, by default, no schematic attributes are set. + + + Items ------ +===== + +Item types +---------- -### Item types There are three kinds of items: nodes, tools and craftitems. -* Node (`register_node`): A node from the world. -* Tool (`register_tool`): A tool/weapon that can dig and damage - things according to `tool_capabilities`. -* Craftitem (`register_craftitem`): A miscellaneous item. +* Node: Can be placed in the world's voxel grid +* Tool: Has a wear property but cannot be stacked. The default use action is to + dig nodes or hit objects according to its tool capabilities. +* Craftitem: Cannot dig nodes or be placed + +Amount and wear +--------------- -### Amount and wear -All item stacks have an amount between 0 to 65535. It is 1 by +All item stacks have an amount between 0 and 65535. It is 1 by default. Tool item stacks can not have an amount greater than 1. -Tools use a wear (=damage) value ranging from 0 to 65535. The -value 0 is the default and used is for unworn tools. The values +Tools use a wear (damage) value ranging from 0 to 65535. The +value 0 is the default and is used for unworn tools. The values 1 to 65535 are used for worn tools, where a higher value stands for a higher wear. Non-tools always have a wear value of 0. -### Item formats +Item formats +------------ + Items and item stacks can exist in three formats: Serializes, table format and `ItemStack`. -#### Serialized +When an item must be passed to a function, it can usually be in any of +these formats. + +### Serialized + This is called "stackstring" or "itemstring". It is a simple string with 1-3 components: the full item identifier, an optional amount and an optional wear value. Syntax: @@ -1483,7 +1419,8 @@ Examples: * `'default:pick_stone'`: a new stone pickaxe * `'default:pick_wood 1 21323'`: a wooden pickaxe, ca. 1/3 worn out -#### Table format +### Table format + Examples: 5 dirt nodes: @@ -1498,30 +1435,33 @@ An apple: {name="default:apple", count=1, wear=0, metadata=""} -#### `ItemStack` +### `ItemStack` + A native C++ format with many helper methods. Useful for converting -between formats. See the Class reference section for details. +between formats. See the [Class reference] section for details. + -When an item must be passed to a function, it can usually be in any of -these formats. Groups ------- +====== + In a number of places, there is a group table. Groups define the properties of a thing (item, node, armor of entity, capabilities of tool) in such a way that the engine and other mods can can interact with the thing without actually knowing what the thing is. -### Usage +Usage +----- + Groups are stored in a table, having the group names with keys and the group ratings as values. For example: + -- Default dirt groups = {crumbly=3, soil=1} - -- ^ Default dirt + -- A more special dirt-kind of thing groups = {crumbly=2, soil=1, level=2, outerspace=1} - -- ^ A more special dirt-kind of thing Groups always have a rating associated with them. If there is no useful meaning for a rating for an enabled group, it shall be `1`. @@ -1533,26 +1473,36 @@ You can read the rating of a group for an item or a node by using minetest.get_item_group(itemname, groupname) -### Groups of items +Groups of items +--------------- + Groups of items can define what kind of an item it is (e.g. wool). -### Groups of nodes +Groups of nodes +--------------- + In addition to the general item things, groups are used to define whether a node is destroyable and how long it takes to destroy by a tool. -### Groups of entities +Groups of entities +------------------ + For entities, groups are, as of now, used only for calculating damage. The rating is the percentage of damage caused by tools with this damage group. -See "Entity damage mechanism". +See [Entity damage mechanism]. object.get_armor_groups() --> a group-rating table (e.g. {fleshy=100}) object.set_armor_groups({fleshy=30, cracky=80}) -### Groups of tools +Groups of tools +--------------- + Groups in tools define which groups of nodes and entities they are effective towards. -### Groups in crafting recipes +Groups in crafting recipes +-------------------------- + An example: Make meat soup from any meat, any water and any bowl: { @@ -1573,7 +1523,9 @@ Another example: Make red wool from white wool and red dye: recipe = {'wool:white', 'group:dye,basecolor_red'}, } -### Special groups +Special groups +-------------- + * `immortal`: Disables the group damage system for an entity * `punch_operable`: For entities; disables the regular damage mechanism for players punching it by hand or a non-tool item, so that it can do something @@ -1584,7 +1536,7 @@ Another example: Make red wool from white wool and red dye: from destroyed nodes. * `0` is something that is directly accessible at the start of gameplay * There is no upper limit -* `dig_immediate`: (player can always pick up node without reducing tool wear) +* `dig_immediate`: Player can always pick up node without reducing tool wear * `2`: the node always gets the digging time 0.5 seconds (rail, sign) * `3`: the node always gets the digging time 0 seconds (torch) * `disable_jump`: Player (and possibly other things) cannot jump from node @@ -1599,9 +1551,13 @@ Another example: Make red wool from white wool and red dye: connect to each other * `slippery`: Players and items will slide on the node. Slipperiness rises steadily with `slippery` value, starting at 1. +* `disable_repair`: If set to 1 for a tool, it cannot be repaired using the + `"toolrepair"` crafting recipe -### Known damage and digging time defining groups +Known damage and digging time defining groups +--------------------------------------------- + * `crumbly`: dirt, sand * `cracky`: tough but crackable stuff like stone. * `snappy`: something that can be cut using fine tools; e.g. leaves, small @@ -1617,7 +1573,9 @@ Another example: Make red wool from white wool and red dye: speed of a tool if the tool can dig at a faster speed than this suggests for the hand. -### Examples of custom groups +Examples of custom groups +------------------------- + Item groups are often used for defining, well, _groups of items_. * `meat`: any meat-kind of a thing (rating might define the size or healing @@ -1631,7 +1589,9 @@ Item groups are often used for defining, well, _groups of items_. * `weapon`: any weapon * `heavy`: anything considerably heavy -### Digging time calculation specifics +Digging time calculation specifics +---------------------------------- + Groups such as `crumbly`, `cracky` and `snappy` are used for this purpose. Rating is `1`, `2` or `3`. A higher rating for such a group implies faster digging time. @@ -1646,7 +1606,15 @@ Tools define their properties by a list of parameters for groups. They cannot dig other groups; thus it is important to use a standard bunch of groups to enable interaction with tools. -#### Tools definition + + + +Tools +===== + +Tools definition +---------------- + Tools define: * Full punch interval @@ -1657,19 +1625,22 @@ Tools define: * Digging times * Damage groups -#### Full punch interval +### Full punch interval + When used as a weapon, the tool will do full damage if this time is spent between punches. If e.g. half the time is spent, the tool will do half damage. -#### Maximum drop level +### Maximum drop level + Suggests the maximum level of node, when dug with the tool, that will drop it's useful item. (e.g. iron ore to drop a lump of iron). This is not automated; it is the responsibility of the node definition to implement this. -#### Uses +### Uses + Determines how many uses the tool has when it is used for digging a node, of this group, of the maximum level. For lower leveled nodes, the use count is multiplied by `3^leveldiff`. @@ -1678,11 +1649,13 @@ is multiplied by `3^leveldiff`. * `uses=10, leveldiff=1`: actual uses: 30 * `uses=10, leveldiff=2`: actual uses: 90 -#### Maximum level +### Maximum level + Tells what is the maximum level of a node of this group that the tool will be able to dig. -#### Digging times +### Digging times + List of digging times for different ratings of the group, for nodes of the maximum level. @@ -1695,10 +1668,12 @@ If the result digging time is 0, a delay of 0.15 seconds is added between digging nodes; If the player releases LMB after digging, this delay is set to 0, i.e. players can more quickly click the nodes away instead of holding LMB. -#### Damage groups -List of damage for groups of entities. See "Entity damage mechanism". +### Damage groups + +List of damage for groups of entities. See [Entity damage mechanism]. -#### Example definition of the capabilities of a tool +Example definition of the capabilities of a tool +------------------------------------------------ tool_capabilities = { full_punch_interval=1.5, @@ -1738,14 +1713,18 @@ Table of resulting tool uses: easy nodes to be quickly breakable. * At `level > 2`, the node is not diggable, because it's `level > maxlevel` + + + Entity damage mechanism ------------------------ +======================= + Damage calculation: damage = 0 foreach group in cap.damage_groups: - damage += cap.damage_groups[group] * limit(actual_interval / - cap.full_punch_interval, 0.0, 1.0) + damage += cap.damage_groups[group] + * limit(actual_interval / cap.full_punch_interval, 0.0, 1.0) * (object.armor_groups[group] / 100.0) -- Where object.armor_groups[group] is 0 for inexistent values return damage @@ -1764,7 +1743,8 @@ 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. @@ -1781,18 +1761,25 @@ Return value of this function will determine if damage is done by this function 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`. + + + + +Metadata +======== Node Metadata ------------- + The instance of a node in the world normally only contains the three values -mentioned in "Nodes". However, it is possible to insert extra data into a -node. It is called "node metadata"; See `NodeMetaRef`. +mentioned in [Nodes]. However, it is possible to insert extra data into a node. +It is called "node metadata"; See `NodeMetaRef`. Node metadata contains two things: @@ -1801,10 +1788,10 @@ Node metadata contains two things: Some of the values in the key-value store are handled specially: -* `formspec`: Defines a right-click inventory menu. See "Formspec". +* `formspec`: Defines a right-click inventory menu. See [Formspec]. * `infotext`: Text shown on the screen when the node is pointed at -Example stuff: +Example: local meta = minetest.get_meta(pos) meta:set_string("formspec", @@ -1834,40 +1821,58 @@ Example stuff: Item Metadata ------------- -Item stacks can store metadata too. See `ItemStackMetaRef`. + +Item stacks can store metadata too. See [`ItemStackMetaRef`]. 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. -Example stuff: +Example: local meta = stack:get_meta() meta:set_string("key", "value") print(dump(meta:to_table())) + + + Formspec --------- +======== + Formspec defines a menu. Currently not much else than inventories are supported. It is a string, with a somewhat strange format. Spaces and newlines can be inserted between the blocks, as is used in the examples. -### Examples +Position and size units are inventory slots, `X` and `Y` position the formspec +element relative to the top left of the menu or container. `W` and `H` are its +width and height values. +When displaying text which can contain formspec code, e.g. text set by a player, +use `minetest.formspec_escape`. +For coloured text you can use `minetest.colorize`. -#### Chest +WARNING: Minetest allows you to add elements to every single formspec instance +using `player:set_formspec_prepend()`, which may be the reason backgrounds are +appearing when you don't expect them to. See [`no_prepend[]`]. + +Examples +-------- + +### Chest size[8,9] list[context;main;0,0;8,4;] list[current_player;main;0,5;8,4;] -#### Furnace +### Furnace size[8,9] list[context;fuel;2,3;1,1;] @@ -1875,7 +1880,7 @@ examples. list[context;dst;5,1;2,2;] list[current_player;main;0,5;8,4;] -#### Minecraft-like player inventory +### Minecraft-like player inventory size[8,7.5] image[1,0.6;1,2;player.png] @@ -1883,25 +1888,31 @@ examples. list[current_player;craft;3,0;3,3;] list[current_player;craftpreview;7,1;1,1;] -### Elements +Elements +-------- + +### `size[,,]` -#### `size[,,]` * Define the size of the menu in inventory slots * `fixed_size`: `true`/`false` (optional) * deprecated: `invsize[,;]` -#### `position[,]` +### `position[,]` + * 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: +* 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[,]` +### `anchor[,]` + * 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: +* 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]. @@ -1909,206 +1920,233 @@ examples. * `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) +### `no_prepend[]` + +* Must be used after the `size`, `position`, and `anchor` elements (if present). +* Disables player:set_formspec_prepend() from applying to this formspec. + +### `container[,]` + +* 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 +### `container_end[]` + +* End of a container, following elements are no longer relative to this + container. + +### `list[;;,;,;]` -#### `list[;;,;,;]` * Show an inventory list -#### `list[;;,;,;]` +### `list[;;,;,;]` + * Show an inventory list -#### `listring[;]` +### `listring[;]` + * Allows to create a ring of inventory lists * Shift-clicking on items in one element of the ring will send them to the next inventory list inside the ring * The first occurrence of an element inside the ring will determine the inventory where items will be sent to -#### `listring[]` +### `listring[]` + * Shorthand for doing `listring[;]` for the last two inventory lists added by list[...] -#### `listcolors[;]` +### `listcolors[;]` + * Sets background color of slots as `ColorString` * Sets background color of slots on mouse hovering -#### `listcolors[;;]` +### `listcolors[;;]` + * Sets background color of slots as `ColorString` * Sets background color of slots on mouse hovering * Sets color of slots border -#### `listcolors[;;;;]` +### `listcolors[;;;;]` + * Sets background color of slots as `ColorString` * Sets background color of slots on mouse hovering * Sets color of slots border * Sets default background color of tooltips * Sets default font color of tooltips -#### `tooltip[;;;]` +### `tooltip[;;;]` + * Adds tooltip for an element * `` tooltip background color as `ColorString` (optional) * `` tooltip font color as `ColorString` (optional) -#### `image[,;,;]` +### `tooltip[,;,;;;]` +* Adds tooltip for an area. Other tooltips will take priority when present. +* `` tooltip background color as `ColorString` (optional) +* `` tooltip font color as `ColorString` (optional) + +### `image[,;,;]` + * Show an image -* Position and size units are inventory slots -#### `item_image[,;,;]` +### `item_image[,;,;]` + * Show an inventory image of registered item/node -* Position and size units are inventory slots -#### `bgcolor[;]` +### `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 affect the size + of the formspec). + +### `background[,;,;]` -#### `background[,;,;]` * Use a background. Inventory rectangles are not drawn then. -* Position and size units are inventory slots * Example for formspec 8x4 in 16x resolution: image shall be sized 8 times 16px times 4 times 16px. -#### `background[,;,;;]` +### `background[,;,;;]` + * Use a background. Inventory rectangles are not drawn then. -* Position and size units are inventory slots * Example for formspec 8x4 in 16x resolution: image shall be sized 8 times 16px times 4 times 16px -* If `true` the background is clipped to formspec size +* If `auto_clip` is `true`, the background is clipped to the formspec size (`x` and `y` are used as offset values, `w` and `h` are ignored) -#### `pwdfield[,;,;;