Reduce redundancy in chance-based drops
This commit is contained in:
parent
08d8d99ab3
commit
09c731cee0
21
api.lua
21
api.lua
@ -44,6 +44,7 @@ minetest.after(0.01, function()
|
|||||||
print("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
|
print("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
|
||||||
for _, name in ipairs(unified_inventory.items_list) do
|
for _, name in ipairs(unified_inventory.items_list) do
|
||||||
local def = minetest.registered_items[name]
|
local def = minetest.registered_items[name]
|
||||||
|
-- Simple drops
|
||||||
if type(def.drop) == "string" then
|
if type(def.drop) == "string" then
|
||||||
local dstack = ItemStack(def.drop)
|
local dstack = ItemStack(def.drop)
|
||||||
if not dstack:is_empty() and dstack:get_name() ~= name then
|
if not dstack:is_empty() and dstack:get_name() ~= name then
|
||||||
@ -55,23 +56,35 @@ minetest.after(0.01, function()
|
|||||||
})
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
-- 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
|
||||||
|
to register them later, in order to avoid duplicates ]]
|
||||||
|
local drop_memo = {}
|
||||||
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
|
||||||
local dstack = ItemStack(itit.items[j])
|
local dstack = ItemStack(itit.items[j])
|
||||||
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()
|
||||||
|
if #itit.items == 1 and itit.rarity == 1 then
|
||||||
|
drop_memo[dname] = "digging"
|
||||||
|
elseif drop_memo[dname] ~= "digging" then
|
||||||
|
drop_memo[dname] = "digging_chance"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for itemstring, crafttype in pairs(drop_memo) do
|
||||||
unified_inventory.register_craft({
|
unified_inventory.register_craft({
|
||||||
type = "digging_chance",
|
type = crafttype,
|
||||||
items = {name},
|
items = {name},
|
||||||
output = dstack:get_name(),
|
output = itemstring,
|
||||||
width = 0,
|
width = 0,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
for _, recipes in pairs(unified_inventory.crafts_for.recipe) do
|
for _, recipes in pairs(unified_inventory.crafts_for.recipe) do
|
||||||
for _, recipe in ipairs(recipes) do
|
for _, recipe in ipairs(recipes) do
|
||||||
local ingredient_items = {}
|
local ingredient_items = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user