Item & Node: update settings & callbacks: inheritance from ide-helper
This commit is contained in:
@@ -83,14 +83,8 @@ local function addRarityToDesc(rarity, desc)
|
||||
return desc..'\n'..colorize(color, rarityString)
|
||||
end
|
||||
|
||||
---The alias `table.merge` for EmmyLua
|
||||
---@type fun(...):(NodeDefinition|ItemDefinition)
|
||||
local defMerge = function(...)
|
||||
return tableMerge(...)
|
||||
end
|
||||
|
||||
---@param itemDef Item.ItemDefinition
|
||||
---@return NodeDefinition|ItemDefinition
|
||||
---@return ItemDefinition
|
||||
local function itemDefToLuantiDef(itemDef)
|
||||
local modName = Mod.getInfo().shortName
|
||||
local S = core.get_translator(modName)
|
||||
@@ -127,7 +121,7 @@ local function itemDefToLuantiDef(itemDef)
|
||||
s._description = description
|
||||
s.description = luantiDescription..core.get_background_escape_sequence('#110F13')
|
||||
|
||||
local luantiDef = defMerge(s, c, true)
|
||||
local luantiDef = tableMerge(s, c, true) --[[@as ItemDefinition]]
|
||||
|
||||
return luantiDef
|
||||
end
|
||||
@@ -167,8 +161,7 @@ function Item:new(itemDef)
|
||||
itemDef = tableCopy(itemDef)
|
||||
|
||||
-- Adding default parameterss
|
||||
---@type Item.ItemDefinition
|
||||
itemDef = tableMerge(itemDef, self.defaultDef, true)
|
||||
itemDef = tableMerge(itemDef, self.defaultDef, true) --[[@as Item.ItemDefinition]]
|
||||
local s = itemDef.settings
|
||||
|
||||
local shortModName = Mod.getInfo().shortName
|
||||
@@ -190,7 +183,7 @@ function Item:new(itemDef)
|
||||
itemDef.settings._type = nil
|
||||
|
||||
if type == 'node' then
|
||||
registerNode(luantiDef)
|
||||
registerNode(luantiDef --[[@as NodeDefinition]])
|
||||
elseif type == 'craftitem' then
|
||||
registerCraftitem(luantiDef)
|
||||
elseif type == 'tool' then
|
||||
|
||||
@@ -1,67 +1,4 @@
|
||||
---@class Item.Callbacks
|
||||
---@meta
|
||||
|
||||
---@class Item.Callbacks : ItemDefinition.Callbacks
|
||||
local Callbacks = {}
|
||||
|
||||
---Called when the 'place' key was pressed with the item in hand
|
||||
---and pointing at a node.
|
||||
---Shall place item and return the leftover itemstack
|
||||
---or nil to not modify the inventory.
|
||||
---The placer may be any ObjectRef or nil.
|
||||
---
|
||||
---default: core.item_place
|
||||
---@type (fun(itemstack:ItemStack, placer:Player|ObjectRef|nil, pointed_thing:pointed_thing):ItemStack|nil, Position|vector|nil)?
|
||||
Callbacks.on_place = core.item_place
|
||||
|
||||
---Same as on_place but called when not pointing at a node.
|
||||
---Function must return either nil if inventory shall not be modified,
|
||||
---or an itemstack to replace the original itemstack.
|
||||
---The user may be any ObjectRef or nil.
|
||||
---
|
||||
---default: core.item_secondary_use
|
||||
---@type fun(itemstack:ItemStack, user:Player|ObjectRef|nil, pointed_thing:pointed_thing)?
|
||||
Callbacks.on_secondary_use = nil
|
||||
|
||||
---Shall drop item and return the leftover itemstack.
|
||||
---The dropper may be any ObjectRef or nil.
|
||||
---
|
||||
---default: core.item_drop
|
||||
---@type (fun(itemstack:ItemStack|ItemStackString, dropper:Player|ObjectRef|nil, pos:Position):ItemStack)?
|
||||
Callbacks.on_drop = core.item_drop
|
||||
|
||||
---Called when a dropped item is punched by a player.
|
||||
---Shall pick-up the item and return the leftover itemstack or nil to not
|
||||
---modify the dropped item.
|
||||
---
|
||||
---default: core.item_pickup
|
||||
---* `itemstack`: the `ItemStack` to be picked up
|
||||
---* `picker`: any `ObjectRef` or `nil`
|
||||
---* `pointed_thing`: the dropped item (a `"__builtin:item"` luaentity) as `type="object"` `pointed_thing`
|
||||
---* `time_from_last_punch`: other parameters from `luaentity:on_punch`
|
||||
---* `...`: other parameters from `luaentity:on_punch`
|
||||
---@type fun(itemstack:ItemStack, picker:Player|ObjectRef|nil, pointed_thing:pointed_thing, time_from_last_punch, ...)?
|
||||
Callbacks.on_pickup = core.item_pickup
|
||||
|
||||
---Called when user presses the 'punch/dig' key with the item in hand.
|
||||
---Function must return either nil if inventory shall not be modified,
|
||||
---or an itemstack to replace the original itemstack.
|
||||
---e.g. itemstack:take_item(); return itemstack
|
||||
---The user may be any ObjectRef or nil.
|
||||
---Note that defining this callback will prevent normal punching/digging
|
||||
---behavior on the client, as the interaction is instead "forwarded" to the
|
||||
---server.
|
||||
---
|
||||
---default: nil
|
||||
---@type (fun(itemstack:ItemStack, user:Player|ObjectRef|nil, pointed_thing:pointed_thing):ItemStack|nil)?
|
||||
Callbacks.on_use = nil
|
||||
|
||||
---Called after a tool is used to dig a node and will replace the default
|
||||
---tool wear-out handling.
|
||||
---Shall return the leftover itemstack or nil to not
|
||||
---modify the dropped item.
|
||||
---The user may be any ObjectRef or nil.
|
||||
---
|
||||
---default: nil
|
||||
---
|
||||
---@type fun(itemstack:ItemStack, user:Player|ObjectRef|nil, node, digparams)?
|
||||
Callbacks.after_use = nil
|
||||
|
||||
return Callbacks
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---@meta
|
||||
|
||||
---@class Item.ItemDefinition
|
||||
---@field settings Item.Settings
|
||||
---@field callbacks Item.Callbacks?
|
||||
local ItemDefinition = {}
|
||||
|
||||
return ItemDefinition
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
---@meta
|
||||
|
||||
---Rarity of items:
|
||||
--- * `common`
|
||||
--- * `uncommon`
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
---@class Item.Settings
|
||||
---@meta
|
||||
|
||||
---@class Item.Settings : ItemDefinition.Settings
|
||||
local Settings = {}
|
||||
|
||||
---Technical name of the item. Must be unique and have the format `mod_name:item_name`
|
||||
---@type string
|
||||
Settings.name = ''
|
||||
|
||||
---@type string?
|
||||
Settings.description = nil
|
||||
|
||||
---Whether to add the mod name to the settings.name. Default: `true`
|
||||
---@type boolean?
|
||||
Settings._add_mod_name = nil
|
||||
@@ -40,14 +39,6 @@ Settings._type = nil
|
||||
---@type Item.Rarity?
|
||||
Settings._rarity = nil
|
||||
|
||||
|
||||
---Table of groups-characteristics of Item.
|
||||
---`key` = name, `value` = rating; `rating` = number.
|
||||
---
|
||||
---If rating not applicable, use 1.
|
||||
---@type table<string,number>?
|
||||
Settings.groups = nil
|
||||
|
||||
---The number of inventory slots that can be stored in an ItemStack.
|
||||
---@type integer?
|
||||
Settings._itemstack_inventory_size = nil
|
||||
@@ -68,142 +59,3 @@ Settings._itemstack_inventory_allowed_groups = nil
|
||||
---with which cannot be placed in an item's inventory.
|
||||
---@type string[]?
|
||||
Settings._itemstack_inventory_disallowed_groups = nil
|
||||
|
||||
|
||||
|
||||
---Texture shown in the inventory GUI.
|
||||
---Defaults to a 3D rendering of the node if left empty.
|
||||
---@type string?
|
||||
Settings.inventory_image = nil
|
||||
|
||||
---An overlay texture which is not affected by colorization.
|
||||
---@type string?
|
||||
Settings.inventory_overlay = nil
|
||||
|
||||
|
||||
|
||||
---Texture shown when item is held in hand.
|
||||
---Defaults to a 3D rendering of the node if left empty.
|
||||
---@type string?
|
||||
Settings.wield_image = nil
|
||||
|
||||
---Like `inventory_overlay` but only used in the same situation as `wield_image`.
|
||||
---@type string?
|
||||
Settings.wield_overlay = nil
|
||||
|
||||
---Scale for the item when held in hand.
|
||||
---@type Position?
|
||||
Settings.wield_scale = nil
|
||||
|
||||
|
||||
|
||||
---An image file containing the palette of a node.
|
||||
---You can set the currently used color as the "palette_index" field of
|
||||
---the item stack metadata.
|
||||
---The palette is always stretched to fit indices between 0 and 255, to
|
||||
---ensure compatibility with "colorfacedir" (and similar) nodes.
|
||||
---@type string?
|
||||
Settings.palette = nil
|
||||
|
||||
---Color the item is colorized with. The palette overrides this.
|
||||
---It is a colorspec.
|
||||
---@type string|ColorSpec|nil
|
||||
Settings.color = nil
|
||||
|
||||
---Maximum amount of items that can be in a single stack.
|
||||
---The default can be changed by the setting `default_stack_max`.
|
||||
---@type number?
|
||||
Settings.stack_max = nil
|
||||
|
||||
---Range of node and object pointing that is possible with this item held.
|
||||
---Can be overridden with itemstack meta.
|
||||
---@type number?
|
||||
Settings.range = nil
|
||||
|
||||
---If true, item can point to all liquid nodes (`liquidtype ~= "none"`),
|
||||
---even those for which `pointable = false`.
|
||||
---@type boolean?
|
||||
Settings.liquids_pointable = nil
|
||||
|
||||
---Contains lists to override the `pointable` property of nodes and objects.
|
||||
---The index can be a node/entity name or a group with the prefix `"group:"`.
|
||||
---For objects `armor_groups` are used and for players the entity name is irrelevant.)
|
||||
---If multiple fields fit, the following priority order is applied:
|
||||
---1. value of matching node/entity name
|
||||
---2. `true` for any group
|
||||
---3. `false` for any group
|
||||
---4. `"blocking"` for any group
|
||||
---5. `liquids_pointable` if it is a liquid node
|
||||
---6. `pointable` property of the node or object
|
||||
---@type table?
|
||||
Settings.pointabilities = nil
|
||||
|
||||
---When used for nodes: Defines amount of light emitted by node.
|
||||
---Otherwise: Defines texture glow when viewed as a dropped item.
|
||||
---To set the maximum (14), use the value `core.LIGHT_MAX`.
|
||||
---A value outside the range 0 to `core.LIGHT_MAX` causes undefined
|
||||
---behavior.
|
||||
---@type number?
|
||||
Settings.light_source = nil
|
||||
|
||||
|
||||
|
||||
---See "Tool Capabilities" section for an example including explanation.
|
||||
---TODO: сделать или подтянуть из какого-нибудь helpers тип этой таблицы
|
||||
---@type table?
|
||||
Settings.tool_capabilities = nil
|
||||
|
||||
---Set wear bar color of the tool by setting color stops and blend mode.
|
||||
---See "Wear Bar Color" section for further explanation including an example.
|
||||
---TODO: сделать или подтянуть из какого-нибудь helpers тип этой таблицы
|
||||
---@type table?
|
||||
Settings.wear_color = nil
|
||||
|
||||
---If nil and item is node, prediction is made automatically.
|
||||
---If nil and item is not a node, no prediction is made.
|
||||
---If "" and item is anything, no prediction is made.
|
||||
---Otherwise should be name of node which the client immediately places
|
||||
---on ground when the player places the item. Server will always update
|
||||
---with actual result shortly.
|
||||
---@type string?
|
||||
Settings.node_placement_prediction = nil
|
||||
|
||||
---if "", no prediction is made.
|
||||
---if "air", node is removed.
|
||||
---Otherwise should be name of node which the client immediately places
|
||||
---upon digging. Server will always update with actual result shortly.
|
||||
---`default: "air"`
|
||||
---@type string?
|
||||
Settings.node_dig_prediction = nil
|
||||
|
||||
---Only affects touchscreen clients.
|
||||
---Defines the meaning of short and long taps with the item in hand.
|
||||
---If specified as a table, the field to be used is selected according to
|
||||
---the current `pointed_thing`.
|
||||
---There are three possible TouchInteractionMode values:
|
||||
---* "long_dig_short_place" (long tap = dig, short tap = place)
|
||||
---* "short_dig_long_place" (short tap = dig, long tap = place)
|
||||
---* "user":
|
||||
---* * For `pointed_object`: Equivalent to "short_dig_long_place" if the
|
||||
--- client-side setting "touch_punch_gesture" is "short_tap" (the
|
||||
--- default value) and the item is able to punch (i.e. has no on_use
|
||||
--- callback defined).
|
||||
--- Equivalent to "long_dig_short_place" otherwise.
|
||||
---* * For `pointed_node` and `pointed_nothing`:
|
||||
--- Equivalent to "long_dig_short_place".
|
||||
---* * The behavior of "user" may change in the future.
|
||||
---The default value is "user".
|
||||
---
|
||||
---@type table<string,SimpleSoundSpec>?
|
||||
Settings.touch_interaction = nil
|
||||
|
||||
|
||||
|
||||
---Definition of item sounds to be played at various events.
|
||||
---All fields in this table are optional.
|
||||
---
|
||||
---@type table<string,SimpleSoundSpec>?
|
||||
Settings.sound = nil
|
||||
|
||||
|
||||
return Settings
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
---@alias Item.Type 'craftitem'|'node'|'tool'
|
||||
---@meta
|
||||
|
||||
---@alias Item.Type 'craftitem'|'node'|'tool'
|
||||
|
||||
Reference in New Issue
Block a user