itemstack.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ---@meta
  2. ---ItemStack
  3. ------------
  4. ---An `ItemStack` is a stack of items.
  5. ---
  6. ---It can be created via `ItemStack(x)`, where x is an ItemStack,
  7. ---an itemstring, a table or nil.
  8. ---
  9. --- **Operators**
  10. ---
  11. ---* `stack1 == stack2`:
  12. ---* Returns whether `stack1` and `stack2` are identical.
  13. ---* Note: `stack1:to_string() == stack2:to_string()` is not reliable,
  14. --- as stack metadata can be serialized in arbitrary order.
  15. ---* Note: if `stack2` is an itemstring or table representation of an
  16. --- ItemStack, this will always return false, even if it is "equivalent".
  17. ---@class mt.ItemStack
  18. local ItemStackObject = {}
  19. ---`ItemStack` constructor.
  20. ---@param x mt.Item
  21. ---@return mt.ItemStack
  22. function ItemStack(x) end
  23. ---Returns `true` if stack is empty.
  24. ---@return boolean
  25. function ItemStackObject:is_empty() end
  26. ---@return string name ie: "default:stone"
  27. function ItemStackObject:get_name() end
  28. ---Returns a boolean indicating whether the item was cleared.
  29. ---@param item_name string
  30. ---@return boolean cleared
  31. function ItemStackObject:set_name(item_name) end
  32. ---Returns number of items on the stack.
  33. ---@return number
  34. function ItemStackObject:get_count() end
  35. ---Returns a boolean indicating whether the item was cleared.
  36. ---@param count integer Unsigned 16 bit.
  37. ---@return boolean cleared
  38. function ItemStackObject:set_count(count) end
  39. ---Returns tool wear (`0`-`65535`), `0` for non-tools.
  40. ---@return number
  41. function ItemStackObject:get_wear() end
  42. ---Returns boolean indicating whether item was cleared.
  43. ---@param wear integer Unsigned 16 bit.
  44. ---@return boolean cleared
  45. function ItemStackObject:set_wear(wear) end
  46. ---**DEPRECATED** Returns metadata (a string attached to an item stack).
  47. ---@return string
  48. ---@deprecated
  49. function ItemStackObject:get_metadata() end
  50. ---**DEPRECATED**
  51. ---@param metadata string
  52. ---@return true
  53. ---@deprecated
  54. function ItemStackObject:set_metadata(metadata) end
  55. ---* Returns the description shown in inventory list tooltips.
  56. ---* The engine uses this when showing item descriptions in tooltips.
  57. ---* Fields for finding the description, in order:
  58. --- * `description` in item metadata (See [Item Metadata]);
  59. --- * `description` in item definition;
  60. --- * item name.
  61. ---@return string
  62. function ItemStackObject:get_description() end
  63. ---* Returns the short description or nil.
  64. ---* Unlike the description, this does not include new lines.
  65. ---* Fields for finding the short description, in order:
  66. --- * `short_description` in item metadata (See [Item Metadata]);
  67. --- * `short_description` in item definition;
  68. --- * first line of the description (From item meta or def, see `get_description()`);
  69. --- * Returns nil if none of the above are set.
  70. ---@return string|nil
  71. function ItemStackObject:get_short_description() end
  72. ---Removes all items from the stack, making it empty.
  73. function ItemStackObject:clear() end
  74. ---Replace the contents of this stack.
  75. ---@param item string|table
  76. function ItemStackObject:replace(item) end
  77. ---Returns the stack in itemstring form.
  78. ---@return string
  79. function ItemStackObject:to_string() end
  80. ---Returns the stack in Lua table form.
  81. ---@return table
  82. function ItemStackObject:to_table() end
  83. ---Returns the maximum size of the stack (depends on the item).
  84. ---@return number
  85. function ItemStackObject:get_stack_max() end
  86. ---Returns `get_stack_max() - get_count()`.
  87. ---@return number
  88. function ItemStackObject:get_free_space() end
  89. ---Returns `true` if the item name refers to a defined item type.
  90. ---@return boolean
  91. function ItemStackObject:is_known() end
  92. ---Returns the item definition table.
  93. ---@return mt.ItemDef
  94. function ItemStackObject:get_definition() end
  95. ---Returns the digging properties of the item, or those of the hand if none are
  96. ---defined for this item type.
  97. ---@return mt.ToolCaps
  98. function ItemStackObject:get_tool_capabilities() end
  99. ---Increases wear by `amount` if the item is a tool, otherwise does nothing
  100. ---@param amount integer 0..65536
  101. function ItemStackObject:add_wear(amount) end
  102. ---* Increases wear in such a way that, if only this function is called,
  103. --- the item breaks after `max_uses` times.
  104. ---* Does nothing if item is not a tool or if `max_uses` is 0.
  105. ---@param max_uses integer 0..65536
  106. function ItemStackObject:add_wear_by_uses(max_uses) end
  107. ---* Returns leftover `ItemStack`.
  108. ---* Put some item or stack onto this stack.
  109. ---@param item mt.Item
  110. ---@return mt.ItemStack leftover
  111. function ItemStackObject:add_item(item) end
  112. ---Returns `true` if item or stack can be fully added to this one.
  113. ---@param item mt.Item
  114. ---@return boolean
  115. function ItemStackObject:item_fits(item) end
  116. ---* Returns taken `ItemStack`.
  117. ---* Take (and remove) up to `n` items from this stack.
  118. ---@param n number|nil Default: `1`.
  119. ---@return mt.ItemStack taken
  120. function ItemStackObject:take_item(n) end
  121. ---* Returns taken `ItemStack`.
  122. ---* Copy (don't remove) up to `n` items from this stack.
  123. ---@param n number|nil Default: `1`.
  124. ---@return mt.ItemStack taken
  125. function ItemStackObject:peek_item(n) end
  126. ---* Returns `true` if this stack is identical to `other`.
  127. ---* Note: `stack1:to_string() == stack2:to_string()` is not reliable,
  128. --- as stack metadata can be serialized in arbitrary order.
  129. ---* Note: if `other` is an itemstring or table representation of an
  130. --- ItemStack, this will always return false, even if it is
  131. --- "equivalent".
  132. ---@param other mt.Item
  133. function ItemStackObject:equals(other) end
  134. ---@return mt.ItemStackMetaRef
  135. function ItemStackObject:get_meta() end