Item: Corrections to the design, added the last empty lines
This commit is contained in:
@@ -33,10 +33,10 @@ local RARITY_INDEX = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
---@class Item
|
---@class Item
|
||||||
---@field itemDef Item.ItemDefinition
|
---@field itemDef Item.ItemDefinition
|
||||||
---@field luantiDef table
|
---@field luantiDef ItemDefinition
|
||||||
---@field getVisual fun(): string
|
---@field getVisual fun(): string
|
||||||
---@field defaultDef Item.ItemDefinition
|
---@field defaultDef Item.ItemDefinition
|
||||||
local Item = {
|
local Item = {
|
||||||
defaultDef = {
|
defaultDef = {
|
||||||
settings = {
|
settings = {
|
||||||
@@ -122,19 +122,19 @@ local function itemDefToLuantiDef(itemDef)
|
|||||||
return luantiDef
|
return luantiDef
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param luantiDef NodeDefinition|ItemDefinition
|
---@param luantiDef NodeDefinition
|
||||||
local function register3dItem(luantiDef)
|
local function register3dItem(luantiDef)
|
||||||
local ld = luantiDef
|
local name = luantiDef.name
|
||||||
local name = ld.name
|
luantiDef.name = nil
|
||||||
ld.name = nil
|
|
||||||
core.register_node(':'..name, luantiDef)
|
core.register_node(':'..name, luantiDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param luantiDef ItemDefinition
|
---@param luantiDef ItemDefinition
|
||||||
local function registerFlatItem(luantiDef)
|
local function registerFlatItem(luantiDef)
|
||||||
local ld = luantiDef
|
local name = luantiDef.name
|
||||||
local name = ld.name
|
luantiDef.name = nil
|
||||||
ld.name = nil
|
|
||||||
core.register_craftitem(':'..name, luantiDef)
|
core.register_craftitem(':'..name, luantiDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -144,23 +144,23 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
---@param def Item.ItemDefinition|Node.NodeDefinition
|
||||||
---@return Item
|
---@return Item
|
||||||
function Item:new(itemDef)
|
function Item:new(def)
|
||||||
---Adding default parameters
|
---Adding default parameters
|
||||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
def = defMerge(def, self.defaultDef, true)
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local instance = getInstance(self, {})
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
local luantiDef = itemDefToLuantiDef(def)
|
||||||
local visual = itemDef.settings.visual
|
local visual = def.settings.visual
|
||||||
|
|
||||||
if visual == nil then
|
if visual == nil then
|
||||||
visual = 'item_2d'
|
visual = 'item_2d'
|
||||||
end
|
end
|
||||||
|
|
||||||
itemDef.settings.visual = nil
|
def.settings.visual = nil
|
||||||
|
|
||||||
if visual == 'item_3d' then
|
if visual == 'item_3d' then
|
||||||
register3dItem(luantiDef)
|
register3dItem(luantiDef)
|
||||||
@@ -173,7 +173,7 @@ function Item:new(itemDef)
|
|||||||
return visual
|
return visual
|
||||||
end
|
end
|
||||||
|
|
||||||
instance.itemDef = itemDef
|
instance.itemDef = def
|
||||||
instance.luantiDef = luantiDef
|
instance.luantiDef = luantiDef
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|||||||
Reference in New Issue
Block a user