Fix annotations for voxel manipulations.

This commit is contained in:
Alexander Chibrikin
2026-01-05 21:33:16 +03:00
parent cb4f88919d
commit 0e1cc45130
3 changed files with 115 additions and 99 deletions

View File

@@ -5,68 +5,84 @@
--- A helper class for voxel areas. --- A helper class for voxel areas.
--- It can be created via `VoxelArea(pmin, pmax)` or --- It can be created via `VoxelArea(pmin, pmax)` or
--- `VoxelArea:new({MinEdge = pmin, MaxEdge = pmax})`. --- `VoxelArea:new({MinEdge = pmin, MaxEdge = pmax})`.
--- The coordinates are *inclusive*, like most other things in Minetest. --- The coordinates are *inclusive*, like most other things in Luanti.
---
--- @field MinEdge Position
--- @field MaxEdge Position
--- @field ystride integer
--- @field zstride integer
VoxelArea = {} VoxelArea = {}
--- The coordinates are *inclusive*, like most other things in Minetest. --- The coordinates are *inclusive*, like most other things in Luanti.
--- ---
--- Also you can create an instance via `VoxelArea(pmin, pmax)` --- Also you can create an instance via `VoxelArea(pmin, pmax)`
--- ---
--- @param cuboid { MinEdge: any, MaxEdge: any } --- @param cuboid { MinEdge: Position, MaxEdge: Position }
--- @return VoxelArea --- @return VoxelArea
function VoxelArea:new(cuboid) end function VoxelArea:new(cuboid) end
--- returns a 3D vector containing the size of the area formed by `MinEdge` and `MaxEdge`. --- returns a 3D vector containing the size of the area formed by `MinEdge` and `MaxEdge`.
--- @return Position --- @return Position
function VoxelArea:getExtent() end function VoxelArea:getExtent() end
--- returns the volume of the area formed by `MinEdge` and `MaxEdge`. --- returns the volume of the area formed by `MinEdge` and `MaxEdge`.
--- @return number --- @return integer
function VoxelArea:getVolume() end function VoxelArea:getVolume() end
--- returns the index of an absolute position in a flat array starting at `1`. --- returns the index of an absolute position in a flat array starting at `1`.
--- * `x`, `y` and `z` must be integers to avoid an incorrect index result. --- * `x`, `y` and `z` must be integers to avoid an incorrect index result.
--- * The position (x, y, z) is not checked for being inside the area volume, --- * The position (x, y, z) is not checked for being inside the area volume,
--- being outside can cause an incorrect index result. --- being outside can cause an incorrect index result.
--- * Useful for things like `VoxelManip`, raw Schematic specifiers, --- * Useful for things like `VoxelManip`, raw Schematic specifiers,
--- `PerlinNoiseMap:get2d`/`3dMap`, and so on. --- `PerlinNoiseMap:get2d`/`3dMap`, and so on.
--- @param x number --- @param x integer
--- @param y number --- @param y integer
--- @param z number --- @param z integer
--- @return number --- @return integer
function VoxelArea:index(x, y, z) end function VoxelArea:index(x, y, z) end
--- same functionality as `index(x, y, z)` but takes a vector. --- same functionality as `index(x, y, z)` but takes a vector.
--- * As with `index(x, y, z)`, the components of `p` must be integers, and `p` --- * As with `index(x, y, z)`, the components of `p` must be integers, and `p`
--- is not checked for being inside the area volume. --- is not checked for being inside the area volume.
--- @param position Position --- @param position Position
--- @return number --- @return integer
function VoxelArea:indexp(position) end function VoxelArea:indexp(position) end
--- returns the absolute position vector corresponding to index `i`. --- returns the absolute position vector corresponding to index `i`.
--- @param i number --- @param i integer
--- @return Position --- @return Position
function VoxelArea:position(i) end function VoxelArea:position(i) end
--- check if (`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`. --- check if (`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`.
--- @param x number --- @param x integer
--- @param y number --- @param y integer
--- @param z number --- @param z integer
--- @return boolean --- @return boolean
function VoxelArea:contains(x, y, z) end function VoxelArea:contains(x, y, z) end
--- check if Position(`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`. --- check if Position(`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`.
--- @param position Position --- @param position Position
--- @return boolean --- @return boolean
function VoxelArea:containsp(position) end function VoxelArea:containsp(position) end
--- same as above, except takes an index `i`
--- same as `:containsp()`, except takes an index `i`
--- @param i integer
--- @return boolean
function VoxelArea:containsi(i) end function VoxelArea:containsi(i) end
--- returns an iterator that returns indices. --- returns an iterator that returns indices.
--- * from (`min_x`,`min_y`,`min_z`) to (`max_x`,`max_y`,`max_z`) in the order of `[z [y [x]]]`. --- * from (`min_x`,`min_y`,`min_z`) to (`max_x`,`max_y`,`max_z`) in the order of `[z [y [x]]]`.
--- @param min_x number --- @param min_x integer
--- @param min_y number --- @param min_y integer
--- @param min_z number --- @param min_z integer
--- @param max_x number --- @param max_x integer
--- @param max_y number --- @param max_y integer
--- @param max_z number --- @param max_z integer
--- @return fun(tbl: table<number, number>): number, number --- @return fun(tbl: table<number, number>): number, number
function VoxelArea:iter(min_x, min_y, min_z, max_x, max_y, max_z) end function VoxelArea:iter(min_x, min_y, min_z, max_x, max_y, max_z) end
--- returns an iterator that returns indices. --- returns an iterator that returns indices.
--- * from (`min_x`,`min_y`,`min_z`) to (`max_x`,`max_y`,`max_z`) in the order of `[z [y [x]]]`. --- * from (`min_x`,`min_y`,`min_z`) to (`max_x`,`max_y`,`max_z`) in the order of `[z [y [x]]]`.
--- @param min_pos Position --- @param min_pos Position
--- @param max_pos Position --- @param max_pos Position
--- @return fun(tbl: table<number, number>): number, number --- @return fun(tbl: table<number, number>): number, number

View File

@@ -2,95 +2,94 @@
--- @class VoxelManip --- @class VoxelManip
--- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.7.0/doc/lua_api.txt#L4244)
VoxelManip = {} VoxelManip = {}
--- Loads a chunk of map into the VoxelManip object --- Loads a chunk of map into the VoxelManip object containing the region formed by `p1` and `p2`.
--- containing the region formed by `p1` and `p2`. --- * returns actual emerged `pmin`, actual emerged `pmax`
--- * returns actual emerged `pmin`, actual emerged `pmax`
--- @param position1 Position min position for load part of map --- @param position1 Position min position for load part of map
--- @param position2 Position max position for load part of map --- @param position2 Position max position for load part of map
--- @return Position, Position --- @return Position, Position
function VoxelManip:read_from_map(position1, position2) end function VoxelManip:read_from_map(position1, position2) end
--- Writes the data loaded from the `VoxelManip` back to
--- the map. --- Writes the data loaded from the `VoxelManip` back to the map.
--- * **important**: data must be set using `VoxelManip:set_data()` before --- * **important**: data must be set using `VoxelManip:set_data()` before calling this.
--- calling this. --- * if `light` is `true`, then lighting is automatically recalculated.
--- * if `light` is true, then lighting is automatically recalculated. --- The default value is `true`.
--- The default value is true. --- If `light` is `false`, no light calculations happen, and you should correct
--- If `light` is false, no light calculations happen, and you should correct --- all modified blocks with `minetest.fix_light()` as soon as possible.
--- all modified blocks with `minetest.fix_light()` as soon as possible. --- Keep in mind that modifying the map where light is incorrect can cause more lighting bugs.
--- Keep in mind that modifying the map where light is incorrect can cause --- @param light boolean? Default: `true`
--- more lighting bugs.
--- @param light boolean? Default: true
function VoxelManip:write_to_map(light) end function VoxelManip:write_to_map(light) end
--- Returns a `MapNode` table of the node currently loaded in
--- the `VoxelManip` at that position --- Returns a `MapNode` table of the node currently loaded in the `VoxelManip` at that position.
--- @param pos Position
--- @return MapNode
function VoxelManip:get_node_at(pos) end function VoxelManip:get_node_at(pos) end
--- Sets a specific `MapNode` in the `VoxelManip` at
--- that position. --- Sets a specific `MapNode` in the `VoxelManip` at that position.
--- @param pos Position
--- @param node MapNode
function VoxelManip:set_node_at(pos, node) end function VoxelManip:set_node_at(pos, node) end
--- Retrieves the node content data loaded into the `VoxelManip` object. --- Retrieves the node content data loaded into the `VoxelManip` object.
--- * returns raw node data in the form of an array of node content IDs --- * 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 --- * if the param `buffer` is present, this table will be used to store the result instead.
--- result instead. --- @param buffer? integer[]
--- @param buffer number[]|nil --- @return integer[]
--- @return number[]
function VoxelManip:get_data(buffer) end function VoxelManip:get_data(buffer) end
--- Sets the data contents of the `VoxelManip` object --- Sets the data contents of the `VoxelManip` object
--- * expects raw node data in the form of an array of node content IDs --- * expects raw node data in the form of an array of node content IDs
--- * the array must be exactly the size of the volume of the `VoxelManip` object --- * the array must be exactly the size of the volume of the `VoxelManip` object
--- * the array must be indexed from `1` to `volume` --- * the array must be indexed from `1` to `volume`
--- * the data can be retrieved using `VoxelManip:get_data()` --- * the data can be retrieved using `VoxelManip:get_data()`
--- @param data number[] --- @param data integer[]
function VoxelManip:set_data(data) end function VoxelManip:set_data(data) end
--- Sets the data contents of the `VoxelManip` object
--- function VoxelManip:set_data(data) end
--- Does nothing, kept for compatibility. --- Does nothing, kept for compatibility.
--- function VoxelManip:update_map() end --- function VoxelManip:update_map() end
--- Set the lighting within the `VoxelManip` to --- Set the lighting within the `VoxelManip` to a uniform value.
--- a uniform value. --- * `light` is a table, `{day=<0...15>, night=<0...15>}`
--- * `light` is a table, `{day=<0...15>, night=<0...15>}` --- * To be used only by a `VoxelManip` object from `minetest.get_mapgen_object`.
--- * To be used only by a `VoxelManip` object from --- * (`p1`, `p2`) is the area in which lighting is set, defaults to the whole area if left out.
--- `minetest.get_mapgen_object`.
--- * (`p1`, `p2`) is the area in which lighting is set, defaults to the whole
--- area if left out.
function VoxelManip:set_lighting(light, p1, p2) end function VoxelManip:set_lighting(light, p1, p2) end
--- Gets the light data read into the `VoxelManip` object. --- Gets the light data read into the `VoxelManip` object.
--- * Returns an array (indices 1 to volume) of integers ranging from `0` to --- * Returns an array (indices 1 to volume) of integers ranging from `0` to `255`.
--- `255`. --- * Each value is the bitwise combination of day and night light values
--- * Each value is the bitwise combination of day and night light values --- (`0` to `15` each).
--- (`0` to `15` each). --- * `light = day + (night * 16)`
--- * `light = day + (night * 16)` --- * If the param `buffer` is present, this table will be used to store the
--- * If the param `buffer` is present, this table will be used to store the --- result instead.
--- result instead. --- @param buffer integer[]? [optional]
--- @param buffer number[]? [optional] --- @return integer[]
--- @return number[]
function VoxelManip:get_light_data(buffer) end function VoxelManip:get_light_data(buffer) end
--- Sets the `param1` (light) contents of each node in the `VoxelManip`. --- Sets the `param1` (light) contents of each node in the `VoxelManip`.
--- * expects lighting data in the same format that `get_light_data()` returns --- * expects lighting data in the same format that `get_light_data()` returns
--- @param light_data number[] --- @param light_data integer[]
function VoxelManip:set_light_data(light_data) end function VoxelManip:set_light_data(light_data) end
--- Gets the raw `param2` data read into the `VoxelManip` object. --- Gets the raw `param2` data read into the `VoxelManip` object.
--- * Returns an array (indices 1 to volume) of integers ranging from `0` to --- * Returns an array (indices 1 to volume) of integers ranging from `0` to `255`.
--- `255`. --- * If the param `buffer` is present, this table will be used to store the result instead.
--- * If the param `buffer` is present, this table will be used to store the --- @param buffer integer[]? [optional]
--- result instead. --- @return integer[]
--- @param buffer number[]? [optional]
--- @return number[]
function VoxelManip:get_param2_data(buffer) end function VoxelManip:get_param2_data(buffer) end
--- Sets the `param2` contents of each node in the `VoxelManip`. --- Sets the `param2` contents of each node in the `VoxelManip`.
--- @param param2_data number[] --- @param param2_data integer[]
function VoxelManip:set_param2_data(param2_data) end function VoxelManip:set_param2_data(param2_data) end
--- Calculate lighting within the `VoxelManip`. --- Calculate lighting within the `VoxelManip`.
--- * To be used only by a `VoxelManip` object from --- * To be used only by a `VoxelManip` object from
--- `minetest.get_mapgen_object`. --- `minetest.get_mapgen_object`.
--- * (`p1`, `p2`) is the area in which lighting is set, defaults to the whole --- * (`p1`, `p2`) is the area in which lighting is set, defaults to the whole
--- area if left out or nil. For almost all uses these should be left out --- area if left out or nil. For almost all uses these should be left out
--- or nil to use the default. --- or nil to use the default.
--- * `propagate_shadow` is an optional boolean deciding whether shadows in a --- * `propagate_shadow` is an optional boolean deciding whether shadows in a
--- generated mapchunk above are propagated down into the mapchunk, defaults --- generated mapchunk above are propagated down into the mapchunk, defaults
--- to `true` if left out. --- to `true` if left out.
--- @overload fun(p1:Position, p2:Position) --- @overload fun(p1:Position, p2:Position)
--- @overload fun(propagate_shadow:boolean) --- @overload fun(propagate_shadow:boolean)
--- @overload fun() --- @overload fun()
@@ -98,11 +97,14 @@ function VoxelManip:set_param2_data(param2_data) end
--- @param p2 Position --- @param p2 Position
--- @param propagate_shadow boolean --- @param propagate_shadow boolean
function VoxelManip:calc_lighting(p1, p2, propagate_shadow) end function VoxelManip:calc_lighting(p1, p2, propagate_shadow) end
--- Update liquid flow --- Update liquid flow
function VoxelManip:update_liquids() end function VoxelManip:update_liquids() end
--- Returns `true` or `false` if the data in the voxel --- 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 --- manipulator had been modified since the last read from map, due to a call to
--- `minetest.set_data()` on the loaded area elsewhere. --- `minetest.set_data()` on the loaded area elsewhere.
--- @return boolean
function VoxelManip:was_modified() end function VoxelManip:was_modified() end
--- Returns actual emerged minimum and maximum positions. --- Returns actual emerged minimum and maximum positions.
function VoxelManip:get_emerged_area() end function VoxelManip:get_emerged_area() end

View File

@@ -13,10 +13,14 @@
--- @class NodeTable --- @class NodeTable
--- @field name string --- @field name string
--- @field param1 number? --- @field param1 integer? 8-bit integer ranging from 0 to 255
--- @field param2 number? --- @field param2 integer? 8-bit integer ranging from 0 to 255
NodeTable = {} NodeTable = {}
--- @class MapNode: NodeTable
--- @field force_place? boolean if the node should forcibly overwrite any previous contents (default: false)
--- See ./classes/NodeMetaRef.lua --- See ./classes/NodeMetaRef.lua
--- See ./classes/VoxelArea.lua --- See ./classes/VoxelArea.lua
@@ -33,9 +37,9 @@ PseudoRandom = {}
--- See ./classes/InvRef.lua --- See ./classes/InvRef.lua
--- @class Position --- @class Position
--- @field x number --- @field x number|integer
--- @field y number --- @field y number|integer
--- @field z number --- @field z number|integer
@@ -1258,6 +1262,7 @@ function minetest.set_mapgen_params(MapgenParams) end
--- 4) Settings set as the user config default --- 4) Settings set as the user config default
--- ---
--- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5019-L5026) --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5019-L5026)
--- @return string|nil
function minetest.get_mapgen_setting(name) end function minetest.get_mapgen_setting(name) end
--- * Same as above, but returns the value as a NoiseParams table if the --- * Same as above, but returns the value as a NoiseParams table if the
--- setting `name` exists and is a valid NoiseParams. --- setting `name` exists and is a valid NoiseParams.
@@ -2161,7 +2166,7 @@ function minetest.raillike_group(name) end
--- ---
--- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5662-L5663) --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5662-L5663)
--- @param name string --- @param name string
--- @return number --- @return integer
function minetest.get_content_id(name) end function minetest.get_content_id(name) end
--- Returns a string --- Returns a string
--- * Gets the name of the content with that content ID --- * Gets the name of the content with that content ID
@@ -2391,14 +2396,7 @@ function minetest.request_insecure_environment() end
--- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5821-L5822) --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5821-L5822)
function minetest.global_exists(name) end function minetest.global_exists(name) end
-- Objects:
--- Settings object containing all of the settings from the
--- main config file (`minetest.conf`).
---
--- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4766-L4767)
--- @type table
minetest.settings = {}
--- `EnvRef` of the server environment and world. --- `EnvRef` of the server environment and world.
--- * Any function in the minetest namespace can be called using the syntax --- * Any function in the minetest namespace can be called using the syntax
--- `minetest.env:somefunction(somearguments)` --- `minetest.env:somefunction(somearguments)`