diff --git a/mods/CORE/CraftSystem/src/CraftSystem/BaseCraftHandler.lua b/mods/CORE/CraftSystem/src/CraftSystem/BaseCraftHandler.lua index fcecc31..f6133ad 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/BaseCraftHandler.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/BaseCraftHandler.lua @@ -25,7 +25,7 @@ local BaseCraftHandler = { function BaseCraftHandler:getCraftByName(craftName) local craft = self.craftsByName[craftName] - assert(craft ~= nil, ('There is no primitive craft named `%s`.'):format( + assert(craft ~= nil, ('A craft `%s` not exists.'):format( craftName)) return craft @@ -36,7 +36,7 @@ end function BaseCraftHandler:getCraftsByGroup(craftGroup) local crafts = self.craftsByGroup[craftGroup] - assert(crafts ~= nil, ('There are no primitive crafts with `%s` group'):format( + assert(crafts ~= nil, ('A craft with group `%s` not exists.'):format( craftGroup)) return crafts diff --git a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraft.lua b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraft.lua index ca8e543..8c5d952 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraft.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraft.lua @@ -8,7 +8,8 @@ local BaseCraft = require('CraftSystem.BaseCraft') ---@class CraftSystem.PrimitiveCraft : CraftSystem.BaseCraft ---@field recipe CraftSystem.CraftRecipe ----@field returnItems ItemStackString[] +---@field altRecipes CraftSystem.CraftRecipe[] +---@field returnItems ItemStackString[]? local PrimitiveCraft = extend(BaseCraft, {}) ---Definition table for the `CraftSystem.PrimitiveCraft`. @@ -16,6 +17,7 @@ local PrimitiveCraft = extend(BaseCraft, {}) ---**Only for EmmyLua.** ---@class CraftSystem.PrimitiveCraftDef : CraftSystem.BaseCraftDef ---@field recipe CraftSystem.CraftRecipe +---@field altRecipes CraftSystem.CraftRecipe[]? ---@field returnItems ItemStackString[]? ---@param name string @@ -23,13 +25,13 @@ local PrimitiveCraft = extend(BaseCraft, {}) ---@return CraftSystem.PrimitiveCraft function PrimitiveCraft:new(name, def) ---@type CraftSystem.PrimitiveCraft - local instance = getInstance(self, { - name = name, - group = def.group, - output = def.output, - recipe = def.recipe, - returnItems = def.returnItems or {} - }) + local instance = getInstance(self, {}) + instance.name = name + instance.group = def.group + instance.output = def.output + instance.recipe = def.recipe + instance.altRecipes = def.altRecipes or {} + instance.returnItems = def.returnItems return instance end diff --git a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua index 5e36220..0fb160c 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua @@ -42,6 +42,17 @@ function PrimitiveCraftHandler:registerCraft(craftName, def) tableInsert(self.craftsList, craft) end +---Adds alternative recipes to the craft with the specified name. +--- +---If a craft with the specified name does not exist, an error will call. +---@param craftName string +---@param recipes CraftSystem.CraftRecipe[] +function PrimitiveCraftHandler:registerAlternativeRecipes(craftName, recipes) + local craft = PrimitiveCraftHandler:getCraftByName(craftName) + + craft.altRecipes = tableJoin(craft.altRecipes or {}, recipes) +end + core.register_on_mods_loaded(function() for groupName, crafts in pairs(PrimitiveCraftHandler.craftsByGroup) do tableSort(crafts, function(a, b)