Properly seperate chance digs from normal digs

This commit is contained in:
Wuzzy 2016-08-07 04:47:15 +02:00
parent 80f99cffe7
commit 1c5fcd18ca

39
api.lua
View File

@ -58,11 +58,10 @@ minetest.after(0.01, function()
end end
-- Complex drops -- Complex drops
elseif type(def.drop) == "table" then elseif type(def.drop) == "table" then
--[[ Extract single items from the table and save them into dedicated table --[[ Extract single items from the table and save them into dedicated tables
to register them later, in order to avoid duplicates ]] to register them later, in order to avoid duplicates ]]
local drop_memo = {} local drop_guaranteed = {}
--[[ Also take count into account ]] local drop_maybe = {}
local drop_count = {}
for i=1,#def.drop.items do for i=1,#def.drop.items do
local itit = def.drop.items[i] local itit = def.drop.items[i]
for j=1,#itit.items do for j=1,#itit.items do
@ -70,27 +69,33 @@ minetest.after(0.01, function()
if not dstack:is_empty() and dstack:get_name() ~= name then if not dstack:is_empty() and dstack:get_name() ~= name then
local dname = dstack:get_name() local dname = dstack:get_name()
local dcount = dstack:get_count() local dcount = dstack:get_count()
if drop_count[dname] == nil then
drop_count[dname] = 0
end
if #itit.items == 1 and itit.rarity == 1 then if #itit.items == 1 and itit.rarity == 1 then
if drop_count[dname] == "digging_chance" then if drop_guaranteed[dname] == nil then
drop_count[dname] = 0 drop_guaranteed[dname] = 0
end end
drop_memo[dname] = "digging" drop_guaranteed[dname] = drop_guaranteed[dname] + dcount
drop_count[dname] = drop_count[dname] + dcount else
elseif drop_memo[dname] ~= "digging" then if drop_maybe[dname] == nil then
drop_memo[dname] = "digging_chance" drop_maybe[dname] = 0
drop_count[dname] = drop_count[dname] + dcount end
drop_maybe[dname] = drop_maybe[dname] + dcount
end end
end end
end end
end end
for itemstring, crafttype in pairs(drop_memo) do for itemstring, count in pairs(drop_guaranteed) do
unified_inventory.register_craft({ unified_inventory.register_craft({
type = crafttype, type = "digging",
items = {name}, items = {name},
output = itemstring .. " " .. drop_count[itemstring], output = itemstring .. " " .. count,
width = 0,
})
end
for itemstring, count in pairs(drop_maybe) do
unified_inventory.register_craft({
type = "digging_chance",
items = {name},
output = itemstring .. " " .. count,
width = 0, width = 0,
}) })
end end