]> git.lizzy.rs Git - minetest.git/blobdiff - doc/lua_api.txt
Fix compiling if no endian.h found
[minetest.git] / doc / lua_api.txt
index e027fe11da8a9ef5c1331be7aa8dfd815708d8fe..e4a016b1a02dbde269606c6dccb0036bf3fdf1d6 100644 (file)
@@ -103,6 +103,7 @@ mods
 |   |-- screenshot.png
 |   |-- description.txt
 |   |-- init.lua
+|   |-- models
 |   |-- textures
 |   |   |-- modname_stuff.png
 |   |   `-- modname_something_else.png
@@ -137,6 +138,9 @@ init.lua:
   minetest.setting_get(name) and minetest.setting_getbool(name) can be used
   to read custom or existing settings at load time, if necessary.
 
+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.
@@ -211,7 +215,7 @@ Advanced texture modifiers:
   [combine:<w>x<h>:<x1>,<y1>=<file1>:<x2>,<y2>=<file2>
     w = width, h = height, x1/x2 = x position, y1/y1 = y position,
     file1/file2 = texture to combine
-    Create a textue of size <w> x <h> and blit <file1> to (<x1>,<y1>)
+    Create a texture of size <w> x <h> and blit <file1> to (<x1>,<y1>)
     and blit <file2> to (<x2>,<y2>).
     Example: [combine:16x32:0,0=default_cobble.png:0,16=default_wood.png
 
@@ -220,7 +224,7 @@ Advanced texture modifiers:
     Example: tnt_tnt_side.png^[brighten
 
   [noalpha
-    Makes the texture completly opaque.
+    Makes the texture completely opaque.
     Example: default_leaves.png^[noalpha
 
   [makealpha:<r>,<g>,<b>
@@ -258,6 +262,14 @@ Advanced texture modifiers:
     Crops the texture to a frame of a vertical animation.
     Example: default_torch_animated.png^[verticalframe:16:8
 
+  [mask:<file>
+    Apply a mask to the base image.
+    The mask is applied using binary AND.
+
+  [colorize:<color>
+    Colorize the textures with given color
+    <color> as ColorString
+
 Sounds
 -------
 Only OGG Vorbis files are supported.
@@ -396,14 +408,21 @@ param2 is reserved for the engine when any of these are used:
     0 = y+    1 = z+    2 = z-    3 = x+    4 = x-    5 = y-
     facedir's two less significant bits are rotation around the axis
   paramtype2 == "leveled"
-  ^ The drawn node level is read from param2, like flowingliquid
-
+  collision_box = {
+       type = "fixed",
+       fixed = {
+                       {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
+                       },
+  },
+  ^ defines list of collision boxes for the node. If empty, collision boxes
+       will be the same as nodeboxes, in case of any other nodes will be full cube
+       as in the example above.
+                       
 Nodes can also contain extra data. See "Node Metadata".
 
 Node drawtypes
 ---------------
-There are a bunch of different looking node types. These are mostly just
-copied from Minetest 0.3; more may be made in the future.
+There are a bunch of different looking node types.
 
 Look for examples in games/minimal or games/minetest_game.
 
@@ -413,14 +432,19 @@ Look for examples in games/minimal or games/minetest_game.
 - flowingliquid
 - glasslike
 - glasslike_framed
+- glasslike_framed_optional
 - allfaces
 - allfaces_optional
 - torchlike
 - signlike
 - plantlike
+- firelike
 - fencelike
 - raillike
 - nodebox -- See below. EXPERIMENTAL
+- mesh -- use models for nodes
+
+*_optional drawtypes need less rendering time if deactivated (always client side)
 
 Node boxes
 -----------
@@ -458,6 +482,12 @@ A box of a regular node would look like:
 
 type = "leveled" is same as "fixed", but y2 will be automatically set to level from param2
 
+Meshes
+-----------
+If drawtype "mesh" is used tiles should hold model materials textures.
+Only static meshes are implemented.
+For supported model formats see Irrlicht engine documentation.
+    
 Ore types
 ---------------
 These tell in what manner the ore is generated.
@@ -466,13 +496,13 @@ All default ores are of the uniformly-distributed scatter type.
 - scatter
     Randomly chooses a location and generates a cluster of ore.
     If noise_params is specified, the ore will be placed if the 3d perlin noise at
-    that point is greater than the noise_threshhold, giving the ability to create a non-equal
+    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.
     The relative height of the sheet can be controlled by the same perlin noise as well, by specifying
     a non-zero 'scale' parameter in noise_params.  IMPORTANT: The noise is not transformed by offset or
-    scale when comparing against the noise threshhold, but scale is used to determine relative height.
+    scale when comparing against the noise threshold, but scale is used to determine relative height.
     The height of the blob is randomly scattered, with a maximum height of clust_size.
     clust_scarcity and clust_num_ores are ignored.
     This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
@@ -841,7 +871,7 @@ tool_capabilities = {
     damage_groups = {fleshy=2},
 }
 
-This makes the tool be able to dig nodes that fulfill both of these:
+This makes the tool be able to dig nodes that fulfil both of these:
 - Have the **crumbly** group
 - Have a **level** group less or equal to 2
 
@@ -978,16 +1008,16 @@ list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]
 ^ Show an inventory list
 
 listcolors[<slot_bg_normal>;<slot_bg_hover>]
-^ Sets background color of slots in HEX-Color format
+^ Sets background color of slots as ColorString
 ^ Sets background color of slots on mouse hovering
 
 listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>]
-^ Sets background color of slots in HEX-Color format
+^ Sets background color of slots as ColorString
 ^ Sets background color of slots on mouse hovering
 ^ Sets color of slots border
 
 listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>;<tooltip_bgcolor>;<tooltip_fontcolor>]
-^ Sets background color of slots in HEX-Color format
+^ 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
@@ -995,8 +1025,8 @@ listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>;<tooltip_bgcolor>;<too
 
 tooltip[<gui_element_name>;<tooltip_text>;<bgcolor>,<fontcolor>]
 ^ Adds tooltip for an element
-^ <bgcolor> tooltip background color in HEX-Color format (optional)
-^ <fontcolor> tooltip font color in HEX-Color format (optional)
+^ <bgcolor> tooltip background color as ColorString (optional)
+^ <fontcolor> tooltip font color as ColorString (optional)
 
 
 image[<X>,<Y>;<W>,<H>;<texture name>]
@@ -1008,7 +1038,7 @@ item_image[<X>,<Y>;<W>,<H>;<item name>]
 ^ Position and size units are inventory slots
 
 bgcolor[<color>;<fullscreen>]
-^ Sets background color of formspec in HEX-Color format
+^ Sets background color of formspec as ColorString
 ^ If true the background color is drawn fullscreen (does not effect the size of the formspec)
 
 background[<X>,<Y>;<W>,<H>;<texture name>]
@@ -1119,7 +1149,7 @@ textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>;<sele
 tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]
 ^ show a tabHEADER at specific position (ignores formsize)
 ^ x and y position the itemlist relative to the top left of the menu
-^ name fieldname data is transfered to Lua
+^ name fieldname data is transferred to Lua
 ^ caption 1... name shown on top of tab
 ^ current_tab index of selected tab 1...
 ^ transparent (optional) show transparent
@@ -1129,7 +1159,7 @@ box[<X>,<Y>;<W>,<H>;<color>]
 ^ simple colored semitransparent box
 ^ x and y position the box relative to the top left of the menu
 ^ w and h are the size of box
-^ color in HEX-Color format
+^ color as ColorString
 
 dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]
 ^ show a dropdown field
@@ -1138,14 +1168,14 @@ dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]
 ^     2) read the value on pressing a button (all dropdown values are available)
 ^ x and y position of dropdown
 ^ width of dropdown
-^ fieldname data is transfered to Lua
+^ fieldname data is transferred to Lua
 ^ items to be shown in dropdown
 ^ index of currently selected dropdown item
 
 checkbox[<X>,<Y>;<name>;<label>;<selected>;<tooltip>]
 ^ show a checkbox
 ^ x and y position of checkbox
-^ name fieldname data is transfered to Lua
+^ name fieldname data is transferred to Lua
 ^ label to be shown left of checkbox
 ^ selected (optional) true/false
 ^ tooltip (optional)
@@ -1158,7 +1188,7 @@ scrollbar[<X>,<Y>;<W>,<H>;<orientation>;<name>;<value>]
 ^ x and y position of trackbar
 ^ width and height
 ^ orientation vertical/horizontal
-^ fieldname data is transfered to lua
+^ fieldname data is transferred to lua
 ^ value this trackbar is set to (0-1000)
 ^ see also minetest.explode_scrollbar_event (main menu: engine.explode_scrollbar_event)
 
@@ -1175,15 +1205,15 @@ table[<X>,<Y>;<W>,<H>;<name>;<cell 1>,<cell 2>,...,<cell n>;<selected idx>]
 tableoptions[<opt 1>;<opt 2>;...]
 ^ sets options for table[]:
 ^ color=#RRGGBB
-^^ default text color (HEX-Color), defaults to #FFFFFF
+^^ default text color (ColorString), defaults to #FFFFFF
 ^ background=#RRGGBB
-^^ table background color (HEX-Color), defaults to #000000
+^^ table background color (ColorString), defaults to #000000
 ^ border=<true/false>
 ^^ should the table be drawn with a border? (default true)
 ^ highlight=#RRGGBB
-^^ highlight background color (HEX-Color), defaults to #466432
+^^ highlight background color (ColorString), defaults to #466432
 ^ highlight_text=#RRGGBB
-^^ highlight text color (HEX-Color), defaults to #FFFFFF
+^^ highlight text color (ColorString), defaults to #FFFFFF
 ^ opendepth=<value>
 ^^ all subtrees up to depth < value are open (default value = 0)
 ^^ only useful when there is a column of type "tree"
@@ -1193,7 +1223,7 @@ tablecolumns[<type 1>,<opt 1a>,<opt 1b>,...;<type 2>,<opt 2a>,<opt 2b>;...]
 ^ types: text, image, color, indent, tree
 ^^ text:   show cell contents as text
 ^^ image:  cell contents are an image index, use column options to define images
-^^ color:  cell contents are a HEX-Color and define color of following cell
+^^ color:  cell contents are a ColorString and define color of following cell
 ^^ indent: cell contents are a number and define indentation of following cell
 ^^ tree:   same as indent, but user can open and close subtrees (treeview-like)
 ^ column options:
@@ -1224,8 +1254,8 @@ Inventory location:
 - "nodemeta:<X>,<Y>,<Z>": Any node metadata
 - "detached:<name>": A detached inventory
 
-HEX-Color
----------
+ColorString
+-----------
 #RGB
 ^ defines a color in hexadecimal format
 #RGBA
@@ -1235,6 +1265,12 @@ HEX-Color
 #RRGGBBAA
 ^ defines a color in hexadecimal format and alpha channel
 
+Named colors are also supported and are equivalent to "CSS Color Module Level 4"
+(http://dev.w3.org/csswg/css-color/#named-colors). To specify the value of the
+alpha channel, append #AA to the end of the color name (e.g. colorname#08). For
+named colors the hexadecimal string representing the alpha value must (always)
+be two hexadecimal digits.
+
 Vector helpers
 ---------------
 vector.new([x[, y, z]]) -> vector
@@ -1272,6 +1308,8 @@ minetest.formspec_escape(string) -> string
 ^ escapes characters [ ] \ , ;  that can not be used in formspecs
 minetest.is_yes(arg)
 ^ returns whether arg can be interpreted as yes
+minetest.get_us_time()
+^ returns time with microsecond precision
 
 minetest namespace reference
 -----------------------------
@@ -1535,8 +1573,6 @@ minetest.set_node_level(pos, level)
 ^ set level of leveled node, default level = 1, if totallevel > maxlevel returns rest (total-max).
 minetest.add_node_level(pos, level)
 ^ increase level of leveled node by level, default level = 1, if totallevel > maxlevel returns rest (total-max). can be negative for decreasing
-minetest.get_time_us()
-^ get time in microseconds
 
 Inventory:
 minetest.get_inventory(location) -> InvRef
@@ -1715,7 +1751,7 @@ minetest.place_schematic(pos, schematic, rotation, replacements, force_placement
 ^ Place the schematic specified by schematic (see: Schematic specifier) at pos.
 ^ Rotation can be "0", "90", "180", "270", or "random".
 ^ If the rotation parameter is omitted, the schematic is not rotated.
-^ replacements = {{"oldname", "convert_to"}, ...}
+^ replacements = {["old_name"] = "convert_to", ...}
 ^ force_placement is a boolean indicating whether nodes other than air and
 ^ ignore are replaced by the schematic
 
@@ -1742,7 +1778,7 @@ minetest.parse_json(string[, nullvalue]) -> something
 minetest.write_json(data[, styled]) -> string or nil and error message
 ^ Convert a Lua table into a JSON string
 ^ styled: Outputs in a human-readable format if this is set, defaults to false
-^ Un-serializable things like functions and userdata are saved as null.
+^ Unserializable things like functions and userdata are saved as null.
 ^ Warning: JSON is more strict than the Lua table format.
     1. You can only use strings and positive integers of at least one as keys.
     2. You can not mix string and integer keys.
@@ -1759,6 +1795,18 @@ minetest.deserialize(string) -> table
 ^ Example: deserialize('return { ["foo"] = "bar" }') -> {foo='bar'}
 ^ Example: deserialize('print("foo")') -> nil (function call fails)
   ^ error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)
+minetest.compress(data, method, ...) -> compressed_data
+^ Compress a string of data.
+^ `method` is a string identifying the compression method to be used.
+^ Supported compression methods:
+^     Deflate (zlib): "deflate"
+^ `...` indicates method-specific arguments.  Currently defined arguments are:
+^     Deflate: `level` - Compression level, 0-9 or nil.
+minetest.decompress(compressed_data, method, ...) -> data
+^ Decompress a string of data (using ZLib).
+^ See documentation on minetest.compress() for supported compression methods.
+^ currently supported.
+^ `...` indicates method-specific arguments.  Currently, no methods use this.
 minetest.is_protected(pos, name) -> bool
 ^ This function should be overridden by protection mods and should be used to
   check if a player can interact at a position.
@@ -2073,6 +2121,8 @@ methods:
   ^ returns actual emerged pmin, actual emerged pmax
 - write_to_map():  Writes the data loaded from the VoxelManip back to the map.
   ^ important: data must be set using VoxelManip:set_data before calling this
+- get_node_at(pos): Returns a MapNode table of the node currently loaded in the VoxelManip at that position
+- set_node_at(pos, node): Sets a specific MapNode in the VoxelManip at that position
 - get_data():  Gets the data read into the VoxelManip object
   ^ returns raw node data is in the form of an array of node content ids
 - set_data(data):  Sets the data contents of the VoxelManip object
@@ -2084,7 +2134,7 @@ methods:
   ^ To be used only by a VoxelManip object from minetest.get_mapgen_object
   ^ (p1, p2) is the area in which lighting is set; defaults to the whole area if left out
 - get_light_data(): Gets the light data read into the VoxelManip object
-  ^ Returns an array (indicies 1 to volume) of integers ranging from 0 to 255
+  ^ Returns an array (indices 1 to volume) of integers ranging from 0 to 255
   ^ Each value is the bitwise combination of day and night light values (0..15 each)
   ^ light = day + (night * 16)
 - set_light_data(light_data):  Sets the param1 (light) contents of each node in the VoxelManip
@@ -2095,6 +2145,8 @@ methods:
   ^ To be used only by a VoxelManip object from minetest.get_mapgen_object
   ^ (p1, p2) is the area in which lighting is set; defaults to the whole area if left out
 - update_liquids():  Update liquid flow
+- was_modified(): Returns true or false if the data in the voxel manipulator had been modified since
+  the last read from map, due to a call to minetest.set_data() on the loaded area elsewhere
 
 VoxelArea: A helper class for voxel areas
 - Can be created via VoxelArea:new{MinEdge=pmin, MaxEdge=pmax}
@@ -2204,7 +2256,7 @@ treedef={
   thin_branches, - boolean true -> use thin (1 node) branches
   fruit,         - string  fruit node name
   fruit_chance,  - num     chance (0-100) to replace leaves with fruit node
-  seed,          - num     random seed
+  seed,          - num     random seed; if no seed is provided, the engine will create one
   }
 
 Key for Special L-System Symbols used in Axioms
@@ -2378,7 +2430,7 @@ Node definition (register_node)
 
     drawtype = "normal", -- See "Node drawtypes"
     visual_scale = 1.0,
-    ^ Supported for drawtypes "plantlike", "signlike", "torchlike".
+    ^ Supported for drawtypes "plantlike", "signlike", "torchlike", "mesh".
     ^ For plantlike, the image will start at the bottom of the node; for the
     ^ other drawtypes, the image will be centered on the node.
     ^ Note that positioning for "torchlike" may still change.
@@ -2400,7 +2452,6 @@ Node definition (register_node)
     diggable = true, -- If false, can never be dug
     climbable = false, -- If true, can be climbed on (ladder)
     buildable_to = false, -- If true, placed nodes can replace this node
-    drop = "", -- alternatively drop = { max_items = ..., items = { ... } }
     liquidtype = "none", -- "none"/"source"/"flowing"
     liquid_alternative_flowing = "", -- Flowing version of source liquid
     liquid_alternative_source = "", -- Source version of flowing liquid
@@ -2413,6 +2464,7 @@ Node definition (register_node)
     light_source = 0, -- Amount of light emitted by node
     damage_per_second = 0, -- If player is inside node, this damage is caused
     node_box = {type="regular"}, -- See "Node boxes"
+    mesh = "model",
     selection_box = {type="regular"}, -- See "Node boxes"
     ^ If drawtype "nodebox" is used and selection_box is nil, then node_box is used
     legacy_facedir_simple = false, -- Support maps made in and before January 2012
@@ -2423,6 +2475,17 @@ Node definition (register_node)
         dug = <SimpleSoundSpec>,
         place = <SimpleSoundSpec>,
     },
+    drop = "",  -- Name of dropped node when dug. Default is the node itself.
+    -- Alternatively:
+    drop = {
+        max_items = 1,  -- Maximum number of items to drop.
+        items = { -- Choose max_items randomly from this list.
+            {
+                items = {"foo:bar", "baz:frob"},  -- Choose one item randomly from this list.
+                rarity = 1,  -- Probability of getting is 1 / rarity.
+            },
+        },
+    },
 
     on_construct = func(pos),
     ^ Node constructor; always called after adding node
@@ -2566,7 +2629,7 @@ Ore definition (register_ore)
     flags = "",
     ^ Attributes for this ore generation
     noise_threshhold = 0.5,
-    ^ If noise is above this threshhold, ore is placed.  Not needed for a uniform distribution
+    ^ If noise is above this threshold, ore is placed.  Not needed for a uniform distribution
     noise_params = {offset=0, scale=1, spread={x=100, y=100, z=100}, seed=23, octaves=3, persist=0.70}
     ^ NoiseParams structure describing the perlin noise used for ore distribution.
     ^ Needed for sheet ore_type.  Omit from scatter ore_type for a uniform ore distribution
@@ -2626,7 +2689,7 @@ Decoration definition (register_decoration)
         },
     },
     ^ See 'Schematic specifier' for details.
-    replacements = {{"oldname", "convert_to"}, ...},
+    replacements = {["oldname"] = "convert_to", ...},
     flags = "place_center_x, place_center_z",
     ^ Flags for schematic decorations.  See 'Schematic attributes'.
     rotation = "90" -- rotate schematic 90 degrees on placement
@@ -2733,3 +2796,16 @@ ParticleSpawner definition (add_particlespawner)
     playername = "singleplayer"
     ^ Playername is optional, if specified spawns particle only on the player's client
 }
+
+NoiseParams definition (PerlinNoiseMap)
+{
+    offset = 0,
+    scale = 0,
+    spread = 0,
+    seed = 0,
+    octaves = 0,
+    ^ A higher value will result in more details, this means more operations
+    persist = 0,
+    eased = false
+    ^ Whether it should create curves in 3D perlin maps
+}