mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-26 20:43:42 +01:00
Separate custom_crafts tables from main table
This commit is contained in:
parent
fa30a0d076
commit
058cd05ed7
19
init.lua
19
init.lua
@ -1,7 +1,4 @@
|
|||||||
craftguide = {
|
craftguide = {}
|
||||||
custom_crafts = {},
|
|
||||||
craft_types = {},
|
|
||||||
}
|
|
||||||
|
|
||||||
local M = minetest
|
local M = minetest
|
||||||
local player_data = {}
|
local player_data = {}
|
||||||
@ -109,15 +106,15 @@ local function __func()
|
|||||||
return debug.getinfo(2, "n").name
|
return debug.getinfo(2, "n").name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local custom_crafts, craft_types = {}, {}
|
||||||
|
|
||||||
function craftguide.register_craft_type(name, def)
|
function craftguide.register_craft_type(name, def)
|
||||||
local func = "craftguide." .. __func() .. "(): "
|
local func = "craftguide." .. __func() .. "(): "
|
||||||
assert(name, func .. "'name' field missing")
|
assert(name, func .. "'name' field missing")
|
||||||
assert(def.description, func .. "'description' field missing")
|
assert(def.description, func .. "'description' field missing")
|
||||||
assert(def.icon, func .. "'icon' field missing")
|
assert(def.icon, func .. "'icon' field missing")
|
||||||
|
|
||||||
if not craftguide.craft_types[name] then
|
craft_types[name] = def
|
||||||
craftguide.craft_types[name] = def
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function craftguide.register_craft(def)
|
function craftguide.register_craft(def)
|
||||||
@ -127,7 +124,7 @@ function craftguide.register_craft(def)
|
|||||||
assert(def.output, func .. "'output' field missing")
|
assert(def.output, func .. "'output' field missing")
|
||||||
assert(def.items, func .. "'items' field missing")
|
assert(def.items, func .. "'items' field missing")
|
||||||
|
|
||||||
craftguide.custom_crafts[#craftguide.custom_crafts + 1] = def
|
custom_crafts[#custom_crafts + 1] = def
|
||||||
end
|
end
|
||||||
|
|
||||||
local recipe_filters = {}
|
local recipe_filters = {}
|
||||||
@ -276,8 +273,8 @@ local function cache_recipes(output)
|
|||||||
local recipes = M.get_all_craft_recipes(output) or {}
|
local recipes = M.get_all_craft_recipes(output) or {}
|
||||||
local c = 0
|
local c = 0
|
||||||
|
|
||||||
for i = 1, #craftguide.custom_crafts do
|
for i = 1, #custom_crafts do
|
||||||
local custom_craft = craftguide.custom_crafts[i]
|
local custom_craft = custom_crafts[i]
|
||||||
if match(custom_craft.output, "%S*") == output then
|
if match(custom_craft.output, "%S*") == output then
|
||||||
c = c + 1
|
c = c + 1
|
||||||
recipes[c] = custom_craft
|
recipes[c] = custom_craft
|
||||||
@ -444,7 +441,7 @@ local function get_recipe_fs(data, iY)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local custom_recipe = craftguide.craft_types[recipe.type]
|
local custom_recipe = craft_types[recipe.type]
|
||||||
|
|
||||||
if custom_recipe or shapeless or recipe.type == "cooking" then
|
if custom_recipe or shapeless or recipe.type == "cooking" then
|
||||||
local icon = custom_recipe and custom_recipe.icon or
|
local icon = custom_recipe and custom_recipe.icon or
|
||||||
|
Loading…
Reference in New Issue
Block a user