items.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. ---@diagnostic disable: missing-return
  2. ---@meta
  3. ---Item handling
  4. ----------------
  5. -- Returns a string for making an image of a cube (useful as an item image).
  6. ---@param img1 string
  7. ---@param img2 string
  8. ---@param img3 string
  9. ---@return string
  10. function minetest.inventorycube(img1, img2, img3) end
  11. -- Returns the position of a `pointed_thing` or `nil` if the `pointed_thing`
  12. -- does not refer to a node or entity.
  13. --
  14. -- If the optional `above` parameter is true and the `pointed_thing` refers
  15. -- to a node, then it will return the `above` position of the `pointed_thing`.
  16. ---@param pointed_thing mt.PointedThing
  17. ---@param above boolean|nil
  18. ---@return mt.Vector
  19. function minetest.get_pointed_thing_position(pointed_thing, above) end
  20. -- Convert a vector to a facedir value,
  21. -- used in `param2` for `paramtype2="facedir"`.
  22. --
  23. -- Passing something non-`nil`/`false` for the optional second parameter
  24. -- causes it to take the `y` component into account.
  25. ---@param dir mt.Vector
  26. ---@param is6d boolean|nil
  27. ---@return mt.NodeParam
  28. function minetest.dir_to_facedir(dir, is6d) end
  29. -- Convert a facedir back into a vector aimed directly out the "back" of a node.
  30. ---@param facedir mt.NodeParam
  31. ---@return mt.Vector
  32. function minetest.facedir_to_dir(facedir) end
  33. -- Convert a vector to a 4dir value, used in `param2` for `paramtype2="4dir"`.
  34. ---@param dir mt.Vector
  35. ---@return string
  36. function minetest.dir_to_fourdir(dir) end
  37. -- Convert a 4dir back into a vector aimed directly out the "back" of a node.
  38. ---@param fourdir string
  39. ---@return mt.Vector
  40. function minetest.fourdir_to_dir(fourdir) end
  41. -- Convert a vector to a wallmounted value, used for `paramtype2="wallmounted"`.
  42. ---@param dir mt.Vector
  43. ---@return mt.NodeParam
  44. function minetest.dir_to_wallmounted(dir) end
  45. -- Convert a wallmounted value back into a vector
  46. -- aimed directly out the "back" of a node.
  47. ---@param wallmounted mt.ParamType2
  48. ---@return mt.Vector
  49. function minetest.wallmounted_to_dir(wallmounted) end
  50. -- Convert a vector into a yaw (angle).
  51. ---@param dir mt.Vector
  52. ---@return number
  53. function minetest.dir_to_yaw(dir) end
  54. -- Convert yaw (angle) to a vector.
  55. ---@param yaw number
  56. ---@return mt.Vector
  57. function minetest.yaw_to_dir(yaw) end
  58. -- Returns a boolean. Returns `true` if the given `paramtype2` contains
  59. -- color information (`color`, `colorwallmounted`, `colorfacedir`, etc.).
  60. ---@param ptype mt.ParamType2
  61. ---@return boolean
  62. function minetest.is_colored_paramtype(ptype) end
  63. -- Removes everything but the color information from the given `param2` value.
  64. --
  65. -- Returns `nil` if the given `paramtype2` does not contain color information.
  66. ---@param param2 mt.NodeParam
  67. ---@param paramtype2 mt.ParamType2
  68. ---@return mt.NodeParam|nil
  69. function minetest.strip_param2_color(param2, paramtype2) end
  70. -- Returns list of itemstrings that are dropped by `node` when dug
  71. -- with the item `toolname` (not limited to tools).
  72. ---@param node mt.Node|string Node as table or node name.
  73. ---@param toolname string|nil Name of the item used to dig.
  74. ---@return mt.ItemString[]
  75. function minetest.get_node_drops(node, toolname) end
  76. -- Used in `minetest.get_craft_result` and `minetest.get_craft_recipe`.
  77. ---@class mt.CraftInput
  78. ---@field method "normal"|"cooking"|"fuel"
  79. ---@field width number|nil
  80. ---@field items mt.Item[]
  81. -- Used in `minetest.get_craft_result`.
  82. ---@class mt.CraftOutput
  83. ---@field item mt.ItemStack Can be empty.
  84. ---@field time number
  85. ---@field replacements mt.ItemStack[]
  86. ---@param input mt.CraftInput
  87. ---@return mt.CraftOutput output
  88. ---@return mt.CraftInput decremented_input
  89. function minetest.get_craft_result(input) end
  90. -- Returns last registered recipe for output item (node).
  91. ---@param output mt.Node|mt.ItemString
  92. ---@return mt.CraftInput
  93. function minetest.get_craft_recipe(output) end
  94. -- Example result for `"default:gold_ingot"` with two recipes:
  95. --
  96. -- ```lua
  97. -- {
  98. -- {
  99. -- method = "cooking", width = 3,
  100. -- output = "default:gold_ingot", items = {"default:gold_lump"}
  101. -- },
  102. -- {
  103. -- method = "normal", width = 1,
  104. -- output = "default:gold_ingot 9", items = {"default:goldblock"}
  105. -- }
  106. -- }
  107. -- ```
  108. ---@class mt.AllCraftRecipes:mt.CraftInput
  109. ---@field output mt.ItemString
  110. ---@param item mt.Node
  111. ---@return mt.AllCraftRecipes|nil
  112. function minetest.get_all_craft_recipes(item) end
  113. -- Handles drops from nodes after digging:
  114. -- Default action is to put them into digger's inventory.
  115. --
  116. -- Can be overridden to get different functionality
  117. -- (e.g. dropping items on ground).
  118. ---@param pos mt.Vector
  119. ---@param drops mt.ItemString[]
  120. ---@param digger mt.ObjectRef
  121. function minetest.handle_node_drops(pos, drops, digger) end
  122. -- Creates an item string which contains palette index information
  123. -- for hardware colorization. You can use the returned string
  124. -- as an output in a craft recipe.
  125. ---@param item mt.Item
  126. ---@param palette_index integer Added to the item stack.
  127. ---@return mt.ItemString
  128. function minetest.itemstring_with_palette(item, palette_index) end
  129. -- Creates an item string which contains static color information
  130. -- for hardware colorization. Use this method if you wish to colorize
  131. -- an item that does not own a palette. You can use the returned string
  132. -- as an output in a craft recipe.
  133. ---@param item mt.Item
  134. ---@param colorstring mt.ColorString The new color of the item stack.
  135. ---@return mt.ItemString
  136. function minetest.itemstring_with_color(item, colorstring) end
  137. ---Defaults for the `on_place`, `on_drop`, `on_punch` and `on_dig`
  138. ------------------------------------------------------------------
  139. -- Default `on_place` callback for nodes.
  140. --
  141. -- Place item as a node.
  142. --
  143. -- * If `prevent_after_place` set to `true`, `after_place_node` is not called
  144. -- for the newly placed node to prevent a callback and placement loop.
  145. ---@param itemstack mt.Item
  146. ---@param placer mt.ObjectRef
  147. ---@param pointed_thing mt.PointedThing
  148. ---@param param2 mt.NodeParam|nil Overrides `facedir` and wallmounted `param2`.
  149. ---@param prevent_after_place boolean|nil
  150. ---@return mt.ItemStack, mt.Vector|nil position
  151. function minetest.item_place_node(
  152. itemstack,
  153. placer,
  154. pointed_thing,
  155. param2,
  156. prevent_after_place
  157. )
  158. end
  159. -- Place item as-is.
  160. --
  161. -- - **Note**: This function is deprecated and will never be called.
  162. ---@param itemstack mt.Item
  163. ---@param placer mt.ObjectRef
  164. ---@param pointed_thing mt.PointedThing
  165. ---@return mt.ItemStack leftover
  166. ---@deprecated
  167. function minetest.item_place_object(itemstack, placer, pointed_thing) end
  168. -- Default `on_place` callback for items.
  169. --
  170. -- Wrapper that calls `minetest.item_place_node` if appropriate.
  171. -- Calls `on_rightclick` of `pointed_thing.under` if defined instead.
  172. --
  173. -- **Note**: is not called when wielded item overrides `on_place`.
  174. ---@param itemstack mt.Item
  175. ---@param placer mt.ObjectRef
  176. ---@param pointed_thing mt.PointedThing
  177. ---@param param2 mt.NodeParam|nil Overrides facedir and wallmounted `param2`.
  178. ---@return mt.ItemStack, mt.Vector|nil position
  179. function minetest.item_place(itemstack, placer, pointed_thing, param2) end
  180. -- Runs callbacks registered by `minetest.register_on_item_pickup` and adds
  181. -- the item to the picker's `"main"` inventory list.
  182. --
  183. -- * Parameters are the same as in `on_pickup`.
  184. ---@param itemstack mt.ItemStack
  185. ---@param picker mt.ObjectRef
  186. ---@param pointed_thing mt.PointedThing
  187. ---@param time_from_last_punch number
  188. ---@param ... any
  189. ---@return mt.ItemStack leftover
  190. function minetest.item_pickup(
  191. itemstack,
  192. picker,
  193. pointed_thing,
  194. time_from_last_punch,
  195. ...
  196. )
  197. end
  198. -- Default `on_drop` callback.
  199. --
  200. -- Drop the item.
  201. ---@param itemstack mt.Item
  202. ---@param dropper mt.ObjectRef|nil
  203. ---@param pos mt.Vector
  204. ---@return mt.ItemStack leftover
  205. function minetest.item_drop(itemstack, dropper, pos) end
  206. -- Default `on_eat` callback.
  207. --
  208. -- - `replace_with_item` is the itemstring which is added to the inventory. If
  209. -- the player is eating a stack, then replace_with_item goes to a different
  210. -- spot.
  211. --
  212. -- Returns a function wrapper for `minetest.do_item_eat`.
  213. ---@param hp_change number
  214. ---@param replace_with_item mt.Item|nil
  215. ---@return fun(itemstack:mt.Item, user:mt.ObjectRef, pointed_thing:mt.PointedThing)
  216. function minetest.item_eat(hp_change, replace_with_item) end
  217. -- Default `on_punch` callback.
  218. --
  219. -- Calls functions registered by `minetest.register_on_punchnode()`.
  220. ---@param pos mt.Vector
  221. ---@param node mt.Node
  222. ---@param puncher mt.ObjectRef
  223. ---@param pointed_thing mt.PointedThing
  224. function minetest.node_punch(pos, node, puncher, pointed_thing) end
  225. -- Default `on_dig` callback.
  226. --
  227. -- - Checks if node can be dug, puts item into inventory, removes node.
  228. -- - Calls functions registered by `minetest.registered_on_dignodes()`.
  229. ---@param pos mt.Vector
  230. ---@param node mt.Node
  231. ---@param digger mt.ObjectRef
  232. function minetest.node_dig(pos, node, digger) end