diff --git a/lua_api.html b/lua_api.html index bea02a1..4f0a2f0 100644 --- a/lua_api.html +++ b/lua_api.html @@ -188,6 +188,7 @@ layout: default
If you have any difficulty in understanding this, please read Programming in Lua.
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 must specify two fields:
size
field is a 3D vector containing the dimensions of the provided schematic.data
field is a flat table of MapNodes making up the schematic,
- in the order of [z [y [x]]]
.size
field is a 3D vector containing the dimensions of the provided schematic. (required)yslice_prob
field is a table of {ypos, prob} which sets the ypos
th vertical slice
+ of the schematic to have a prob / 256 * 100
chance of occuring. (default: 255)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)Important: The default value for param1
in MapNodes here is 255
,
-which represents "always place".
In the bulk MapNode
data, param1
, instead of the typical light values,
-instead represents the probability of that node appearing in the structure.
When passed to minetest.create_schematic
, probability is an integer value
-ranging from 0
to 255
:
0
means that node will never appear (0% chance).255
means the node will always appear (100% chance).p
is greater than 0
, then there is a
- (p / 256 * 100)
% chance that node will appear when the schematic is
- placed on the map.Important note: Node aliases cannot be used for a raw schematic provided - when registering as a decoration.
+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.
See section "Flag Specifier Format".
Currently supported flags: place_center_x
, place_center_y
,
@@ -1801,6 +1801,14 @@ pass key press events to formspec!
#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.
+ColorSpec
A ColorSpec specifies a 32-bit color. It can be written in either:
+table form, each element ranging from 0..255 (a, if absent, defaults to 255):
+ colorspec = {a=255, r=0, g=255, b=0}
+numerical form, the raw integer value of an ARGB8 quad:
+ colorspec = 0xFF00FF00
+or string form, a ColorString (defined above):
+ colorspec = "green"
minetest.is_singleplayer()
minetest.features
{foo=true, bar=true}
{foo=true, bar=true}
minetest.has_feature(arg)
: returns boolean, missing_features
missing_features
: {foo=true, bar=true}
minetest.get_player_information(playername)
Example of minetest.get_player_information
return value:
{
- address = "127.0.0.1", -- IP address of client
- ip_version = 4, -- IPv4 / IPv6
- min_rtt = 0.01, -- minimum round trip time
- max_rtt = 0.2, -- maximum round trip time
- avg_rtt = 0.02, -- average round trip time
- min_jitter = 0.01, -- minimum packet time jitter
- max_jitter = 0.5, -- maximum packet time jitter
- avg_jitter = 0.03, -- average packet time jitter
- connection_uptime = 200, -- seconds since client connected
-
- -- following information is available on debug build only!!!
+minetest.get_player_information(player_name)
: returns a table containing
+ information about player. Example return value:
+ {
+ address = "127.0.0.1", -- IP address of client
+ ip_version = 4, -- IPv4 / IPv6
+ min_rtt = 0.01, -- minimum round trip time
+ max_rtt = 0.2, -- maximum round trip time
+ avg_rtt = 0.02, -- average round trip time
+ min_jitter = 0.01, -- minimum packet time jitter
+ max_jitter = 0.5, -- maximum packet time jitter
+ avg_jitter = 0.03, -- average packet time jitter
+ connection_uptime = 200, -- seconds since client connected -- following information is available on debug build only!!!
-- DO NOT USE IN MODS
--ser_vers = 26, -- serialization version used by client
--prot_vers = 23, -- protocol version used by client
@@ -1936,6 +1938,18 @@ value must (always) be two hexadecimal digits.
--state = "Active" -- current client state
}
+
+minetest.mkdir(path)
: returns success.
+- Creates a directory specified by
path
, creating parent directories
+ if they don't exist.
+minetest.get_dir_list(path, [is_dir])
: returns list of entry names
+- is_dir is one of:
+- nil: return all entries,
+- true: return only subdirectory names, or
+- false: return only file names.
+
+
+
Logging
minetest.debug(line)
@@ -2017,6 +2031,18 @@ value must (always) be two hexadecimal digits.
- Called when a player dies
+minetest.register_on_punchplayer(func(player, hitter, time_from_last_punch, tool_capabilities, dir, damage))
+- Called when a player is punched
+player
- ObjectRef - Player that was punched
+hitter
- ObjectRef - Player that hit
+time_from_last_punch
: Meant for disallowing spamming of clicks (can be nil)
+tool_capabilities
: capability table of used tool (can be nil)
+dir
: unit vector of direction of punch. Always defined. Points from
+ the puncher to the punched.
+damage
- number that represents the damage calculated by the engine
+- should return
true
to prevent the default damage mechanism
+
+
minetest.register_on_respawnplayer(func(ObjectRef))
- Called when player is to be respawned
- Called before repositioning of player occurs
@@ -2101,9 +2127,17 @@ value must (always) be two hexadecimal digits.
Setting-related
-minetest.setting_set(name, value)
+minetest.setting_set(name, value)
+- Setting names can't contain whitespace or any of
="{}#
.
+- Setting values can't contain the sequence
\n"""
.
+- Setting names starting with "secure." can't be set.
+
+
minetest.setting_get(name)
: returns string or nil
-minetest.setting_setbool(name, value)
+minetest.setting_setbool(name, value)
+- See documentation on
setting_set
for restrictions.
+
+
minetest.setting_getbool(name)
: returns boolean or nil
minetest.setting_get_pos(name)
: returns position or nil
minetest.setting_save()
, returns nil
, save all settings to config file
@@ -2677,6 +2711,12 @@ and minetest.auth_reload
call the authetification handler.
- Deprecated: An alias for the former.
+minetest.raillike_group(name)
: returns a rating
+- Returns rating of the connect_to_raillike group corresponding to name
+- If name is not yet the name of a connect_to_raillike group, a new group id
+- is created, with that name
+
+
minetest.get_content_id(name)
: returns an integer
- Gets the internal content ID of
name
@@ -2777,23 +2817,22 @@ end
the floor or ceiling
- The first four options are mutually-exclusive; the last in the list takes
precedence over the first.
-
-
-
-
-
-minetest.rotate_node(itemstack, placer, pointed_thing)
-
+minetest.rotate_node(itemstack, placer, pointed_thing)
- calls
rotate_and_place()
with infinitestacks set according to the state of
the creative mode setting, and checks for "sneak" to set the invert_wall
parameter.
+
+
+
+
minetest.forceload_block(pos)
- forceloads the position
pos
.
- returns
true
if area could be forceloaded
+- Please note that forceloaded areas are saved when the server restarts.
@@ -2802,19 +2841,32 @@ end
stops forceloading the position pos
+
+minetest.request_insecure_environment()
: returns an environment containing
+ insecure functions if the calling mod has been listed as trusted in the
+ secure.trusted_mods
setting or security is disabled, otherwise returns nil
.
+
+- Only works at init time.
+- DO NOT ALLOW ANY OTHER MODS TO ACCESS THE RETURNED ENVIRONMENT, STORE IT IN
+ A LOCAL VARIABLE!
+
+
+
+minetest.global_exists(name)
+
+- Checks if a global variable has been set, without triggering a warning.
+
+
-Please note that forceloaded areas are saved when the server restarts.
-minetest.global_exists(name)
-^ Checks if a global variable has been set, without triggering a warning.
Global objects
minetest.env
: EnvRef
of the server environment and world.
- Any function in the minetest namespace can be called using the syntax
minetest.env:somefunction(somearguments)
instead of minetest.somefunction(somearguments)
+- Deprecated, but support is not to be dropped soon
-- Deprecated, but support is not to be dropped soon
Global tables
@@ -2950,6 +3002,7 @@ Can be gotten via minetest.get_node_timer(pos)
.
set_properties(object property table)
+is_player()
: returns true for players, false otherwise
LuaEntitySAO-only (no-op for other objects)
@@ -2971,7 +3024,6 @@ Can be gotten via minetest.get_node_timer(pos)
.
Player-only (no-op for other objects)
-is_player()
: true for players, false for others
get_player_name()
: returns ""
if is not a player
get_look_dir()
: get camera direction as a unit vector
get_look_pitch()
: pitch in radians
@@ -3050,7 +3102,7 @@ Can be gotten via minetest.get_node_timer(pos)
.
set_sky(bgcolor, type, {texture names})
-bgcolor
: {r=0...255, g=0...255, b=0...255}
or nil
, defaults to white
+bgcolor
: ColorSpec, defaults to white
- Available types:
"regular"
: Uses 0 textures, bgcolor
ignored
"skybox"
: Uses 6 textures, bgcolor
used
@@ -3083,6 +3135,21 @@ Can be gotten via minetest.get_node_timer(pos)
.
- in third person view (max. values
{x=-10/10,y=-10,15,z=-5/5}
)
+get_nametag_attributes()
+- returns a table with the attributes of the nametag of the player
+- {
+ color = {a=0..255, r=0..255, g=0..255, b=0..255},
+ }
+
+
+set_nametag_attributes(attributes)
+- sets the attributes of the nametag of the player
+attributes
:
+ {
+ color = ColorSpec,
+ }
+
+
InvRef
An InvRef
is a reference to an inventory.
@@ -3202,15 +3269,29 @@ or minetest.get_perlin(noiseparams)
.
Format of size
is {x=dimx, y=dimy, z=dimz}
. The z
conponent is ommitted
for 2D noise, and it must be must be larger than 1 for 3D noise (otherwise
nil
is returned).
+For each of the functions with an optional buffer
parameter: If buffer
is not
+nil, this table will be used to store the result instead of creating a new table.
Methods
get2dMap(pos)
: returns a <size.x>
times <size.y>
2D array of 2D noise
with values starting at pos={x=,y=}
get3dMap(pos)
: returns a <size.x>
times <size.y>
times <size.z>
3D array
of 3D noise with values starting at pos={x=,y=,z=}
-get2dMap_flat(pos)
: returns a flat <size.x * size.y>
element array of 2D noise
+get2dMap_flat(pos, buffer)
: returns a flat <size.x * size.y>
element array of 2D noise
with values starting at pos={x=,y=}
-get3dMap_flat(pos)
: Same as get2dMap_flat
, but 3D noise
+get3dMap_flat(pos, buffer)
: Same as get2dMap_flat
, but 3D noise
+calc2dMap(pos)
: Calculates the 2d noise map starting at pos
. The result is stored internally.
+calc3dMap(pos)
: Calculates the 3d noise map starting at pos
. The result is stored internally.
+getMapSlice(slice_offset, slice_size, buffer)
: In the form of an array, returns a slice of the
+ most recently computed noise results. The result slice begins at coordinates slice_offset
and
+ takes a chunk of slice_size
.
+ E.g. to grab a 2-slice high horizontal 2d plane of noise starting at buffer offset y = 20:
+ noisevals = noise:getMapSlice({y=20}, {y=2})
+ It is important to note that slice_offset
offset coordinates begin at 1, and are relative to
+ the starting position of the most recently calculated noise.
+ To grab a single vertical column of noise starting at map coordinates x = 1023, y=1000, z = 1000:
+ noise:calc3dMap({x=1000, y=1000, z=1000})
+ noisevals = noise:getMapSlice({x=24, z=1}, {x=1, z=1})
VoxelManip
An interface to the MapVoxelManipulator
for Lua.
@@ -3231,8 +3312,9 @@ The map will be pre-loaded if two positions are passed to either.
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
+get_data(buffer)
: Gets the data read into the VoxelManip
object
+- returns raw node data in the form of an array of node content IDs
+- if the param
buffer
is present, this table will be used to store the result instead
set_data(data)
: Sets the data contents of the VoxelManip
object
@@ -3613,7 +3695,7 @@ minetest.spawn_tree(pos,apple_tree)
^ List can be shortened to needed length ]]
alpha = 255,
use_texture_alpha = false, -- Use texture's alpha channel
- post_effect_color = {a=0, r=0, g=0, b=0}, -- If player is inside node
+ post_effect_color = "green#0F", -- If player is inside node, see "ColorSpec"
paramtype = "none", -- See "Nodes" --[[
^ 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. ]]