item.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ---@meta
  2. ---Item definition
  3. ------------------
  4. -- Used by `minetest.register_node`, `minetest.register_craftitem`, and
  5. -- `minetest.register_tool`.
  6. ---@class mt.ItemDef
  7. ---@field name string|nil
  8. ---@field type string|nil
  9. ---Item's description.
  10. ---
  11. ---Can contain new lines. `"\n"` has to be used as new line character.
  12. ---@field description string|nil
  13. ---Short item description.
  14. ---
  15. ---Must not contain new lines.
  16. ---
  17. ---Default: `nil`
  18. ---@field short_description string|nil
  19. ---Item groups.
  20. ---
  21. ---key = name, value = rating; rating = 1..3.
  22. ---
  23. ---If rating not applicable, use 1.
  24. ---
  25. ---* `{wool = 1, fluffy = 3}`
  26. ---* `{soil = 2, outerspace = 1, crumbly = 1}`
  27. ---* `{bendy = 2, snappy = 1}`
  28. ---* `{hard = 1, metal = 1, spikes = 1}`
  29. ---@field groups mt.ObjectGroups|nil
  30. ---Item inventory texture.
  31. ---@field inventory_image string|nil
  32. ---An overlay to the inventory texture which does not get colorized.
  33. ---@field inventory_overlay string|nil
  34. ---Item wielded texture.
  35. ---@field wield_image string|nil
  36. ---An overlay to the wielded texture which does not get colorized.
  37. ---@field wield_overlay string|nil
  38. ---An texture containing the palette of an item.
  39. ---
  40. ---You can set the currently used color as the `"palette_index"` field of the item stack metadata.
  41. ---
  42. ---The palette is always stretched to fit indices between `0` and `255`, to ensure compatibility with `"colorfacedir"` and `"colorwallmounted"` nodes.
  43. ---@field palette string|nil
  44. ---The color of the item. The palette overrides this.
  45. ---@field color mt.ColorSpec|nil
  46. ---The scale the item will have in the player hand.
  47. ---@field wield_scale mt.Vector|nil
  48. ---How much items can be stacked together.
  49. ---
  50. ---The default value of `99` may be configured by users using the setting `"default_stack_max"`.
  51. ---@field stack_max integer|nil
  52. ---How far will the player be able to aim with this node as hand.
  53. ---@field range number|nil
  54. ---If true, item points to all liquid nodes (`liquidtype ~= "none"`), even those for which `pointable = false`.
  55. ---@field liquids_pointable boolean|nil
  56. ---* **When used for nodes:** Defines amount of light emitted by node.
  57. ---* **Otherwise:** Defines texture glow when viewed as a dropped item
  58. ---
  59. ---To set the maximum (`14`), use the value `minetest.LIGHT_MAX`.
  60. ---
  61. ---A value outside the range `0` to `minetest.LIGHT_MAX` causes undefined behavior.
  62. ---
  63. ---Default: `0`
  64. ---@field light_source integer|nil
  65. ---Define the tool capabilities.
  66. ---@field tool_capabilities mt.ToolCaps|nil
  67. ---Define client-side placement prediction.
  68. ---
  69. ---* If `nil` and item is node, prediction is made automatically.
  70. ---* If `nil` and item is not a node, no prediction is made.
  71. ---* If `""` and item is anything, no prediction is made.
  72. ---
  73. ---Otherwise should be name of node which the client immediately places on ground when the player places the item.
  74. ---
  75. ---Server will always update actual result shortly.
  76. ---@field node_placement_prediction string|nil
  77. ---Define client-side dig prediction.
  78. ---
  79. ---* If `""`, no prediction is made.
  80. ---* If `"air"`, node is removed.
  81. ---
  82. ---Otherwise should be name of node which the client immediately place upon digging.
  83. ---
  84. ---Server will always update actual result shortly.
  85. ---
  86. ---Default: `""`
  87. ---@field node_dig_prediction string|nil
  88. ---Definition of items sounds to be played at various events.
  89. ---
  90. ---All fields in this table are optional.
  91. ---
  92. ---* `breaks`: When tool breaks due to wear. Ignored for non-tools.
  93. ---* `eat`: When item is eaten with `minetest.do_item_eat`.
  94. ---@field sound {breaks: mt.SimpleSoundSpec, eat: mt.SimpleSoundSpec}|nil
  95. ---When the `place` key was pressed with the item in hand and a node was pointed at.
  96. ---
  97. ---Shall place item and return the leftover `itemstack` or `nil` to not modify the inventory.
  98. ---
  99. ---The placer may be any `ObjectRef` or `nil`.
  100. ---
  101. ---default: `minetest.item_place`
  102. ---@field on_place nil|fun(itemstack: mt.ItemStack, placer?: mt.ObjectRef, pointed_thing: mt.PointedThing): mt.ItemStack?
  103. ---Same as `on_place` but called when not pointing at a node.
  104. ---
  105. ---Function must return either `nil` if inventory shall not be modified, or an `itemstack` to replace the original `itemstack`.
  106. ---
  107. ---The user may be any `ObjectRef` or `nil`.
  108. ---
  109. ---default: `nil`
  110. ---@field on_secondary_use nil|fun(itemstack: mt.ItemStack, placer?: mt.ObjectRef, pointed_thing: mt.PointedThing): mt.ItemStack?
  111. -- Called when a dropped item is punched by a player.
  112. --
  113. -- Shall pick-up the item and return the leftover itemstack or nil to not
  114. -- modify the dropped item.
  115. --
  116. -- default: `minetest.item_pickup`
  117. ---@field on_pickup nil|fun(itemstack: mt.ItemStack, picker?: mt.ObjectRef, pointed_thing?: mt.PointedThing, time_from_last_punch?: number, ...?: any): mt.ItemStack?
  118. ---Shall drop item and return the leftover `itemstack`.
  119. ---
  120. ---The dropper may be any `ObjectRef` or `nil`.
  121. ---
  122. ---default: `minetest.item_drop`
  123. ---@field on_drop nil|fun(itemstack: mt.ItemStack, dropper?: mt.ObjectRef, pos: mt.Vector): mt.ItemStack?
  124. ---When user pressed the `punch/mine` key with the item in hand.
  125. ---
  126. ---Function must return either `nil` if inventory shall not be modified, or an `itemstack` to replace the original `itemstack`.
  127. ---
  128. ---e.g.:
  129. ---```lua
  130. ---itemstack:take_item(); return itemstack
  131. ---```
  132. ---
  133. ---Otherwise, the function is free to do what it wants.
  134. ---
  135. ---The user may be any `ObjectRef` or `nil`.
  136. ---
  137. ---The default functions handle regular use cases.
  138. ---
  139. ---default: `nil`
  140. ---@field on_use nil|fun(itemstack: mt.ItemStack, user?: mt.ObjectRef, pointed_thing: mt.PointedThing): mt.ItemStack?
  141. ---If defined, should return an itemstack and will be called instead of wearing out the item (if tool).
  142. ---
  143. ---If returns `nil`, does nothing.
  144. ---
  145. ---If after_use doesn't exist, it is the same as:
  146. ---```lua
  147. ---function(itemstack, user, node, digparams)
  148. --- itemstack:add_wear(digparams.wear)
  149. --- return itemstack
  150. ---end
  151. ---```
  152. ---
  153. ---The user may be any `ObjectRef` or `nil`.
  154. ---@field after_use nil|fun(itemstack: mt.ItemStack, user?: mt.ObjectRef, node: mt.Node, digparams: unknown): mt.ItemStack?