misc.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. ---@diagnostic disable: missing-return
  2. ---@meta
  3. ---Storage API
  4. --------------
  5. ---Returns reference to mod private `StorageRef`.
  6. ---
  7. ---Must be called during mod load time.
  8. ---@return mt.StorageRef
  9. function minetest.get_mod_storage() end
  10. ---Misc
  11. -------
  12. ---Returns list of `ObjectRefs`.
  13. ---@return mt.PlayerObjectRef[]
  14. ---@nodiscard
  15. function minetest.get_connected_players() end
  16. ---Returns whether `obj` is a player
  17. ---@param obj mt.ObjectRef
  18. ---@return boolean
  19. ---@nodiscard
  20. function minetest.is_player(obj) end
  21. ---Returns whether player exists (regardless of online status).
  22. ---@param name string
  23. ---@return boolean
  24. ---@nodiscard
  25. function minetest.player_exists(name) end
  26. ---Replaces definition of a builtin hud element.
  27. ---@param name '"breath"'|'"health"'
  28. ---@param hud_definition mt.HUDDef
  29. function minetest.hud_replace_builtin(name, hud_definition) end
  30. ---This function can be overridden by mods to change the join message.
  31. ---@param player_name string
  32. function minetest.send_join_message(player_name) end
  33. ---This function can be overridden by mods to change the leave message.
  34. ---@param player_name string
  35. ---@param timed_out boolean
  36. function minetest.send_leave_message(player_name, timed_out) end
  37. ---Returns an 48-bit integer.
  38. ---
  39. ---Gives a unique hash number for a node position (16+16+16=48bit).
  40. ---@param pos mt.Vector
  41. ---@return integer
  42. ---@nodiscard
  43. function minetest.hash_node_position(pos) end
  44. ---Inverse transform of `minetest.hash_node_position`.
  45. ---@param hash integer
  46. ---@return mt.Vector
  47. ---@nodiscard
  48. function minetest.get_position_from_hash(hash) end
  49. ---Get rating of a group of an item. (`0` means: not in group)
  50. ---@param name string
  51. ---@param group string
  52. ---@return integer
  53. ---@nodiscard
  54. function minetest.get_item_group(name, group) end
  55. ---Get rating of a group of an item. (`0` means: not in group)
  56. ---
  57. ---An alias for `minetest.get_item_group`.
  58. ---@deprecated
  59. ---@param name string
  60. ---@param group string
  61. ---@return integer
  62. ---@nodiscard
  63. function minetest.get_node_group(name, group) end
  64. ---Returns rating of the `connect_to_raillike` group corresponding to name
  65. ---
  66. ---If name is not yet the name of a `connect_to_raillike` group, a new group id is created, with that name.
  67. ---@param name string
  68. ---@return integer
  69. ---@nodiscard
  70. function minetest.raillike_group(name) end
  71. ---Gets the internal content ID of the node `name`.
  72. ---@param name string
  73. ---@return integer
  74. ---@nodiscard
  75. function minetest.get_content_id(name) end
  76. ---Gets the name of the node with that content ID.
  77. ---@param content_id integer
  78. ---@return string
  79. ---@nodiscard
  80. function minetest.get_name_from_content_id(content_id) end
  81. ---Convert a string containing JSON data into the Lua equivalent.
  82. ---
  83. ---On success returns a table, a string, a number, a boolean or `nullvalue`.
  84. ---
  85. ---On failure outputs an error message and returns `nil`.
  86. ---
  87. ---Example: `parse_json("[10, {\"a\":false}]")`, returns `{10, {a = false}}`.
  88. ---@param string string
  89. ---@param nullvalue? any Returned in place of the JSON null; defaults to `nil`
  90. ---@return table|string|number|boolean|nil
  91. ---@nodiscard
  92. function minetest.parse_json(string, nullvalue) end
  93. ---Convert a Lua table into a JSON string.
  94. ---
  95. ---Unserializable things like functions and userdata will cause an error.
  96. ---
  97. ---**Warning**: JSON is more strict than the Lua table format.
  98. ---1. You can only use strings and positive integers of at least one as keys.
  99. ---2. You can not mix string and integer keys. This is due to the fact that JSON has two distinct array and object values.
  100. ---@param data table
  101. ---@param styled boolean|nil Human-readable format, default: false
  102. ---@return string? output
  103. ---@return string? error
  104. ---@nodiscard
  105. function minetest.write_json(data, styled) end
  106. ---Convert a table containing tables, strings, numbers, booleans and `nil`s into string form readable by `minetest.deserialize`.
  107. ---
  108. ---Example: `serialize({foo="bar"})`, returns `'return { ["foo"] = "bar" }'`.
  109. ---@param table table
  110. ---@return string
  111. ---@nodiscard
  112. function minetest.serialize(table) end
  113. ---Convert a string returned by `minetest.serialize` into a table.
  114. ---
  115. ---`string` is loaded in an empty sandbox environment.
  116. ---
  117. ---Will load functions if safe is false or omitted. Although these functions cannot directly access the global environment, they could bypass this restriction with maliciously crafted Lua bytecode if mod security is disabled.
  118. ---
  119. ---This function should not be used on untrusted data, regardless of the value of `safe`. It is fine to serialize then deserialize user-provided data, but directly providing user input to deserialize is always unsafe.
  120. ---@param string string
  121. ---@param safe? boolean
  122. ---@return table?
  123. ---@nodiscard
  124. function minetest.deserialize(string, safe) end
  125. ---Compress a string of data.
  126. ---@param data string
  127. ---@param method '"deflate"' Compression method
  128. ---@param ... integer Compression level (0-9)
  129. ---@return string
  130. ---@nodiscard
  131. function minetest.compress(data, method, ...) end
  132. ---See documentation of `minetest.compress()`.
  133. ---@param compressed_data string
  134. ---@param method '"deflate"' Compression method
  135. ---@param ... unknown
  136. ---@nodiscard
  137. function minetest.decompress(compressed_data, method, ...) end
  138. ---Returns a `ColorString` from rgb or rgba values.
  139. ---
  140. ---Each argument is a 8 Bit unsigned integer
  141. ---
  142. ---Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
  143. ---@param red integer
  144. ---@param green integer
  145. ---@param blue integer
  146. ---@param alpha? integer
  147. ---@return mt.ColorString
  148. ---@nodiscard
  149. function minetest.rgba(red, green, blue, alpha) end
  150. ---Encodes a string in base64.
  151. ---@param string string
  152. ---@return string
  153. ---@nodiscard
  154. function minetest.encode_base64(string) end
  155. ---Decodes a string encoded in base64.
  156. ---
  157. ---Padding characters are only supported starting at version `5.4.0`, where `5.5.0` and newer perform proper checks.
  158. ---@param string string
  159. ---@return string
  160. ---@nodiscard
  161. function minetest.decode_base64(string) end
  162. ---Returning `true` restricts the player `name` from modifying (i.e. digging, placing) the node at position `pos`.
  163. ---`name` will be `""` for non-players or unknown players.
  164. ---
  165. ---This function should be overridden by protection mods.
  166. ---
  167. ---It is highly recommended to grant access to players with the `protection_bypass` privilege.
  168. ---
  169. ---Cache and call the old version of this function if the position is not protected by the mod. This will allow using multiple protection mods.
  170. ---
  171. ---Example:
  172. ---```lua
  173. ---local old_is_protected = minetest.is_protected
  174. ---function minetest.is_protected(pos, name)
  175. --- if mymod:position_protected_from(pos, name) then
  176. --- return true
  177. --- end
  178. --- return old_is_protected(pos, name)
  179. ---end
  180. ---```
  181. ---@param pos mt.Vector
  182. ---@param name string
  183. ---@return boolean
  184. ---@nodiscard
  185. function minetest.is_protected(pos, name) end
  186. ---This function calls functions registered with `minetest.register_on_protection_violation`.
  187. ---@param pos mt.Vector
  188. ---@param name string
  189. function minetest.record_protection_violation(pos, name) end
  190. ---Returning `true` means that Creative Mode is enabled for player `name`.
  191. ---`name` will be `""` for non-players or if the player is unknown.
  192. ---
  193. ---This function should be overridden by Creative Mode-related mods to implement a per-player Creative Mode.
  194. ---
  195. ---By default, this function returns `true` if the setting `creative_mode` is `true` and `false` otherwise.
  196. ---@param name string
  197. ---@return boolean
  198. ---@nodiscard
  199. function minetest.is_creative_enabled(name) end
  200. ---Returns the position of the first node that `player_name` may not modify in the specified cuboid between `pos1` and `pos2`.
  201. ---
  202. ---Returns `false` if no protections were found.
  203. ---
  204. ---Applies `is_protected()` to a 3D lattice of points in the defined volume.
  205. ---
  206. ---The points are spaced evenly throughout the volume and have a spacing similar to, but no larger than, `interval`.
  207. ---
  208. ---All corners and edges of the defined volume are checked.
  209. ---
  210. ---Like `minetest.is_protected`, this function may be extended or overwritten by mods to provide a faster implementation to check the cuboid for intersections.
  211. ---@param pos1 mt.Vector
  212. ---@param pos2 mt.Vector
  213. ---@param player_name string
  214. ---@param interval integer Should be carefully chosen and maximized to avoid an excessive number of points being checked, default: 4
  215. ---@return mt.Vector|false
  216. ---@nodiscard
  217. function minetest.is_area_protected(pos1, pos2, player_name, interval) end
  218. ---Attempt to predict the desired orientation of the facedir-capable node defined by `itemstack`, and place it accordingly (on-wall, on the floor, or hanging from the ceiling).
  219. ---
  220. ---* `infinitestacks`: if `true`, the itemstack is not changed. Otherwise the stacks are handled normally.
  221. ---* `orient_flags`: Optional table containing extra tweaks to the placement code:
  222. --- * `invert_wall`: if `true`, place wall-orientation on the ground and ground-orientation on the wall.
  223. --- * `force_wall` : if `true`, always place the node in wall orientation.
  224. --- * `force_ceiling`: if `true`, always place on the ceiling.
  225. --- * `force_floor`: if `true`, always place the node on the floor.
  226. --- * `force_facedir`: if `true`, forcefully reset the facedir to north when placing on the floor or ceiling.
  227. --- * The first four options are mutually-exclusive; the last in the list takes precedence over the first.
  228. ---* `prevent_after_place` is directly passed to `minetest.item_place_node`
  229. ---
  230. ---Returns the new itemstack after placement.
  231. ---@param itemstack mt.Item
  232. ---@param placer? mt.ObjectRef
  233. ---@param pointed_thing mt.PointedThing
  234. ---@param infinitestacks boolean|nil
  235. ---@param orient_flags {invert_wall: boolean|nil, force_wall: boolean|nil, force_ceiling: boolean|nil, force_floor: boolean|nil, force_facedir: boolean|nil}
  236. ---@param prevent_after_place boolean|nil
  237. ---@return mt.ItemStack
  238. ---@nodiscard
  239. function minetest.rotate_and_place(
  240. itemstack,
  241. placer,
  242. pointed_thing,
  243. infinitestacks,
  244. orient_flags,
  245. prevent_after_place
  246. )
  247. end
  248. ---Calls `rotate_and_place()` with `infinitestacks` set according to the state of the creative mode setting, checks for "sneak" to set the `invert_wall` parameter and `prevent_after_place` set to `true`.
  249. ---@param itemstack mt.Item
  250. ---@param placer mt.ObjectRef
  251. ---@param pointed_thing mt.PointedThing
  252. function minetest.rotate_node(itemstack, placer, pointed_thing) end
  253. ---Returns the amount of knockback applied on the punched player.
  254. ---
  255. ---Arguments are equivalent to `register_on_punchplayer`, except the following:
  256. ---* `distance`: distance between puncher and punched player
  257. ---
  258. ---This function can be overridden by mods that wish to modify this behavior.
  259. ---You may want to cache and call the old function to allow multiple mods to change knockback behavior.
  260. ---@param player mt.ObjectRef
  261. ---@param hitter? mt.ObjectRef
  262. ---@param time_from_last_punch number
  263. ---@param tool_capabilities mt.ToolCaps
  264. ---@param dir mt.Vector
  265. ---@param distance number
  266. ---@param damage number
  267. ---@return number
  268. ---@nodiscard
  269. function minetest.calculate_knockback(
  270. player,
  271. hitter,
  272. time_from_last_punch,
  273. tool_capabilities,
  274. dir,
  275. distance,
  276. damage
  277. )
  278. end
  279. ---Forceloads the position `pos`.
  280. ---
  281. ---Returns `true` if area could be forceloaded.
  282. ---
  283. ---If `transient` is `false` or absent, the forceload will be persistent (saved between server runs).
  284. ---If `true`, the forceload will be transient (not saved between server runs).
  285. ---@param pos mt.Vector
  286. ---@param transient? boolean
  287. function minetest.forceload_block(pos, transient) end
  288. ---Stops forceloading the position `pos`.
  289. ---
  290. ---If `transient` is `false` or absent, frees a persistent forceload.
  291. ---If `true`, frees a transient forceload.
  292. ---@param pos mt.Vector
  293. ---@param transient? boolean
  294. function minetest.forceload_free_block(pos, transient) end
  295. ---Checks whether the mapblock at position `pos` is in the wanted condition.
  296. ---
  297. ---`condition` may be one of the following values:
  298. ---* `"unknown"`: not in memory
  299. ---* `"emerging"`: in the queue for loading from disk or generating
  300. ---* `"loaded"`: in memory but inactive (no ABMs are executed)
  301. ---* `"active"`: in memory and active
  302. ---* Other values are reserved for future functionality extensions
  303. ---
  304. ---Return value, the comparison status:
  305. ---* `false`: Mapblock does not fulfil the wanted condition
  306. ---* `true`: Mapblock meets the requirement
  307. ---* `nil`: Unsupported `condition` value
  308. ---@param pos mt.Vector
  309. ---@param condition '"unknown"'|'"emerging"'|'"loaded"'|'"active"'
  310. ---@return boolean|nil
  311. ---@nodiscard
  312. function minetest.compare_block_status(pos, condition) end
  313. ---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`.
  314. ---
  315. ---Only works at init time and must be called from the mod's main scope (ie: the init.lua of the mod, not from another Lua file or within a function).
  316. ---
  317. ---**DO NOT ALLOW ANY OTHER MODS TO ACCESS THE RETURNED ENVIRONMENT, STORE IT IN A LOCAL VARIABLE!**
  318. ---@return table?
  319. ---@nodiscard
  320. function minetest.request_insecure_environment() end
  321. ---Checks if a global variable has been set, without triggering a warning.
  322. ---@param name string
  323. ---@return boolean
  324. ---@nodiscard
  325. function minetest.global_exists(name) end