ItemStack & ItemStackMetaRef: 5.18 update annotations

This commit is contained in:
Van
2026-11-08 20:46:47 +03:00
parent a94b014166
commit 2ea20a7960
2 changed files with 164 additions and 107 deletions

View File

@@ -1,6 +1,15 @@
---Version: 5.18
---@meta ---@meta
---An `ItemStack` is a stack of items.
---
---`ItemStack([x])`: returns an `ItemStack`.
---
---`x`: (optional) Is one of the following:
--- * `nil` value: Empty stack
--- * `string` value: an `"itemstring"`.
--- * `table` value: `ItemStack` Table format.
--- * The `name` field is mandatory.
---@class ItemStack ---@class ItemStack
---@overload fun(x:ItemStack|ItemStackString|ItemStackTable|nil):ItemStack ---@overload fun(x:ItemStack|ItemStackString|ItemStackTable|nil):ItemStack
ItemStack = {} ItemStack = {}
@@ -13,102 +22,145 @@ ItemStack = {}
---@alias ItemStackString string ---@alias ItemStackString string
--- Put some item or stack onto this stack, returns leftover ItemStack ---Returns true if stack is empty.
--- @param item ItemStack|ItemStackString|ItemStackTable
--- @return self
function ItemStack:add_item(item) end
--- Increases wear by amount if the item is a tool, otherwise does nothing.
--- Wear is only added if the item is a tool. Adding wear might destroy the item.
--- @param amount number Valid amount range is [0,65536]
--- @return boolean Returns true if the item is (or was) a tool.
function ItemStack:add_wear(amount) end
--- Removes all items from the stack, making it empty
--- @return boolean it seams that it always return `true`
function ItemStack:clear() end
--- Returns number of items on the stack
--- @return integer
function ItemStack:get_count() end
--- Returns true/false (success), clears item on failure
--- @param count number count > 0 && count <= 65535 -- or clears
---@return boolean ---@return boolean
function ItemStack:set_count(count) end function ItemStack:is_empty() end
--- @return ItemDefinition returns the item definition table ---Returns item name (e.g. `"default:stone"`).
function ItemStack:get_definition() end ---@return string
--- Returns get_stack_max() - get_count()
--- @return number
function ItemStack:get_free_space() end
--- @return ItemStackMetaRef
function ItemStack:get_meta() end
--- Returns a string, for compatibility reasons this is equal to get_meta():get_string("")
--- @deprecated
function ItemStack:get_metadata() end
--- Returns item name (e.g. "default:stone")
--- @return ItemStackString
function ItemStack:get_name() end function ItemStack:get_name() end
--- Returns true/false (success), clears item on failure ---Sets the item name.
---
---Returns `false` if the stack was cleared, `true` otherwise.
---@param item_name string ---@param item_name string
---@return boolean ---@return boolean
function ItemStack:set_name(item_name) end function ItemStack:set_name(item_name) end
--- Returns the maximum size of the stack (depends on the item) ---Returns amount of items on the stack.
--- @return number ---@return integer
function ItemStack:get_stack_max() end function ItemStack:get_count() end
--- Returns the digging properties of the item, or those of the hand if none are defined for this item type ---Sets amount of items in the stack.
--- @return table ---
function ItemStack:get_tool_capabilities() end ---Returns `false` if the stack was cleared, `true` otherwise.
---@param count integer
---@return boolean
function ItemStack:set_count(count) end
--- Returns tool wear (0-65535), 0 for non-tools ---Returns tool wear (integer in range [0, 65535]), `0` for non-tools.
--- @return number ---@return integer
function ItemStack:get_wear() end function ItemStack:get_wear() end
--- Returns true/false (success), clears item on failure ---Set tool wear.
--- @param wear number wear <= 65535, otherwise clears ---
---Returns `false` if the stack was cleared, `true` otherwise
---@param wear integer
---@return boolean ---@return boolean
function ItemStack:set_wear(wear) end function ItemStack:set_wear(wear) end
--- Return true if stack is empty ---@return ItemStackMetaRef
--- @return boolean function ItemStack:get_meta() end
function ItemStack:is_empty() end
--- Returns true if the item name refers to a defined item type ---@deprecated
function ItemStack:get_metadata() end
---@deprecated
function ItemStack:set_metadata() end
---Returns the description shown in inventory list tooltips.
---@return string
function ItemStack:get_description() end
---Returns the short description.
---@return string
function ItemStack:get_short_description() end
---Removes all items from the stack, making it empty.
function ItemStack:clear() end
---Replace the contents of this stack.
---@param item ItemStack|ItemStackString|ItemStackTable
function ItemStack:replace(item) end
---Returns the stack in `itemstring` form.
---@return string
function ItemStack:to_string() end
---Returns the stack in Lua table form.
---
---Returns `nil` if the stack is empty
---@return ItemStackTable?
function ItemStack:to_table() end
---Returns the maximum size of the stack (depends on the item).
---@return integer
function ItemStack:get_stack_max() end
---Returns `get_stack_max() - get_count()`.
---@return integer
function ItemStack:get_free_space() end
---Returns `true` if the item name refers to a defined item type.
---@return boolean ---@return boolean
function ItemStack:is_known() end function ItemStack:is_known() end
--- Returns true if item or stack can be fully added to this one ---Returns the item definition table.
---
---Returns the definition of the `unknown` item if the item is not registered.
---@return ItemDefinition|NodeDefinition
function ItemStack:get_definition() end
---Returns the digging properties of the item,
---or those of the hand if none are defined for this item type.
---@return ItemDefinition.tool_capabilities_table
function ItemStack:get_tool_capabilities() end
---Increases wear by `amount` if the item is a tool, otherwise does nothing.
---@param amount integer
function ItemStack:add_wear(amount) end
---Increases wear in such a way that,
---if only this function is called, the item breaks after `max_uses` times.
---
---Does nothing if item is not a tool or if `max_uses` is `0`.
---@param max_uses integer
function ItemStack:add_wear_by_uses(max_uses) end
---Returns the wear bar parameters of the item,
---or nil if none are defined for this item type or in the stack's meta.
---@return ItemDefinition.wearbar_color_table
function ItemStack:get_wear_bar_params() end
---Put some item or stack onto this stack.
---
---Returns leftover ItemStack.
---@param item ItemStack|ItemStackString|ItemStackTable
---@return self
function ItemStack:add_item(item) end
---Returns `true` if item or stack can be fully added to this one
---@param item ItemStack|ItemStackString|ItemStackTable ---@param item ItemStack|ItemStackString|ItemStackTable
---@return boolean ---@return boolean
function ItemStack:item_fits(item) end function ItemStack:item_fits(item) end
--- Copy (don't remove) up to n items from this stack; returns copied ItemStack; if n is omitted, n=1 is used ---Take (and remove) up to `n` items from this stack.
--- @param count number ---@param count number? default: `1`
--- @return ItemStack
function ItemStack:peek_item(count) end
--- Replace the contents of this stack (item can also be an itemstring or table)
--- @param item ItemStack|ItemStackString|ItemStackTable
--- @return boolean seams always `true`
function ItemStack:replace(item) end
--- Take (and remove) up to n items from this stack; returns taken ItemStack; if n is omitted, n=1 is used
--- @param count? number
---@return ItemStack ---@return ItemStack
function ItemStack:take_item(count) end function ItemStack:take_item(count) end
--- Returns the stack in itemstring form ---Copy (don't remove) up to `n` items from this stack.
--- @return string ---@param count number? default: `1`
function ItemStack:to_string() end ---@return ItemStack
function ItemStack:peek_item(count) end
--- Returns the stack in Lua table form or `nil` if empty. ---Returns `true` if this stack is identical to other.
--- @return table|nil ---
function ItemStack:to_table() end ---**Note**: stack1:to_string() == stack2:to_string() is not reliable,
---as stack metadata can be serialized in arbitrary order.
---
---**Note**: if other is an itemstring or table representation of an ItemStack,
---this will always return false, even if it is "equivalent".
---@param other ItemStack|ItemStackString|ItemStackTable
---@return boolean
function ItemStack:equals(other) end

View File

@@ -1,15 +1,20 @@
---Version: 5.18
---@meta ---@meta
---ItemStack metadata: reference extra data and functionality stored in a stack. ---ItemStack metadata: reference extra data and functionality stored in a stack.
--- Can be obtained via `item:get_meta()`.
--- ---
---Can be obtained via `item:get_meta()`.
---@class ItemStackMetaRef: MetaDataRef ---@class ItemStackMetaRef: MetaDataRef
ItemStackMetaRef = {} ItemStackMetaRef = {}
--- * Overrides the item's tool capabilities ---Overrides the item's tool capabilities.
--- * A nil value will clear the override data and restore the original behavior. ---
---A `nil` value will clear the override data and restore the original behavior.
---@param tool_capabilities ItemDefinition.tool_capabilities_table
function ItemStackMetaRef:set_tool_capabilities(tool_capabilities) end function ItemStackMetaRef:set_tool_capabilities(tool_capabilities) end
--- * Overrides the item's wear bar parameters (see "Wear Bar Color" section) ---Overrides the item's wear bar parameters (see "Wear Bar Color" section)
--- * A nil value will clear the override data and restore the original behavior. ---
---A `nil` value will clear the override data and restore the original behavior.
---@param wear_bar_params ItemDefinition.wearbar_color_table
function ItemStackMetaRef:set_wear_bar_params(wear_bar_params) end function ItemStackMetaRef:set_wear_bar_params(wear_bar_params) end