From: pauloue Date: Wed, 15 Aug 2018 15:05:11 +0000 (-0400) Subject: lua_api.txt: Various fixes and improvements (#7638) X-Git-Tag: 5.0.0~259 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4e2eeee3cc338b95e40a662c37eb4c6c3e7b4101;p=oweals%2Fminetest.git lua_api.txt: Various fixes and improvements (#7638) Improve item types descriptions. Add replacements field to fuel definition. Shorten two headers. Markdown fixes. Remove extra example. Add blank lines after headings. Linkify section references. Bracketed section names can be linked when compiled to HTML. --- diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 3a4e2e0ab..a8e843878 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1,5 +1,6 @@ Minetest Lua Modding API Reference ================================== + * More information at * Developer Wiki: @@ -21,16 +22,19 @@ 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`: `` * `$path_share`: `` @@ -93,29 +97,27 @@ Mods Mod load path ------------- -Paths are relative to the directories listed in the Paths section above. + +Paths are relative to the directories listed in the [Paths] section above. * `games//mods/` * `mods/` * `worlds//worldmods/` -Mod load path for world-specific games --------------------------------------- +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. -This is useful for e.g. adventure worlds. +This is useful for e.g. adventure worlds and happens if the `/game/` +directory exists. -This happens if the following directory exists: - - $world/game/ - -Mods should then be placed in: - - $world/game/mods/ +Mods should then be placed in `/game/mods/`. Modpacks -------- + 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. @@ -140,10 +142,12 @@ Mod directory structure └── 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 @@ -158,10 +162,12 @@ A key-value store of mod details. 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. @@ -175,6 +181,7 @@ to a single modname. This means that if the specified mod is missing, it does not prevent this mod from being loaded. ### `description.txt` + **Deprecated:** you should use mod.conf instead. This file is used if there is no description in mod.conf. @@ -182,29 +189,35 @@ 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: @@ -222,6 +235,7 @@ 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`. @@ -259,6 +273,7 @@ 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: @@ -267,14 +282,17 @@ of the game's nodes are to be used by the core mapgens. For example: ### 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 @@ -295,6 +313,7 @@ Only needed for registered biomes where 'node_stone' is sandstone: ### Aliases needed for Mapgen v6 #### Terrain and biomes + * mapgen_stone * mapgen_water_source * mapgen_lava_source @@ -310,6 +329,7 @@ Only needed for registered biomes where 'node_stone' is sandstone: * mapgen_ice #### Flora + * mapgen_tree * mapgen_leaves * mapgen_apple @@ -320,6 +340,7 @@ Only needed for registered biomes where 'node_stone' is sandstone: * mapgen_pine_needles #### Dungeons + * mapgen_cobble * mapgen_stair_cobble * mapgen_mossycobble @@ -344,10 +365,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: @@ -359,6 +382,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)` @@ -367,6 +391,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 `:`. @@ -379,6 +404,7 @@ on top of `cobble.png`. ### Advanced texture modifiers #### Crack + * `[crack::

` * `[cracko::

` * `[crack:::

` @@ -399,6 +425,7 @@ Example: default_cobble.png^[crack:10:1 #### `[combine:x:,=:,=:...` + * ``: width * ``: height * ``: x position @@ -413,6 +440,7 @@ Example: [combine:16x32:0,0=default_cobble.png:0,16=default_wood.png #### `[resize:x` + Resizes the texture to the given dimensions. Example: @@ -420,6 +448,7 @@ Example: default_sandstone.png^[resize:16x16 #### `[opacity:` + Makes the base image transparent according to the given ratio. `r` must be between 0 (transparent) and 255 (opaque). @@ -429,6 +458,7 @@ 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. @@ -438,6 +468,7 @@ Example: default_apple.png^[invert:rgb #### `[brighten` + Brightens the texture. Example: @@ -445,6 +476,7 @@ Example: tnt_tnt_side.png^[brighten #### `[noalpha` + Makes the texture completely opaque. Example: @@ -452,6 +484,7 @@ Example: default_leaves.png^[noalpha #### `[makealpha:,,` + Convert one color to transparency. Example: @@ -459,6 +492,7 @@ Example: default_cobble.png^[makealpha:128,128,128 #### `[transform` + * ``: transformation(s) to apply Rotates and/or flips the image. @@ -480,6 +514,7 @@ Example: default_stone.png^[transformFXR90 #### `[inventorycube{{{` + Escaping does not apply here and `^` is replaced by `&` in texture names instead. @@ -493,6 +528,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: @@ -500,6 +536,7 @@ Example: base.png^[lowpart:25:overlay.png #### `[verticalframe::` + * ``: animation frame count * ``: current animation frame @@ -510,15 +547,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 @@ -530,6 +570,7 @@ 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 @@ -538,6 +579,7 @@ 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 @@ -546,10 +588,12 @@ 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. @@ -557,6 +601,7 @@ 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 method. To disable the coloring of a face, set its color to white (because multiplying with white does nothing). @@ -564,12 +609,14 @@ 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 @@ -590,6 +637,7 @@ Examples: * 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. @@ -598,6 +646,7 @@ 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 @@ -633,6 +682,7 @@ To colorize a node on the map, set its `param2` value (according to the node's paramtype2). ### Conversion between nodes in the inventory and on the map + Static coloring is the same for both cases, there is no need for conversion. @@ -662,6 +712,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: @@ -681,6 +732,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. @@ -754,34 +806,34 @@ 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, } @@ -790,6 +842,7 @@ one player using `to_player = name,` `SimpleSoundSpec` ----------------- + * e.g. `""` * e.g. `"default_place_node"` * e.g. `{}` @@ -880,16 +933,6 @@ 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 - @@ -904,7 +947,7 @@ The definition of a node is stored and can be accessed by using minetest.registered_nodes[node.name] -See "Registered definitions". +See [Registered definitions]. Nodes are passed by value between Lua and the engine. They are represented by a table: @@ -917,6 +960,7 @@ use them to store arbitrary values. Node paramtypes --------------- + The functions of `param1` and `param2` are determined by certain fields in the node definition. @@ -1007,10 +1051,11 @@ node definition. and 63 being full. * Liquid texture is defined using `special_tiles = {"modname_tilename.png"}` -Nodes can also contain extra data. See "Node Metadata". +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`. @@ -1080,7 +1125,7 @@ Look for examples in `games/minimal` or `games/minetest_game`. * `nodebox` * Often used for stairs and slabs. * Allows defining nodes consisting of an arbitrary number of boxes. - * See 'Node boxes' below for more information. + * See [Node boxes] below for more information. * `mesh` * Uses models for nodes. * Tiles should hold model materials textures. @@ -1101,6 +1146,7 @@ Look for examples in `games/minimal` or `games/minetest_game`. Node boxes ---------- + Node selection boxes are defined using "node boxes". A nodebox is defined as any of: @@ -1171,6 +1217,7 @@ HUD HUD element types ----------------- + The position field is used for all element types. To account for differing resolutions, the position coordinates are the @@ -1209,6 +1256,7 @@ Displays an image on the HUD. * `offset`: offset in pixels from position. ### `text` + Displays text on the HUD. * `scale`: Defines the bounding rectangle of the text. @@ -1220,6 +1268,7 @@ Displays text on the HUD. * `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. @@ -1231,6 +1280,7 @@ Displays a horizontal bar made up of half-images. 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. @@ -1238,6 +1288,7 @@ Displays a horizontal bar made up of half-images. * `offset`: offset in pixels from position. ### `waypoint` + Displays distance to selected world position. * `name`: The name of the waypoint. @@ -1257,10 +1308,11 @@ Position/vector {x=num, y=num, z=num} -For helper functions see "Spatial Vectors". +For helper functions see [Spatial Vectors]. `pointed_thing` --------------- + * `{type="nothing"}` * `{type="node", under=pos, above=pos}` * `{type="object", ref=ObjectRef}` @@ -1310,15 +1362,18 @@ Items 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: An item that can be placed in the world as a node. +* Tool: An item that can be worn out and repaired, cannot be stacked, and often + digs or deals damage. +* Craftitem: A general purpose item that can be used in crafting recipes, eaten, + dropped, or used on things in the world. Amount and wear --------------- + All item stacks have an amount between 0 to 65535. It is 1 by default. Tool item stacks can not have an amount greater than 1. @@ -1329,6 +1384,7 @@ a higher wear. Non-tools always have a wear value of 0. Item formats ------------ + Items and item stacks can exist in three formats: Serializes, table format and `ItemStack`. @@ -1336,6 +1392,7 @@ 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: @@ -1350,6 +1407,7 @@ Examples: * `'default:pick_wood 1 21323'`: a wooden pickaxe, ca. 1/3 worn out ### Table format + Examples: 5 dirt nodes: @@ -1365,8 +1423,9 @@ An apple: {name="default:apple", count=1, wear=0, metadata=""} ### `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. @@ -1381,6 +1440,7 @@ the thing without actually knowing what the thing is. Usage ----- + Groups are stored in a table, having the group names with keys and the group ratings as values. For example: @@ -1402,29 +1462,34 @@ You can read the rating of a group for an item or a node by using Groups of items --------------- + Groups of items can define what kind of an item it is (e.g. wool). 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 ------------------ + 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 in tools define which groups of nodes and entities they are effective towards. Groups in crafting recipes -------------------------- + An example: Make meat soup from any meat, any water and any bowl: { @@ -1447,6 +1512,7 @@ Another example: Make red wool from white wool and red dye: 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 @@ -1476,6 +1542,7 @@ Special 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 @@ -1493,6 +1560,7 @@ Known damage and digging time defining 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 @@ -1508,6 +1576,7 @@ Item groups are often used for defining, well, _groups of items_. 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. @@ -1530,6 +1599,7 @@ Tools Tools definition ---------------- + Tools define: * Full punch interval @@ -1585,7 +1655,7 @@ 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". +List of damage for groups of entities. See [Entity damage mechanism]. Example definition of the capabilities of a tool ------------------------------------------------ @@ -1691,9 +1761,10 @@ 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: @@ -1702,7 +1773,7 @@ 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: @@ -1735,7 +1806,8 @@ Example: 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. @@ -1774,7 +1846,7 @@ For coloured text you can use `minetest.colorize`. 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[]` +appearing when you don't expect them to. See [`no_prepend[]`]. Examples -------- @@ -1805,11 +1877,13 @@ Elements -------- ### `size[,,]` + * Define the size of the menu in inventory slots * `fixed_size`: `true`/`false` (optional) * deprecated: `invsize[,;]` ### `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, @@ -1819,6 +1893,7 @@ Elements * Defaults to the center of the game window [0.5, 0.5]. ### `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, @@ -1831,10 +1906,12 @@ Elements extending off the game window due to particular game window sizes. ### `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` @@ -1842,16 +1919,20 @@ Elements (child containers are relative to parent containers) ### `container_end[]` + * End of a container, following elements are no longer relative to this container. ### `list[;;,;,;]` + * Show an inventory list ### `list[;;,;,;]` + * Show an inventory list ### `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 @@ -1859,19 +1940,23 @@ Elements determine the inventory where items will be sent to ### `listring[]` + * Shorthand for doing `listring[;]` for the last two inventory lists added by list[...] ### `listcolors[;]` + * Sets background color of slots as `ColorString` * Sets background color of slots on mouse hovering ### `listcolors[;;]` + * Sets background color of slots as `ColorString` * Sets background color of slots on mouse hovering * Sets color of slots border ### `listcolors[;;;;]` + * Sets background color of slots as `ColorString` * Sets background color of slots on mouse hovering * Sets color of slots border @@ -1879,6 +1964,7 @@ Elements * Sets default font color of tooltips ### `tooltip[;;;]` + * Adds tooltip for an element * `` tooltip background color as `ColorString` (optional) * `` tooltip font color as `ColorString` (optional) @@ -1889,22 +1975,27 @@ Elements * `` tooltip font color as `ColorString` (optional) ### `image[,;,;]` + * Show an image ### `item_image[,;,;]` + * Show an inventory image of registered item/node ### `bgcolor[;]` + * Sets background color of formspec as `ColorString` * If `true`, the background color is drawn fullscreen (does not affect the size of the formspec). ### `background[,;,;]` + * Use a background. Inventory rectangles are not drawn then. * Example for formspec 8x4 in 16x resolution: image shall be sized 8 times 16px times 4 times 16px. ### `background[,;,;;]` + * Use a background. Inventory rectangles are not drawn then. * Example for formspec 8x4 in 16x resolution: image shall be sized 8 times 16px times 4 times 16px @@ -1912,15 +2003,17 @@ Elements (`x` and `y` are used as offset values, `w` and `h` are ignored) ### `pwdfield[,;,;;