diff --git a/lua_api.html b/lua_api.html index 0cb47bf..3d6de96 100644 --- a/lua_api.html +++ b/lua_api.html @@ -4,7 +4,7 @@ layout: default ---
If you have any difficulty in understanding this, please read Programming in Lua.
init.lua
scripts in a shared environment.
The game directory can contain the file minetest.conf, which will be used to set default settings when running the particular game. It can also contain a settingtypes.txt in the same format as the one in builtin. -This settingtypes.txt will be parsed by the menu and the settings will be displayed in the "Games" category in the settings tab.
+This settingtypes.txt will be parsed by the menu and the settings will be displayed +in the "Games" category in the settings tab.Games can provide custom main menu images. They are put inside a menu
directory inside the game directory.
The images are named $identifier.png
, where $identifier
is one of overlay,background,footer,header
.
-If you want to specify multiple images for one identifier, add additional images named like $identifier.$n.png
, with an ascending number $n starting with 1,
-and a random image will be chosen from the provided ones.
Games can provide custom main menu images. They are put inside a menu
directory
+inside the game directory.
The images are named $identifier.png
, where $identifier
is
+one of overlay,background,footer,header
.
+If you want to specify multiple images for one identifier, add additional images named
+like $identifier.$n.png
, with an ascending number $n starting with 1, and a random
+image will be chosen from the provided ones.
Generic:
default_dirt.png^default_grass_side.png
default_grass_side.png
is overlayed over default_dirt.png
.
-The texture with the lower resolution will be automatically upscaled to the higher resolution texture.
Textures can be grouped together by enclosing them in (
and )
.
Example: cobble.png^(thing1.png^thing2.png)
minetest.registered_*
tables.
minetest.registered_schematic
with the key of schematic.name
schematic.name
is nil, the key is the returned IDlistring[<inventory location>;<list name>]
listring[]
listring[<inventory location>;<list name>]
listring[<inventory location>;<list name>]
+ for the last two inventory lists added by list[...]listcolors[<slot_bg_normal>;<slot_bg_hover>]
x
and y
position the field relative to the top left of the menuw
and h
are the size of the fieldh
h
name
is the name of the field as returned in fields to on_receive_fields
label
, if not blank, will be text printed on the top left above the fieldx
and y
position the field relative to the top left of the menuw
and h
are the size of the fieldh
h
name
is the name of the field as returned in fields to on_receive_fields
label
, if not blank, will be text printed on the top left above the fieldfield[<name>;<label>;<default>]
size[]
elementsize[]
elementtextarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
label[<X>,<Y>;<label>]
true
/false
: draw transparent backgroundminetest.explode_textlist_event
(main menu: engine.explode_textlist_event
)minetest.explode_textlist_event
(main menu: engine.explode_textlist_event
)tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]
x
and y
position the itemlist relative to the top left of the menuname
fieldname data is transferred to Luacaption 1
...: name shown on top of tabbox[<X>,<Y>;<W>,<H>;<color>]
x
and y
position the box relative to the top left of the menuw
and h
are the size of boxcolor
is color specified as a ColorString
dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]
x
and y
position of dropdowncheckbox[<X>,<Y>;<name>;<label>;<selected>;<tooltip>]
checkbox[<X>,<Y>;<name>;<label>;<selected>]
x
and y
: position of checkboxname
fieldname data is transferred to Lualabel
to be shown left of checkboxselected
(optional): true
/false
tooltip
(optional)scrollbar[<X>,<Y>;<W>,<H>;<orientation>;<name>;<value>]
x
and y
: position of trackbarw
and h
: width and heightorientation
: vertical
/horizontal
0
-1000
)minetest.explode_scrollbar_event
(main menu: engine.explode_scrollbar_event
)0
-1000
)minetest.explode_scrollbar_event
(main menu: engine.explode_scrollbar_event
)table[<X>,<Y>;<W>,<H>;<name>;<cell 1>,<cell 2>,...,<cell n>;<selected idx>]
tableoptions[]
tablecolumns[]
tableoptions[]
tablecolumns[]
x
and y
: position the itemlist relative to the top left of the menuw
and h
are the size of the itemlistname
: fieldname sent to server on row select or doubleclickcell 1
...cell n
: cell contents given in row-major orderselected idx
: index of row to be selected within table (first row = 1
)minetest.explode_table_event
(main menu: engine.explode_table_event
)minetest.explode_table_event
(main menu: engine.explode_table_event
)tableoptions[<opt 1>;<opt 2>;...]
table[]
table[]
color=#RRGGBB
ColorString
), defaults to #FFFFFF
tablecolumns[<type 1>,<opt 1a>,<opt 1b>,...;<type 2>,<opt 2a>,<opt 2b>;...]
table[]
text
, image
, color
, indent
, tree
table[]
text
, image
, color
, indent
, tree
text
: show cell contents as textimage
: cell contents are an image index, use column options to define imagescolor
: cell contents are a ColorString and define color of following celltree
: same as indent, but user can open and close subtrees (treeview-like)align=<value>
text
and image
: content alignment within cells.
Available values: left
(default), center
, right
, inline
colorspec = 0xFF00FF00
or string form, a ColorString (defined above):
colorspec = "green"
+Most text can contain escape sequences, that can for example color the text.
+There are a few exceptions: tab headers, dropdowns and vertical labels can't.
+The following functions provide escape sequences:
+ core.get_color_escape_sequence(color)
:
+ * color
is a ColorString
+ * The escape sequence sets the text color to color
+ core.colorize(color, message)
:
+ * Equivalent to:
+ core.get_color_escape_sequence(color) ..
+ message ..
+ core.get_color_escape_sequence("#ffffff")
+* color.get_background_escape_sequence(color)
+ * color
is a ColorString
+ * The escape sequence sets the background of the whole text element to
+ color
. Only defined for item descriptions and tooltips.
vector.new(a[, b, c])
: returns a vector:minetest.register_tool(name, item definition)
minetest.register_craftitem(name, item definition)
minetest.register_alias(name, convert_to)
minetest.register_craft(recipe)
minetest.register_craft(recipe)
minetest.clear_craft(recipe)
minetest.register_craft(recipe)
. For output specify only the item, without a quantity.minetest.register_ore(ore definition)
minetest.register_decoration(decoration definition)
minetest.register_on_leaveplayer(func(ObjectRef))
minetest.register_on_leaveplayer(func(ObjectRef, timed_out))
timed_out
: True for timeout, false for other reasons.minetest.register_on_cheat(func(ObjectRef, cheat))
minetest.register_chatcommand(cmd, chatcommand definition)
minetest.register_privilege(name, definition)
definition
: "description text"
definition
: { description = "description text", give_to_singleplayer = boolean, -- default: true }
definition
: { description = "description text", give_to_singleplayer = boolean}
+ the default of give_to_singleplayer
is true name=nil
.minetest.check_password_entry(name, entry, password)
minetest.get_password_hash(name, raw_password)
minetest.string_to_privs(str)
: returns {priv1=true,...}
minetest.auth_reload
call the authetification handler.
minetest.get_mapgen_params()
Returns mapgen parameters, a table containing
mgname
, seed
, chunksize
, water_level
, and flags
.minetest.set_mapgen_params(MapgenParams)
on_mapgen_init
minetest.auth_reload
call the authetification handler.
minetest.get_mapgen_setting(name)
minetest.get_mapgen_setting_noiseparams(name)
name
exists
+ and is a valid NoiseParamsminetest.set_mapgen_setting(name, value, [override_meta=false])
value
, and will take effect if the corresponding mapgen setting
+ is not already present in map_meta.txt. If the optional boolean override_meta is set to true,
+ this setting will become the active setting regardless of the map metafile contents.minetest.set_mapgen_setting_noiseparams(name, value, [override_meta=false])
minetest.set_noiseparams(name, noiseparams, set_default)
name
to the noiseparams table specified in noiseparams
.name
to the noiseparams table specified in noiseparams
.set_default
is an optional boolean (default: true
) that specifies whether the setting
should be applied to the default config or current active configminetest.auth_reload
call the authetification handler.
HTTPApiTable.fetch_async(HTTPRequest req)
: returns handle
HTTPApiTable.fetch_async_get(handle)
: returns HTTPRequestResultminetest.auth_reload
call the authetification handler.
minetest.get_content_id(name)
: returns an integer
minetest.get_name_from_content_id(content_id)
: returns a stringminetest.auth_reload
call the authetification handler.
...
indicates method-specific arguments. Currently, no methods use this.minetest.encode_base64(string)
: returns string encoded in base64minetest.decode_base64(string)
: returns stringminetest.is_protected(pos, name)
: returns boolean
name
shouldn't be abled to dig at pos
or do other
+name
shouldn't be abled to dig at pos
or do other
actions, defineable by mods, due to some mod-defined ownership-like concept.
Returns false or nil, if the player is allowed to do such actions.minetest.get_node_timer(pos)
.
get_player_name()
: returns ""
if is not a playerget_player_velocity()
: returns nil
if is not a player otherwise a table {x, y, z} representing the player's instantaneous velocity in nodes/sget_player_velocity()
: returns nil
if is not a player, otherwise a
+ table {x, y, z} representing the player's instantaneous velocity in nodes/sget_look_dir()
: get camera direction as a unit vectorget_look_pitch()
: pitch in radiansget_look_yaw()
: yaw in radians (wraps around pretty randomly as of now)set_look_pitch(radians)
: sets look pitchset_look_yaw(radians)
: sets look yawget_look_vertical()
: pitch in radiansget_look_horizontal()
: yaw in radiansset_look_vertical(radians)
: sets look pitchset_look_horizontal(radians)
: sets look yawget_look_pitch()
: pitch in radians - Deprecated as broken. Use get_look_vertical.get_look_yaw()
: yaw in radians - Deprecated as broken. Use get_look_horizontal.set_look_pitch(radians)
: sets look pitch - Deprecated. Use set_look_vertical.set_look_yaw(radians)
: sets look yaw - Deprecated. Use set_look_horizontal.get_breath()
: returns players breathset_breath(value)
: sets players breathminetest.get_node_timer(pos)
.
hud_get_hotbar_selected_image
: returns texturenamehud_replace_builtin(name, hud_definition)
minetest.get_node_timer(pos)
.
A fast access data structure to store areas, and find areas near a given position or area.
Every area has a data
string attribute to store additional information.
You can create an empty AreaStore
by calling AreaStore()
, or AreaStore(type_name)
.
-If you chose the parameter-less constructor, a fast implementation will be automatically chosen for you.
get_area(id, include_borders, include_data)
: returns the area with the id id
. (optional) Boolean values include_borders
and include_data
control what's copied.get_areas_for_pos(pos, include_borders, include_data)
: returns all areas that contain the position pos
. (optional) Boolean values include_borders
and include_data
control what's copied.get_areas_in_area(edge1, edge2, accept_overlap, include_borders, include_data)
: returns all areas that contain all nodes inside the area specified by edge1
and edge2
(inclusive). If accept_overlap
is true, also areas are returned that have nodes in common with the specified area. (optional) Boolean values include_borders
and include_data
control what's copied.insert_area(edge1, edge2, data, [id])
: inserts an area into the store. Returns the new area's ID, or nil if the insertion failed. The (inclusive) positions edge1
and edge2
describe the area. data
is a string stored with the area. If passed, id
will be used as the internal area ID, it must be a unique number between 0 and 2^32-2. If you use the id
parameter you must always use it, or insertions are likely to fail due to conflicts.reserve(count)
: reserves resources for at most count
many contained areas. Only needed for efficiency, and only some implementations profit.get_area(id, include_borders, include_data)
: returns the area with the id id
.
+ (optional) Boolean values include_borders
and include_data
control what's copied.get_areas_for_pos(pos, include_borders, include_data)
: returns all areas that contain
+ the position pos
. (optional) Boolean values include_borders
and include_data
control
+ what's copied.get_areas_in_area(edge1, edge2, accept_overlap, include_borders, include_data)
:
+ returns all areas that contain all nodes inside the area specified by edge1
and edge2
(inclusive).
+ If accept_overlap
is true, also areas are returned that have nodes in common with the specified area.
+ (optional) Boolean values include_borders
and include_data
control what's copied.insert_area(edge1, edge2, data, [id])
: inserts an area into the store. Returns the new area's ID,
+ or nil if the insertion failed. The (inclusive) positions edge1
and edge2
describe the area.
+ data
is a string stored with the area. If passed, id
will be used as the internal area ID,
+ it must be a unique number between 0 and 2^32-2. If you use the id
parameter you must always use it,
+ or insertions are likely to fail due to conflicts.reserve(count)
: reserves resources for at most count
many contained areas.
+ Only needed for efficiency, and only some implementations profit.remove_area(id)
: removes the area with the given id from the store, returns success.set_cache_params(params)
: sets params for the included prefiltering cache. Calling invalidates the cache, so that its elements have to be newly generated.set_cache_params(params)
: sets params for the included prefiltering cache.
+ Calling invalidates the cache, so that its elements have to be newly generated.params
:
{
enabled = boolean, -- whether to enable, default true
- block_radius = number, -- the radius (in nodes) of the areas the cache generates prefiltered lists for, minimum 16, default 64
+ block_radius = number, -- the radius (in nodes) of the areas the cache generates
+ prefiltered lists for, minimum 16, default 64
limit = number, -- the cache's size, minimum 20, default 1000
}to_string()
: Experimental. Returns area store serialized as a (binary) string.to_file(filename)
: Experimental. Like to_string()
, but writes the data to a file.from_string(str)
: Experimental. Deserializes string and loads it into the AreaStore. Returns success and, optionally, an error message.from_string(str)
: Experimental. Deserializes string and loads it into the AreaStore.
+ Returns success and, optionally, an error message.from_file(filename)
: Experimental. Like from_string()
, but reads the data from a file.ItemStack
next()
: return next integer random number [-2147483648
...2147483647
]next(min, max)
: return next integer random number [min
...max
]rand_normal_dist(min, max, num_trials=6)
: return normally distributed random number [min
...max
]self
:.name
, which is the registered name ("mod:thing")
.name
, which is the registered name ("mod:thing")
.object
, which is an ObjectRef
pointing to the objectregister_abm
){
+ label = "Lava cooling",
+-- ^ Descriptive label for profiling purposes (optional).
+-- Definitions with identical labels will be listed as one.
-- In the following two fields, also group:groupname will work.
nodenames = {"default:lava_source"},
neighbors = {"default:water_source", "default:water_flowing"}, -- Any of these --[[
@@ -4028,6 +4148,9 @@ minetest.spawn_tree(pos,apple_tree)
register_lbm
){
+ label = "Upgrade legacy doors",
+-- ^ Descriptive label for profiling purposes (optional).
+-- Definitions with identical labels will be listed as one.
name = "modname:replace_legacy_door",
nodenames = {"default:lava_source"},
-- ^ List of node names to trigger the LBM on.
@@ -4158,6 +4281,7 @@ minetest.spawn_tree(pos,apple_tree)
^ paramtype = "light" allows light to propagate from or through the node with light value
^ falling by 1 per node. This line is essential for a light source node to spread its light. ]]
paramtype2 = "none", -- See "Nodes"
+ place_param2 = nil, -- Force value for param2 when player places node
is_ground_content = true, -- If false, the cave generator will not carve through this
sunlight_propagates = false, -- If true, sunlight will go infinitely through this
walkable = true, -- If true, objects collide with node
@@ -4170,7 +4294,8 @@ minetest.spawn_tree(pos,apple_tree)
liquid_alternative_flowing = "", -- Flowing version of source liquid
liquid_alternative_source = "", -- Source version of flowing liquid
liquid_viscosity = 0, -- Higher viscosity = slower flow (max. 7)
- liquid_renewable = true, -- Can new liquid source be created by placing two or more sources nearby?
+ liquid_renewable = true, --[[
+ ^ If true, a new liquid source can be created by placing two or more sources nearby ]]
leveled = 0, --[[
^ Block contains level in param2. Value is default level, used for snow.
^ Don't forget to use "leveled" type nodebox. ]]
@@ -4203,8 +4328,8 @@ minetest.spawn_tree(pos,apple_tree)
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.
+ items = {"foo:bar", "baz:frob"}, -- Items to drop.
+ rarity = 1, -- Probability of dropping is 1 / rarity.
},
},
},
@@ -4369,6 +4494,8 @@ minetest.spawn_tree(pos,apple_tree)
}
register_biome
)Note +The Biome API is still in an experimental phase and subject to change.
{
name = "tundra",
node_dust = "default:snow",
@@ -4388,6 +4515,9 @@ minetest.spawn_tree(pos,apple_tree)
-- ^ Node that replaces all seawater nodes not in the defined surface layer.
node_river_water = "default:ice",
-- ^ Node that replaces river water in mapgens that use default:river_water.
+ node_riverbed = "default:gravel",
+ depth_riverbed = 2,
+-- ^ Node placed under river water and thickness of this layer.
y_min = 1,
y_max = 31000,
-- ^ Lower and upper limits for biome.
@@ -4555,6 +4685,9 @@ minetest.spawn_tree(pos,apple_tree)
size = 1,
collisiondetection = false,
-- ^ collisiondetection: if true collides with physical objects
+ collision_removal = false,
+-- ^ collision_removal: if true then particle is removed when it collides,
+-- ^ requires collisiondetection = true to have any effect
vertical = false,
-- ^ vertical: if true faces player using y axis only
texture = "image.png",
@@ -4583,6 +4716,9 @@ minetest.spawn_tree(pos,apple_tree)
-- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
collisiondetection = false,
-- ^ collisiondetection: if true uses collision detection
+ collision_removal = false,
+-- ^ collision_removal: if true then particle is removed when it collides,
+-- ^ requires collisiondetection = true to have any effect
vertical = false,
-- ^ vertical: if true faces player using y axis only
texture = "image.png",
@@ -4591,7 +4727,7 @@ minetest.spawn_tree(pos,apple_tree)
-- ^ Playername is optional, if specified spawns particle only on the player's client
}
-HTTPRequest
definition (http_fetch
, http_fetch_async
)HTTPRequest
definition (HTTPApiTable.fetch_async
, HTTPApiTable.fetch_async
){
url = "http://example.org",
timeout = 10,
@@ -4610,7 +4746,7 @@ minetest.spawn_tree(pos,apple_tree)
-- ^ Optional, if true performs a multipart HTTP request. Default is false.
}
-HTTPRequestResult
definition (http_fetch
callback, http_fetch_async_get
)HTTPRequestResult
definition (HTTPApiTable.fetch
callback, HTTPApiTable.fetch_async_get
){
completed = true,
-- ^ If true, the request has finished (either succeeded, failed or timed out)