Use Lua code blocks in lua_api.md

This commit is contained in:
AFCMS 2023-04-26 20:09:08 +02:00 committed by GitHub
parent 9c90358912
commit d197ff0f9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2504 additions and 2312 deletions

@ -170,26 +170,28 @@ from the available ones of the following files:
Examples of sound parameter tables:
-- Play locationless
{
```lua
-- Play locationless
{
gain = 1.0, -- default
}
-- Play locationless, looped
{
}
-- Play locationless, looped
{
gain = 1.0, -- default
loop = true,
}
-- Play in a location
{
}
-- Play in a location
{
pos = {x = 1, y = 2, z = 3},
gain = 1.0, -- default
}
-- Play connected to an object, looped
{
}
-- Play connected to an object, looped
{
object = <an ObjectRef>,
gain = 1.0, -- default
loop = true,
}
}
```
Looped sounds must either be connected to an object or played locationless.
@ -205,7 +207,9 @@ Representations of simple things
### Position/vector
{x=num, y=num, z=num}
```lua
{x=num, y=num, z=num}
```
For helper functions see "Vector helpers".
@ -231,19 +235,27 @@ is present, mapped to a boolean of any value, the specified flag is unset.
E.g. A flag field of value
{place_center_x = true, place_center_y=false, place_center_z=true}
```lua
{place_center_x = true, place_center_y=false, place_center_z=true}
```
is equivalent to
{place_center_x = true, noplace_center_y=true, place_center_z=true}
```lua
{place_center_x = true, noplace_center_y=true, place_center_z=true}
```
which is equivalent to
"place_center_x, noplace_center_y, place_center_z"
```lua
"place_center_x, noplace_center_y, place_center_z"
```
or even
"place_center_x, place_center_z"
```lua
"place_center_x, place_center_z"
```
since, by default, no schematic attributes are set.
@ -996,14 +1008,14 @@ Please do not try to access the reference until the camera is initialized, other
* `get_fov()`
* Returns a table with X, Y, maximum and actual FOV in degrees:
```lua
```lua
{
x = number,
y = number,
max = number,
actual = number
}
```
```
* `get_pos()`
* Returns position of camera with view bobbing
@ -1053,7 +1065,7 @@ Methods:
* `get_physics_override()`
* returns:
```lua
```lua
{
speed = float,
jump = float,
@ -1062,7 +1074,7 @@ Methods:
sneak_glitch = boolean,
new_move = boolean,
}
```
```
* `get_override_pos()`
* returns override position
@ -1075,18 +1087,18 @@ Methods:
* `get_movement_acceleration()`
* returns acceleration of the player in different environments:
```lua
```lua
{
fast = float,
air = float,
default = float,
}
```
```
* `get_movement_speed()`
* returns player's speed in different environments:
```lua
```lua
{
walk = float,
jump = float,
@ -1094,19 +1106,19 @@ Methods:
fast = float,
climb = float,
}
```
```
* `get_movement()`
* returns player's movement in different environments:
```lua
```lua
{
liquid_fluidity = float,
liquid_sink = float,
liquid_fluidity_smooth = float,
gravity = float,
}
```
```
* `get_last_look_horizontal()`:
* returns last look horizontal angle
@ -1115,7 +1127,7 @@ Methods:
* `get_control()`:
* returns pressed player controls
```lua
```lua
{
up = boolean,
down = boolean,
@ -1128,7 +1140,7 @@ Methods:
dig = boolean,
place = boolean,
}
```
```
* `get_armor_groups()`
* returns a table with the armor group ratings
@ -1176,10 +1188,12 @@ Can be obtained via `minetest.get_meta(pos)`.
A raycast on the map. It works with selection boxes.
Can be used as an iterator in a for loop as:
local ray = Raycast(...)
for pointed_thing in ray do
```lua
local ray = Raycast(...)
for pointed_thing in ray do
...
end
end
```
The map is loaded as the ray advances. If the map is modified after the
`Raycast` is created, the changes may or may not have an effect on the object.
@ -1207,7 +1221,7 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
#### Node Definition
```lua
{
{
has_on_construct = bool, -- Whether the node has the on_construct callback defined
has_on_destruct = bool, -- Whether the node has the on_destruct callback defined
has_after_destruct = bool, -- Whether the node has the after_destruct callback defined
@ -1263,13 +1277,13 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
legacy_facedir_simple = bool, -- Whether to use old facedir
legacy_wallmounted = bool -- Whether to use old wallmounted
move_resistance = <number>, -- How slow players can move through the node *May not exist*
}
}
```
#### Item Definition
```lua
{
{
name = string, -- Name of the item e.g. "default:stone"
description = string, -- Description of the item e.g. "Stone"
type = string, -- Item type: "none", "node", "craftitem", "tool"
@ -1286,18 +1300,21 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
sound_place = SimpleSoundSpec, -- Sound played when placed
sound_place_failed = SimpleSoundSpec, -- Sound played when placement failed
node_placement_prediction = string -- Node placed in client until server catches up
}
}
```
-----------------
### Chat command definition (`register_chatcommand`)
{
```lua
{
params = "<name> <privilege>", -- Short parameter description
description = "Remove privilege from player", -- Full description
func = function(param), -- Called when command is run.
-- Returns boolean success and text output.
}
}
```
### Server info
```lua
{
@ -1309,29 +1326,30 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
```
### HUD Definition (`hud_add`, `hud_get`)
```lua
{
{
hud_elem_type = "image", -- see HUD element types, default "text"
-- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
-- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
position = {x=0.5, y=0.5},
-- ^ Left corner position of element, default `{x=0,y=0}`.
-- ^ Left corner position of element, default `{x=0,y=0}`.
name = "<name>", -- default ""
scale = {x=2, y=2}, -- default {x=0,y=0}
text = "<text>", -- default ""
number = 2, -- default 0
item = 3, -- default 0
-- ^ Selected item in inventory. 0 for no item selected.
-- ^ Selected item in inventory. 0 for no item selected.
direction = 0, -- default 0
-- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
-- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
alignment = {x=0, y=0}, -- default {x=0, y=0}
-- ^ See "HUD Element Types"
-- ^ See "HUD Element Types"
offset = {x=0, y=0}, -- default {x=0, y=0}
-- ^ See "HUD Element Types"
-- ^ See "HUD Element Types"
size = { x=100, y=100 }, -- default {x=0, y=0}
-- ^ Size of element in pixels
-- ^ Size of element in pixels
style = 0,
-- ^ For "text" elements sets font style: bitfield with 1 = bold, 2 = italic, 4 = monospace
}
-- ^ For "text" elements sets font style: bitfield with 1 = bold, 2 = italic, 4 = monospace
}
```
Escape sequences
@ -1478,7 +1496,8 @@ Same as `image`, but does not accept a `position`; the position is instead deter
### Particle definition (`add_particle`)
{
```lua
{
pos = {x=0, y=0, z=0},
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0},
@ -1499,11 +1518,13 @@ Same as `image`, but does not accept a `position`; the position is instead deter
-- ^ optional, specifies how to animate the particle texture
glow = 0
-- ^ optional, specify particle self-luminescence in darkness
}
}
```
### `ParticleSpawner` definition (`add_particlespawner`)
{
```lua
{
amount = 1,
time = 1,
-- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
@ -1529,4 +1550,5 @@ Same as `image`, but does not accept a `position`; the position is instead deter
-- ^ vertical: if true faces player using y axis only
texture = "image.png",
-- ^ Uses texture (string)
}
}
```

File diff suppressed because it is too large Load Diff

@ -22,14 +22,16 @@ Gamedata
The "gamedata" table is read when calling `core.start()`. It should contain:
{
```lua
{
playername = <name>,
password = <password>,
address = <IP/address>,
port = <port>,
selected_world = <index>, -- 0 for client mode
singleplayer = <true/false>,
}
}
```
Functions
@ -116,7 +118,8 @@ HTTP Requests
Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
{
```lua
{
url = "http://example.org",
timeout = 10,
@ -140,14 +143,16 @@ Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
multipart = boolean
-- Optional, if true performs a multipart HTTP request.
-- Default is false.
}
}
```
### `HTTPRequestResult` definition
Passed to `HTTPApiTable.fetch` callback. Returned by
`HTTPApiTable.fetch_async_get`.
{
```lua
{
completed = true,
-- If true, the request has finished (either succeeded, failed or timed
-- out)
@ -162,7 +167,8 @@ Passed to `HTTPApiTable.fetch` callback. Returned by
-- HTTP status code
data = "response"
}
}
```
Formspec
@ -209,6 +215,7 @@ GUI
* name of current renderer, e.g. "OpenGL 4.6"
* `core.get_window_info()`: Same as server-side `get_player_window_information` API.
```lua
-- Note that none of these things are constant, they are likely to change
-- as the player resizes the window and moves it between monitors
--
@ -241,6 +248,7 @@ GUI
-- Equal to the setting `hud_scaling` multiplied by `dpi / 96`
real_hud_scaling = 1,
}
```
@ -262,7 +270,7 @@ Package - content which is downloadable from the content db, may or may not be i
Ex:
```
```lua
{
mods = "/home/user/.minetest/mods",
share = "/usr/share/minetest/mods",
@ -281,7 +289,7 @@ Package - content which is downloadable from the content db, may or may not be i
* `core.get_games()` -> table of all games (possible in async calls)
* `name` in return value is deprecated, use `title` instead.
* returns a table (ipairs) with values:
```lua
{
id = <id>,
path = <full path to game>,
@ -289,12 +297,13 @@ Package - content which is downloadable from the content db, may or may not be i
title = <title of game>,
menuicon_path = <full path to menuicon>,
author = "author",
DEPRECATED:
--DEPRECATED:
addon_mods_paths = {[1] = <path>,},
}
```
* `core.get_content_info(path)`
* returns
```lua
{
name = "technical_id",
type = "mod" or "modpack" or "game" or "txp",
@ -305,18 +314,20 @@ Package - content which is downloadable from the content db, may or may not be i
depends = {"mod", "names"}, -- mods only
optional_depends = {"mod", "names"}, -- mods only
}
```
* `core.check_mod_configuration(world_path, mod_paths)`
* Checks whether configuration is valid.
* `world_path`: path to the world
* `mod_paths`: list of enabled mod paths
* returns:
```lua
{
is_consistent = true, -- true is consistent, false otherwise
unsatisfied_mods = {}, -- list of mod specs
satisfied_mods = {}, -- list of mod specs
error_message = "", -- message or nil
}
```
Logging
-------
@ -346,7 +357,7 @@ Worlds
* `core.get_worlds()` -> list of worlds (possible in async calls)
* returns
```lua
{
[1] = {
path = <full path to world>,
@ -354,6 +365,7 @@ Worlds
gameid = <gameid of world>,
},
}
```
* `core.create_world(worldname, gameid, init_settings)`
* `core.delete_world(index)`