mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-01-28 20:20:16 +01:00
Minor refactoring
This commit is contained in:
parent
c32feb44fc
commit
90adfb42c1
71
init.lua
71
init.lua
@ -1161,29 +1161,20 @@ core.register_craft = function(def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function register_drops(name, def)
|
local function handle_drops_table(name, drop)
|
||||||
-- Code borrowed and modified from unified_inventory
|
-- Code borrowed and modified from unified_inventory
|
||||||
-- https://github.com/minetest-mods/unified_inventory/blob/master/api.lua
|
-- https://github.com/minetest-mods/unified_inventory/blob/master/api.lua
|
||||||
local drop = def.drop
|
local drop_sure, drop_maybe = {}, {}
|
||||||
|
local drop_items = drop.items or {}
|
||||||
|
local max_items_left = drop.max_items
|
||||||
|
local max_start = true
|
||||||
|
|
||||||
if is_str(drop) and drop ~= name then
|
for i = 1, #drop_items do
|
||||||
craftguide.register_craft({
|
if max_items_left and max_items_left <= 0 then break end
|
||||||
type = "digging",
|
local di = drop_items[i]
|
||||||
items = {name},
|
|
||||||
output = drop,
|
|
||||||
})
|
|
||||||
|
|
||||||
elseif is_table(drop) then
|
for j = 1, #di.items do
|
||||||
local drop_sure, drop_maybe = {}, {}
|
if is_str(di.items[j]) then
|
||||||
local drop_items = drop.items or {}
|
|
||||||
local max_items_left = drop.max_items
|
|
||||||
local max_start = true
|
|
||||||
|
|
||||||
for i = 1, #drop_items do
|
|
||||||
if max_items_left and max_items_left <= 0 then break end
|
|
||||||
local di = drop_items[i]
|
|
||||||
|
|
||||||
for j = 1, #di.items do
|
|
||||||
local dname, dcount = match(di.items[j], "(.*)%s*(%d*)")
|
local dname, dcount = match(di.items[j], "(.*)%s*(%d*)")
|
||||||
dcount = dcount and tonumber(dcount) or 1
|
dcount = dcount and tonumber(dcount) or 1
|
||||||
|
|
||||||
@ -1213,22 +1204,36 @@ local function register_drops(name, def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for item, count in pairs(drop_sure) do
|
for item, count in pairs(drop_sure) do
|
||||||
craftguide.register_craft({
|
craftguide.register_craft({
|
||||||
type = "digging",
|
type = "digging",
|
||||||
items = {name},
|
items = {name},
|
||||||
output = fmt("%s %u", item, count),
|
output = fmt("%s %u", item, count),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
for item, count in pairs(drop_maybe) do
|
for item, count in pairs(drop_maybe) do
|
||||||
craftguide.register_craft({
|
craftguide.register_craft({
|
||||||
type = "digging_chance",
|
type = "digging_chance",
|
||||||
items = {name},
|
items = {name},
|
||||||
output = fmt("%s %u", item, count),
|
output = fmt("%s %u", item, count),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function register_drops(name, def)
|
||||||
|
local drop = def.drop
|
||||||
|
|
||||||
|
if is_str(drop) and drop ~= name then
|
||||||
|
craftguide.register_craft({
|
||||||
|
type = "digging",
|
||||||
|
items = {name},
|
||||||
|
output = drop,
|
||||||
|
})
|
||||||
|
elseif is_table(drop) then
|
||||||
|
handle_drops_table(name, drop)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user