node.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. ---@diagnostic disable: redefined-local, unused-local, missing-return
  2. ---@meta
  3. ---Node definition
  4. ------------------
  5. ---Used by `minetest.register_node`.
  6. ---@alias mt.NodeDef mt.NodeDefFields|NodeDefMethods
  7. ---@class mt.NodeDefFields:mt.ItemDef
  8. ---@field drawtype mt.DrawType|nil
  9. -- * Supported for drawtypes "plantlike", "signlike", "torchlike",
  10. -- "firelike", "mesh", "nodebox", "allfaces".
  11. -- * For plantlike and firelike, the image will start at the bottom of the node.
  12. -- * For torchlike, the image will start at the surface to which the
  13. -- node "attaches".
  14. -- * For the other drawtypes the image will be centered on the node.
  15. ---@field visual_scale number|nil
  16. -- * Textures of node; +Y, -Y, +X, -X, +Z, -Z
  17. -- * Old field name was 'tile_images'.
  18. -- * List can be shortened to needed length.
  19. ---@field tiles mt.TileDef[]|nil
  20. -- Same as `tiles`, but these textures are drawn on top of the base
  21. -- tiles. You can use this to colorize only specific parts of your
  22. -- texture. If the texture name is an empty string, that overlay is not
  23. -- drawn. Since such tiles are drawn twice, it is not recommended to use
  24. -- overlays on very common nodes.
  25. ---@field overlay_tiles mt.TileDef[]|nil
  26. -- * Special textures of node; used rarely.
  27. -- * Old field name was 'special_materials'.
  28. -- * List can be shortened to needed length.
  29. ---@field special_tiles mt.TileDef[]|nil
  30. -- * The node's original color will be multiplied with this color.
  31. -- * If the node has a palette, then this setting only has an effect in
  32. -- the inventory and on the wield item.
  33. ---@field color mt.ColorSpec|nil
  34. -- Specifies how the texture's alpha channel will be used for rendering.
  35. -- possible values:
  36. -- * "opaque": Node is rendered opaque regardless of alpha channel
  37. -- * "clip": A given pixel is either fully see-through or opaque
  38. -- depending on the alpha channel being below/above 50% in value
  39. -- * "blend": The alpha channel specifies how transparent a given pixel
  40. -- of the rendered node is
  41. -- The default is "opaque" for drawtypes normal, liquid and flowingliquid;
  42. -- "clip" otherwise.
  43. -- If set to a boolean value (deprecated): true either sets it to blend
  44. -- or clip, false sets it to clip or opaque mode depending on the drawtype.
  45. ---@field use_texture_alpha "opaque"|"clip"|"blend"|nil
  46. -- * The node's `param2` is used to select a pixel from the image.
  47. -- * Pixels are arranged from left to right and from top to bottom.
  48. -- * The node's color will be multiplied with the selected pixel's color.
  49. -- * Tiles can override this behavior.
  50. -- * Only when `paramtype2` supports palettes.
  51. ---@field palette string|nil
  52. -- Screen tint if player is inside node.
  53. ---@field post_effect_color mt.ColorSpec|nil
  54. ---@field paramtype mt.ParamType|nil
  55. ---@field paramtype2 mt.ParamType2|nil
  56. -- Force value for param2 when player places node.
  57. ---@field place_param2 mt.NodeParam|nil
  58. -- If false, the cave generator and dungeon generator will not carve
  59. -- through this node.
  60. -- Specifically, this stops mod-added nodes being removed by caves and
  61. -- dungeons when those generate in a neighbor mapchunk and extend out
  62. -- beyond the edge of that mapchunk.
  63. ---@field is_ground_content boolean|nil
  64. -- If true, sunlight will go infinitely through this node.
  65. ---@field sunlight_propagates boolean|nil
  66. -- If true, objects collide with node.
  67. ---@field walkable boolean|nil
  68. -- If true, can be pointed at.
  69. ---@field pointable boolean|nil
  70. -- If false, can never be dug.
  71. ---@field diggable boolean|nil
  72. -- If true, can be climbed on (ladder).
  73. ---@field climbable boolean|nil
  74. -- Slows down movement of players through this node (max. 7).
  75. -- If this is nil, it will be equal to liquid_viscosity.
  76. -- Note: If liquid movement physics apply to the node
  77. -- (see `liquid_move_physics`), the movement speed will also be
  78. -- affected by the `movement_liquid_*` settings.
  79. ---@field move_resistance number|nil
  80. -- If true, placed nodes can replace this node.
  81. ---@field buildable_to boolean|nil
  82. -- If true, liquids flow into and replace this node.
  83. -- Warning: making a liquid node 'floodable' will cause problems.
  84. ---@field floodable boolean|nil
  85. -- * "none": no liquid flowing physics
  86. -- * "source": spawns flowing liquid nodes at all 4 sides and below;
  87. -- recommended drawtype: "liquid".
  88. -- * "flowing": spawned from source, spawns more flowing liquid nodes
  89. -- around it until `liquid_range` is reached;
  90. -- will drain out without a source;
  91. -- recommended drawtype: "flowingliquid".
  92. -- If it's "source" or "flowing" and `liquid_range > 0`, then
  93. -- both `liquid_alternative_*` fields must be specified.
  94. ---@field liquidtype "none"|"source"|"flowing"|nil
  95. -- Flowing version of source liquid.
  96. ---@field liquid_alternative_flowing string|nil
  97. -- Source version of flowing liquid.
  98. ---@field liquid_alternative_source string|nil
  99. -- Controls speed at which the liquid spreads/flows (max. 7).
  100. -- 0 is fastest, 7 is slowest.
  101. -- By default, this also slows down movement of players inside the node
  102. -- (can be overridden using `move_resistance`)
  103. ---@field liquid_viscosity number|nil
  104. -- If true, a new liquid source can be created by placing two or more
  105. -- sources nearby.
  106. ---@field liquid_renewable boolean|nil
  107. -- * false: No liquid movement physics apply.
  108. -- * true: Enables liquid movement physics. Enables things like
  109. -- ability to "swim" up/down, sinking slowly if not moving,
  110. -- smoother speed change when falling into, etc. The `movement_liquid_*`
  111. -- settings apply.
  112. -- * nil: Will be treated as true if `liquidtype ~= "none"`
  113. -- and as false otherwise.
  114. -- Default: nil
  115. ---@field liquid_move_physics boolean|nil
  116. -- Only valid for "nodebox" drawtype with 'type = "leveled"'.
  117. -- Allows defining the nodebox height without using param2.
  118. -- The nodebox height is 'leveled' / 64 nodes.
  119. -- The maximum value of 'leveled' is `leveled_max`.
  120. ---@field leveled number|nil
  121. -- Maximum value for `leveled` (0-127), enforced in
  122. -- `minetest.set_node_level` and `minetest.add_node_level`.
  123. -- Values above 124 might causes collision detection issues.
  124. ---@field leveled_max number|nil
  125. -- Maximum distance that flowing liquid nodes can spread around
  126. -- source on flat land;
  127. -- maximum = 8; set to 0 to disable liquid flow.
  128. ---@field liquid_range number|nil
  129. -- Player will take this amount of damage if no bubbles are left.
  130. ---@field drowning number|nil
  131. -- If player is inside node, this damage is caused.
  132. ---@field damage_per_second number|nil
  133. ---@field node_box mt.NodeBox|nil
  134. -- Used for nodebox nodes with the type == "connected".
  135. -- Specifies to what neighboring nodes connections will be drawn.
  136. -- e.g. `{"group:fence", "default:wood"}` or `"default:stone"`.
  137. ---@field connects_to string[]|nil
  138. -- Tells connected nodebox nodes to connect only to these sides of this node.
  139. ---@field connect_sides string[]|nil
  140. -- File name of mesh when using "mesh" drawtype.
  141. ---@field mesh string|nil
  142. -- Custom selection box definition. Multiple boxes can be defined.
  143. -- If "nodebox" drawtype is used and selection_box is nil, then node_box
  144. -- definition is used for the selection box.
  145. ---@field selection_box mt.NodeBox|nil
  146. -- Custom collision box definition. Multiple boxes can be defined.
  147. -- If "nodebox" drawtype is used and collision_box is nil, then node_box
  148. -- definition is used for the collision box.
  149. --
  150. -- Support maps made in and before January 2012.
  151. ---@field collision_box mt.NodeBox|nil
  152. ---@field legacy_facedir_simple boolean|nil
  153. ---@field legacy_wallmounted boolean|nil
  154. -- Valid for drawtypes:
  155. -- mesh, nodebox, plantlike, allfaces_optional, liquid, flowingliquid.
  156. -- 1 - wave node like plants (node top moves side-to-side, bottom is fixed)
  157. -- 2 - wave node like leaves (whole node moves side-to-side)
  158. -- 3 - wave node like liquids (whole node moves up and down)
  159. -- Not all models will properly wave.
  160. -- plantlike drawtype can only wave like plants.
  161. -- allfaces_optional drawtype can only wave like leaves.
  162. -- liquid, flowingliquid drawtypes can only wave like liquids.
  163. ---@field waving number|nil
  164. ---@field sounds mt.NodeSoundsDef|nil
  165. ---@field drop string|mt.NodeDropDef|nil
  166. ---@field drops (string|mt.NodeDropDef)[]|nil
  167. -- * Stores which mod actually registered a node.
  168. -- * If it can not find a source, returns "??".
  169. -- * Useful for getting what mod truly registered something.
  170. -- * Example: if a node is registered as ":othermodname:nodename",
  171. -- nodename will show "othermodname", but mod_origin will say "modname"
  172. ---@field mod_origin string|nil
  173. ---@class NodeDefMethods
  174. local node = {}
  175. -- * Node constructor; called after adding node.
  176. -- * Can set up metadata and stuff like that.
  177. -- * Not called for bulk node placement (i.e. schematics and VoxelManip).
  178. -- * Default: `nil`.
  179. ---@param pos mt.Vector
  180. function node.on_construct(pos) end
  181. -- * Node destructor; called before removing node.
  182. -- * Not called for bulk node placement.
  183. -- * Default: `nil`.
  184. ---@param pos mt.Vector
  185. function node.on_destruct(pos) end
  186. -- * Node destructor; called after removing node.
  187. -- * Not called for bulk node placement.
  188. -- * Default: `nil`.
  189. ---@param pos mt.Vector
  190. ---@param oldnode mt.Node
  191. function node.after_destruct(pos, oldnode) end
  192. -- * Called when a liquid (newnode) is about to flood oldnode, if it has
  193. -- `floodable = true` in the nodedef.
  194. -- * Not called for bulk node placement (i.e. schematics and VoxelManip)
  195. -- or air nodes.
  196. -- * If return true the node is not flooded, but on_flood callback will most
  197. -- likely be called over and over again every liquid update interval.
  198. -- * Default: `nil`.
  199. -- * Warning: making a liquid node 'floodable' will cause problems.
  200. ---@param pos mt.Vector
  201. ---@param oldnode mt.Node
  202. ---@param newnode mt.Node
  203. function node.on_flood(pos, oldnode, newnode) end
  204. -- * Called when oldnode is about be converted to an item, but before the
  205. -- node is deleted from the world or the drops are added.
  206. -- * This is generally the result of either the node being dug or an attached
  207. -- node becoming detached.
  208. -- * Default: `nil`.
  209. ---@param pos mt.Vector
  210. ---@param oldnode mt.Node
  211. ---@param oldmeta mt.NodeMetaRef Old node before deletion.
  212. ---@param drops table<unknown, mt.Item>
  213. function node.preserve_metadata(pos, oldnode, oldmeta, drops) end
  214. -- * Called after constructing node when node was placed using
  215. -- `minetest.item_place_node` / `minetest.place_node`.
  216. -- * If return true no item is taken from itemstack.
  217. -- * Default: `nil`.
  218. ---@param pos mt.Vector
  219. ---@param placer mt.ObjectRef|nil
  220. ---@param itemstack mt.Item
  221. ---@param pointed_thing mt.PointedThing
  222. function node.after_place_node(pos, placer, itemstack, pointed_thing) end
  223. -- * Called after destructing node when node was dug using
  224. -- `minetest.node_dig` / `minetest.dig_node`.
  225. -- * Default: `nil`.
  226. ---@param pos mt.Vector
  227. ---@param oldnode mt.Node
  228. ---@param oldmetadata table
  229. ---@param digger mt.ObjectRef
  230. function node.after_dig_node(pos, oldnode, oldmetadata, digger) end
  231. -- * Returns true if node can be dug, or false if not.
  232. -- * Default: `nil`.
  233. ---@param pos mt.Vector
  234. ---@param player mt.ObjectRef
  235. ---@return boolean
  236. function node.can_dig(pos, player) end
  237. -- * Default: `minetest.node_punch`.
  238. -- * Called when puncher punches the `node` at `pos`.
  239. -- * By default calls `minetest.register_on_punchnode` callbacks.
  240. ---@param pos mt.Vector
  241. ---@param node mt.Node
  242. ---@param puncher mt.ObjectRef
  243. ---@param pointed_thing mt.PointedThing
  244. function node.on_punch(pos, node, puncher, pointed_thing) end
  245. -- * Called when clicker used the 'place/build' key
  246. -- (not necessarily an actual rightclick)
  247. -- while pointing at the node at pos with 'node' being the node table.
  248. -- * `itemstack` will hold clicker's wielded item.
  249. -- * Shall return the leftover itemstack.
  250. -- * Note: pointed_thing can be nil, if a mod calls this function.
  251. -- * This function does not get triggered by clients <=0.4.16 if the
  252. -- "formspec" node metadata field is set.
  253. -- * Default: `nil`.
  254. ---@param pos mt.Vector
  255. ---@param node mt.Node
  256. ---@param clicker mt.ObjectRef
  257. ---@param itemstack mt.Item
  258. ---@param pointed_thing mt.PointedThing|nil
  259. ---@return mt.ItemStack|nil leftover
  260. function node.on_rightclick(pos, node, clicker, itemstack, pointed_thing) end
  261. -- * Default: `minetest.node_dig`.
  262. -- * By default checks privileges, wears out item (if tool) and removes node.
  263. -- * Return `true` if the node was dug successfully, `false` otherwise.
  264. -- * Deprecated: returning nil is the same as returning true.
  265. ---@param pos mt.Vector
  266. ---@param node mt.Node
  267. ---@param digger mt.ObjectRef
  268. ---@return boolean
  269. function node.on_dig(pos, node, digger) end
  270. -- * Called by NodeTimers, see `minetest.get_node_timer` and `mt.NodeTimerRef`.
  271. -- * Return `true` to run the timer for another cycle with the same timeout.
  272. -- * Default: `nil`.
  273. ---@param pos mt.Vector
  274. ---@param elapsed number The total time passed since the timer was started.
  275. ---@return boolean
  276. function node.on_timer(pos, elapsed) end
  277. -- * Called when an UI form (e.g. sign text input) returns data.
  278. -- * See `minetest.register_on_player_receive_fields` for more info.
  279. -- * Default: `nil`.
  280. ---@param pos mt.Vector
  281. ---@param formname string
  282. ---@param fields table<string, unknown> Name = Value.
  283. ---@param sender mt.ObjectRef
  284. function node.on_receive_fields(pos, formname, fields, sender) end
  285. -- * If defined, called when an explosion touches the node,
  286. -- instead of removing the node.
  287. ---@param pos mt.Vector
  288. ---@param intensity number 1.0 = mid range of regular TNT.
  289. function node.on_blast(pos, intensity) end
  290. -- Called when a player wants to move items inside the inventory.
  291. --
  292. -- * Return value: number of items allowed to move.
  293. -- * Moving items in the inventory.
  294. -- * The `allow_*` callbacks return how many items can be moved.
  295. -- * This callback triggered `before` the action.
  296. ---@param pos mt.Vector
  297. ---@param from_list unknown
  298. ---@param from_index integer
  299. ---@param to_list unknown
  300. ---@param to_index integer
  301. ---@param count integer
  302. ---@param player mt.ObjectRef
  303. ---@return integer allowed
  304. function node.allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) end
  305. -- Called after the actual action has happened, according to what was allowed.
  306. --
  307. -- * No return value.
  308. ---@param pos mt.Vector
  309. ---@param from_list unknown
  310. ---@param from_index integer
  311. ---@param to_list unknown
  312. ---@param to_index integer
  313. ---@param count integer
  314. ---@param player mt.ObjectRef
  315. function node.on_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) end
  316. -- Called when a player wants to put something into the inventory.
  317. --
  318. -- * Return value: number of items allowed to put.
  319. -- * Return value -1: Allow and don't modify item count in inventory.
  320. -- * Putting items to the inventory.
  321. -- * The `allow_*` callbacks return how many items can be moved.
  322. -- * This callback triggered `before` the action.
  323. ---@param pos mt.Vector
  324. ---@param listname string
  325. ---@param index integer
  326. ---@param stack mt.Item
  327. ---@param player mt.ObjectRef
  328. ---@return integer allowed
  329. function node.allow_metadata_inventory_put(pos, listname, index, stack, player) end
  330. -- Called after the actual action has happened, according to what was allowed.
  331. --
  332. -- * No return value.
  333. -- * Moving items in the inventory.
  334. -- * The `on_*` callbacks are called after the items have been placed in the inventories.
  335. -- * This callback triggered `after` the action.
  336. ---@param pos mt.Vector
  337. ---@param listname string
  338. ---@param index integer
  339. ---@param stack mt.Item
  340. ---@param player mt.ObjectRef
  341. function node.on_metadata_inventory_put(pos, listname, index, stack, player) end
  342. -- Called when a player wants to take something out of the inventory.
  343. --
  344. -- * Return value: number of items allowed to take.
  345. -- * Return value -1: Allow and don't modify item count in inventory.
  346. -- * Taking items from the inventory.
  347. -- * The `allow_*` callbacks return how many items can be moved.
  348. -- * This callback triggered `before` the action.
  349. ---@param pos mt.Vector
  350. ---@param listname string
  351. ---@param index integer
  352. ---@param stack mt.Item
  353. ---@param player mt.ObjectRef
  354. ---@return integer allowed
  355. function node.allow_metadata_inventory_take(pos, listname, index, stack, player) end
  356. -- Called after the actual action has happened, according to what was allowed.
  357. --
  358. -- * No return value.
  359. -- * Taking items from the inventory.
  360. -- * The `on_*` callbacks are called after the items have been placed in the inventories.
  361. -- * This callback triggered `after` the action.
  362. ---@param pos mt.Vector
  363. ---@param listname string
  364. ---@param index integer
  365. ---@param stack mt.Item
  366. ---@param player mt.ObjectRef
  367. function node.on_metadata_inventory_take(pos, listname, index, stack, player) end
  368. -- * Definition of node sounds to be played at various events.
  369. -- * All fields in this table are optional.
  370. ---@class mt.NodeSoundsDef
  371. -- * If walkable, played when object walks on it.
  372. -- * If node is climbable or a liquid, played when object moves through it.
  373. ---@field footstep mt.SimpleSoundSpec
  374. -- * While digging node.
  375. -- * If `"__group"`, then the sound will be `default_dig_<groupname>`,
  376. -- where `<groupname>` is the name of the item's digging group
  377. -- with the fastest digging time.
  378. -- * In case of a tie, one of the sounds will be played (but we
  379. -- cannot predict which one)
  380. -- * Default value: `"__group"`
  381. ---@field dig mt.SimpleSoundSpec|"__group"
  382. ---@field dug mt.SimpleSoundSpec Node was dug.
  383. ---@field place mt.SimpleSoundSpec Node was placed. Also played after falling.
  384. -- * When node placement failed.
  385. -- * Note: This happens if the _built-in_ node placement failed.
  386. -- * This sound will still be played if the node is placed in the
  387. -- `on_place` callback manually.
  388. ---@field place_failed mt.SimpleSoundSpec
  389. ---@field fall mt.SimpleSoundSpec When node starts to fall or is detached.
  390. ---@class mt.NodeDropDef
  391. -- * Maximum number of item lists to drop.
  392. -- * The entries in 'items' are processed in order. For each:
  393. -- Item filtering is applied, chance of drop is applied, if both are
  394. -- successful the entire item list is dropped.
  395. -- * Entry processing continues until the number of dropped item lists
  396. -- equals 'max_items'.
  397. -- * Therefore, entries should progress from low to high drop chance.
  398. ---@field max_items integer
  399. ---@field items mt.NodeDropItemsDef
  400. ---@class mt.NodeDropItemsDef
  401. -- 1 in 1000 chance of dropping a diamond.
  402. -- Default rarity is '1'.
  403. ---@field rarity integer
  404. -- List of item names.
  405. ---@field items string[]
  406. -- List of tool names.
  407. ---@field tools string[]
  408. -- Only drop if using an item in the "magicwand" group, or an item that is
  409. -- in both the "pickaxe" and the "lucky" groups:
  410. -- ```lua
  411. -- tool_groups = {
  412. -- "magicwand",
  413. -- {"pickaxe", "lucky"}
  414. -- }
  415. -- ```
  416. ---@field tool_groups (string|string[])[]
  417. -- Whether all items in the dropped item list inherit the
  418. -- hardware coloring palette color from the dug node.
  419. -- * Default is 'false'.
  420. ---@field inherit_color boolean