node.lua 18 KB

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