mapgen.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. ---@meta
  2. ---Lua Voxel Manipulator
  3. ------------------------
  4. --[[
  5. VoxelManip is a scripting interface to the internal 'Map Voxel Manipulator'
  6. facility. The purpose of this object is for fast, low-level, bulk access to
  7. reading and writing Map content. As such, setting map nodes through VoxelManip
  8. will lack many of the higher level features and concepts you may be used to
  9. with other methods of setting nodes. For example, nodes will not have their
  10. construction and destruction callbacks run, and no rollback information is
  11. logged.
  12. It is important to note that VoxelManip is designed for speed, and *not* ease
  13. of use or flexibility. If your mod requires a map manipulation facility that
  14. will handle 100% of all edge cases, or the use of high level node placement
  15. features, perhaps `minetest.set_node()` is better suited for the job.
  16. In addition, VoxelManip might not be faster, or could even be slower, for your
  17. specific use case. VoxelManip is most effective when setting large areas of map
  18. at once - for example, if only setting a 3x3x3 node area, a
  19. `minetest.set_node()` loop may be more optimal. Always profile code using both
  20. methods of map manipulation to determine which is most appropriate for your
  21. usage.
  22. A recent simple test of setting cubic areas showed that `minetest.set_node()`
  23. is faster than a VoxelManip for a 3x3x3 node cube or smaller.
  24. ]]
  25. ---@class mt.VoxelManip
  26. local VoxelManip = {}
  27. ---Loads a chunk of map into the VoxelManip object
  28. ---containing the region formed by `p1` and `p2`.
  29. ---@param p1 mt.Vector
  30. ---@param p2 mt.Vector
  31. ---@return mt.Vector
  32. ---@return mt.Vector
  33. function VoxelManip:read_from_map(p1, p2) end
  34. ---Writes the data loaded from the `VoxelManip` back to the map.
  35. ---@param light boolean|nil `true` by default
  36. ---* If `light` is true, then lighting is automatically recalculated.
  37. ---* If `light` is false, no light calculations happen, and you should correct
  38. ---all modified blocks with `minetest.fix_light()` as soon as possible.
  39. ---
  40. ---Keep in mind that modifying the map where light is incorrect can cause
  41. ---more lighting bugs.
  42. function VoxelManip:write_to_map(light) end
  43. ---Returns a `MapNode` table of the node currently loaded in
  44. ---the `VoxelManip` at that position.
  45. ---@param pos mt.Vector
  46. ---@return mt.MapNode
  47. function VoxelManip:get_node_at(pos) end
  48. ---Sets a specific `MapNode` in the `VoxelManip` at that position.
  49. ---@param pos mt.Vector
  50. ---@param node mt.MapNode
  51. function VoxelManip:set_node_at(pos, node) end
  52. ---Retrieves the node content data loaded into the `VoxelManip` object.
  53. ---@param buffer? table If present, will be used to store the result.
  54. ---@return integer[] # Raw node data in the form of an array of node content IDs.
  55. function VoxelManip:get_data(buffer) end
  56. ---Sets the data contents of the `VoxelManip` object
  57. ---@param data integer[]
  58. function VoxelManip:set_data(data) end
  59. ---Does nothing, kept for compatibility.
  60. function VoxelManip:update_map() end
  61. ---Set the lighting within the `VoxelManip` to a uniform value.
  62. ---To be used only by a `VoxelManip` object from
  63. ---`minetest.get_mapgen_object`.
  64. ---@param light {day: integer, night: integer}
  65. ---@param p1 mt.Vector
  66. ---@param p2 mt.Vector
  67. ---* light constraints: `{day=<0...15>, night=<0...15>}`
  68. ---* (`p1`, `p2`) is the area in which lighting is set, defaults to the whole
  69. ---area if left out.
  70. function VoxelManip:set_lighting(light, p1, p2) end
  71. --- Gets the light data read into the `VoxelManip` object
  72. ---@param buffer? integer[] if present, will be used to store the result
  73. ---@return integer[]? # array of integers ranging from `0` to `255`.
  74. ---Each value is the bitwise combination of day and night light values
  75. ---(`0` to `15` each). `light = day + (night * 16)`
  76. function VoxelManip:get_light_data(buffer) end
  77. ---Sets the `param1` (light) contents of each node in the `VoxelManip`.
  78. ---Expects lighting data in the same format that `get_light_data()` returns
  79. ---@param light_data integer[] # integer range is `0` to `255`.
  80. ---Each value is the bitwise combination of day and night light values
  81. ---(`0` to `15` each). `light = day + (night * 16)`
  82. function VoxelManip:set_light_data(light_data) end
  83. ---Gets the raw `param2` data read into the `VoxelManip` object.
  84. ---@return integer[]? # array of integers ranging from `0` to `255`.
  85. ---@param buffer? table if is present, this table
  86. ---will be used to store the result instead.
  87. function VoxelManip:get_param2_data(buffer) end
  88. ---Sets the `param2` contents of each node in the `VoxelManip`.
  89. ---@param param2_data integer[] array of integers ranging from `0` to `255`.
  90. function VoxelManip:set_param2_data(param2_data) end
  91. ---Calculate lighting within the `VoxelManip`.
  92. ---@param p1? mt.Vector
  93. ---@param p2? mt.Vector
  94. ---@param propagate_shadow boolean
  95. ---* To be used only by a `VoxelManip` object from
  96. --- `minetest.get_mapgen_object`.
  97. ---* (`p1`, `p2`) is the area in which lighting is set, defaults to the whole
  98. --- area if left out or nil. For almost all uses these should be left out
  99. --- or nil to use the default.
  100. ---* `propagate_shadow` is an optional boolean deciding whether shadows in a
  101. --- generated mapchunk above are propagated down into the mapchunk, defaults
  102. --- to `true` if left out.
  103. function VoxelManip:calc_lighting(p1, p2, propagate_shadow) end
  104. ---Update liquid flow
  105. function VoxelManip:update_liquids() end
  106. ---Returns `true` if the data in the voxel manipulator
  107. ---had been modified since the last read from map, due to a call to
  108. ---`minetest.set_data()` on the loaded area elsewhere.
  109. ---@return boolean
  110. function VoxelManip:was_modified() end
  111. ---@return mt.Vector # actual emerged minimum position
  112. ---@return mt.Vector # actual emerged maximum position
  113. function VoxelManip:get_emerged_area() end
  114. -- A helper class for voxel areas.
  115. --
  116. -- The coordinates are *inclusive*, like most other things in Minetest.
  117. ---@class mt.VoxelArea
  118. VoxelArea = {}
  119. -- VoxelArea constructor.
  120. ---@param def {MinEdge:mt.Vector, MaxEdge:mt.Vector}
  121. ---@return mt.VoxelArea
  122. function VoxelArea:new(def) end
  123. -- VoxelArea constructor.
  124. ---@param pmin mt.Vector
  125. ---@param pmax mt.Vector
  126. ---@return mt.VoxelArea
  127. function VoxelArea(pmin, pmax) end
  128. -- Returns a 3D vector containing the size of the area formed by `MinEdge` and `MaxEdge`.
  129. ---@return mt.Vector
  130. function VoxelArea:getExtent() end
  131. -- Returns the volume of the area formed by `MinEdge` and `MaxEdge`.
  132. ---@return number
  133. function VoxelArea:getVolume() end
  134. -- Returns the index of an absolute position in a flat array starting at `1`.
  135. ---@param x integer
  136. ---@param y integer
  137. ---@param z integer
  138. ---@return integer
  139. function VoxelArea:index(x, y, z) end
  140. -- Returns the index of an absolute position in a flat array starting at `1`.
  141. --
  142. -- As with `index(x, y, z)`, the components of `p` must be integers, and `p`
  143. -- is not checked for being inside the area volume.
  144. ---@param p mt.Vector
  145. ---@return integer
  146. function VoxelArea:indexp(p) end
  147. -- Returns the absolute position vector corresponding to index `i`.
  148. ---@param i integer
  149. ---@return mt.Vector
  150. function VoxelArea:position(i) end
  151. -- Check if (`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`.
  152. ---@param x number
  153. ---@param y number
  154. ---@param z number
  155. ---@return boolean
  156. function VoxelArea:contains(x, y, z) end
  157. -- Check if `p` is inside area formed by `MinEdge` and `MaxEdge`.
  158. ---@param p mt.Vector
  159. ---@return boolean
  160. function VoxelArea:containsp(p) end
  161. -- Check if index `i` is inside area formed by `MinEdge` and `MaxEdge`.
  162. ---@param i integer
  163. ---@return boolean
  164. function VoxelArea:containsi(i) end
  165. -- Returns an iterator that returns indexes from (`minx`,`miny`,`minz`)
  166. -- to (`maxx`,`maxy`,`maxz`) in the order of `[z [y [x]]]`.
  167. ---@param minx number
  168. ---@param miny number
  169. ---@param minz number
  170. ---@param maxx number
  171. ---@param maxy number
  172. ---@param maxz number
  173. ---@return fun(): integer index
  174. function VoxelArea:iter(minx, miny, minz, maxx, maxy, maxz) end
  175. -- Returns an iterator that returns indexes in the order of `[z [y [x]]]`.
  176. ---@param minp mt.Vector
  177. ---@param maxp mt.Vector
  178. ---@return fun(): integer index
  179. function VoxelArea:iterp(minp, maxp) end
  180. --[[
  181. For a particular position in a voxel area, whose flat array index is known,
  182. it is often useful to know the index of a neighboring or nearby position.
  183. The table below shows the changes of index required for 1 node movements along
  184. the axes in a voxel area:
  185. Movement Change of index
  186. +x +1
  187. -x -1
  188. +y +ystride
  189. -y -ystride
  190. +z +zstride
  191. -z -zstride
  192. If, for example:
  193. local area = VoxelArea(emin, emax)
  194. The values of `ystride` and `zstride` can be obtained using `area.ystride` and
  195. `area.zstride`.
  196. ]]
  197. ---@alias mt.VoxelAreaStride number
  198. ---@type mt.VoxelAreaStride
  199. VoxelArea.ystride = nil
  200. ---@type mt.VoxelAreaStride
  201. VoxelArea.zstride = nil
  202. ---@class mt.GenNotify
  203. ---A table mapping requested generation notification types to arrays of
  204. ---positions at which the corresponding generated structures are located within
  205. ---the current chunk. To enable the capture of positions of interest to be recorded
  206. ---call `minetest.set_gen_notify()` first.
  207. ---@field dungeon mt.Vector[] bottom center position of dungeon rooms
  208. ---@field temple mt.Vector[] bottom center position of desert temples (mgv6 only)
  209. ---@field cave_begin mt.Vector[]
  210. ---@field cave_end mt.Vector[]
  211. ---@field large_cave_begin mt.Vector[]
  212. ---@field large_cave_end mt.Vector[]
  213. ---@field [string] mt.Vector[] key format is `"decoration#id"` (see below)
  214. ---Decorations keys are in format `"decoration#id"`, where `id` is the
  215. ---numeric unique decoration ID as returned by `minetest.get_decoration_id()`.
  216. ---For example, `"decoration#123"`.
  217. ---@alias mt.MapgenObject mt.VoxelManip|mt.GenNotify|table