2015-09-02 19:57:24 +02:00
|
|
|
--
|
|
|
|
-- Goodies mod
|
2017-05-11 23:03:08 +02:00
|
|
|
-- By Kaadmy, for Pixture
|
2015-09-02 19:57:24 +02:00
|
|
|
--
|
|
|
|
|
|
|
|
goodies = {}
|
|
|
|
|
2019-09-21 14:56:37 +02:00
|
|
|
goodies.max_stack_default = 6
|
2015-09-02 19:57:24 +02:00
|
|
|
goodies.max_items = 20
|
|
|
|
|
|
|
|
goodies.types = {}
|
2019-09-21 16:36:53 +02:00
|
|
|
goodies.types_valuable = {}
|
2015-09-02 19:57:24 +02:00
|
|
|
-- custom types
|
2017-05-11 23:03:08 +02:00
|
|
|
goodies.types["FURNACE_SRC"] = {
|
2015-09-02 19:57:24 +02:00
|
|
|
["default:lump_iron"] = 3,
|
|
|
|
["farming:flour"] = 5,
|
|
|
|
}
|
2017-05-11 23:03:08 +02:00
|
|
|
goodies.types["FURNACE_FUEL"] = {
|
2015-09-02 19:57:24 +02:00
|
|
|
["default:lump_coal"] = 2,
|
|
|
|
["default:planks_oak"] = 4,
|
|
|
|
["default:planks_birch"] = 5,
|
|
|
|
}
|
2017-05-11 23:03:08 +02:00
|
|
|
goodies.types["FURNACE_DST"] = {
|
2019-09-21 16:08:19 +02:00
|
|
|
["default:ingot_wrought_iron"] = 5,
|
2015-09-02 19:57:24 +02:00
|
|
|
["farming:bread"] = 8,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- chunk types for villages
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_modpath("village") ~= nil then
|
2017-05-11 23:03:08 +02:00
|
|
|
goodies.types["forge"] = {
|
2015-09-02 19:57:24 +02:00
|
|
|
["default:lump_coal"] = 4,
|
|
|
|
["default:lump_iron"] = 6,
|
|
|
|
["default:pick_stone"] = 9,
|
|
|
|
["default:tree_oak"] = 2,
|
|
|
|
}
|
2019-09-21 16:36:53 +02:00
|
|
|
goodies.types_valuable["forge"] = {
|
|
|
|
["default:ingot_steel"] = 10,
|
|
|
|
["default:ingot_carbon_steel"] = 12,
|
|
|
|
}
|
2015-09-02 19:57:24 +02:00
|
|
|
goodies.types["tavern"] = {
|
2019-09-21 14:56:37 +02:00
|
|
|
["bed:bed"] = { chance = 8, max_stack = 1},
|
2015-09-02 19:57:24 +02:00
|
|
|
["default:bucket"] = 20,
|
|
|
|
["mobs:meat"] = 5,
|
|
|
|
["default:ladder"] = 9,
|
|
|
|
}
|
2019-09-21 16:36:53 +02:00
|
|
|
goodies.types_valuable["tavern"] = {
|
|
|
|
["mobs:pork"] = 9,
|
|
|
|
}
|
2017-05-11 23:03:08 +02:00
|
|
|
goodies.types["house"] = {
|
2015-09-02 19:57:24 +02:00
|
|
|
["default:stick"] = 2,
|
|
|
|
["farming:bread"] = 6,
|
|
|
|
["farming:cotton_1"] = 9,
|
|
|
|
["farming:wheat_1"] = 6,
|
|
|
|
["default:axe_stone"] = 13,
|
|
|
|
["default:apple"] = 3,
|
|
|
|
["default:bucket"] = 8,
|
|
|
|
["default:bucket_water"] = 12,
|
|
|
|
}
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- jewels and gold
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_modpath("jewels") ~= nil then
|
2019-09-21 16:36:53 +02:00
|
|
|
goodies.types_valuable["house"] = {
|
|
|
|
["jewels:bench"] = { chance = 24, max_stack = 1},
|
|
|
|
["jewels:jewel"] = 34,
|
|
|
|
}
|
|
|
|
goodies.types_valuable["tavern"] = { ["jewels:jewel"] = 32 }
|
|
|
|
goodies.types_valuable["forge"] = { ["jewels:jewel"] = 30 }
|
2015-09-06 21:02:45 +02:00
|
|
|
end
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_modpath("gold") ~= nil then
|
2019-09-21 16:36:53 +02:00
|
|
|
goodies.types_valuable["house"] = { ["gold:ingot_gold"] = 12 }
|
|
|
|
goodies.types_valuable["tavern"] = { ["gold:ingot_gold"] = 10 }
|
|
|
|
goodies.types_valuable["forge"] = { ["gold:ingot_gold"] = 8 }
|
2015-09-06 21:02:45 +02:00
|
|
|
end
|
2015-09-02 19:57:24 +02:00
|
|
|
end
|
|
|
|
|
2019-09-21 16:36:53 +02:00
|
|
|
goodies.types_all = {}
|
|
|
|
|
|
|
|
for k,v in pairs(goodies.types) do
|
|
|
|
goodies.types_all[k] = table.copy(v)
|
|
|
|
end
|
|
|
|
for k,v in pairs(goodies.types_valuable) do
|
|
|
|
if not goodies.types_all[k] then
|
|
|
|
goodies.types_all[k] = table.copy(v)
|
|
|
|
else
|
|
|
|
for q,r in pairs(v) do
|
|
|
|
goodies.types_all[k][q] = r
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-02 19:57:24 +02:00
|
|
|
function goodies.fill(pos, ctype, pr, listname, keepchance)
|
|
|
|
-- fill an inventory with a specified type's goodies
|
|
|
|
|
2019-09-21 16:36:53 +02:00
|
|
|
if goodies.types_all[ctype] == nil then return end
|
2015-09-02 19:57:24 +02:00
|
|
|
|
|
|
|
if pr:next(1, keepchance) ~= 1 then
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.remove_node(pos)
|
2015-09-02 19:57:24 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-09-02 19:57:24 +02:00
|
|
|
local inv = meta:get_inventory()
|
2017-05-11 23:03:08 +02:00
|
|
|
|
2015-09-02 19:57:24 +02:00
|
|
|
local size = inv:get_size(listname)
|
|
|
|
|
|
|
|
if size < 1 then return end
|
|
|
|
|
2019-09-21 16:36:53 +02:00
|
|
|
local is_locked = false
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if minetest.get_item_group(node.name, "locked") > 0 then
|
|
|
|
is_locked = true
|
|
|
|
end
|
|
|
|
|
2015-09-02 19:57:24 +02:00
|
|
|
local item_amt = pr:next(1, size)
|
|
|
|
|
2019-09-21 16:36:53 +02:00
|
|
|
local types
|
|
|
|
if is_locked then
|
|
|
|
types = goodies.types_all
|
|
|
|
else
|
|
|
|
types = goodies.types
|
|
|
|
end
|
|
|
|
|
2015-09-02 19:57:24 +02:00
|
|
|
for i = 1, item_amt do
|
2019-09-21 16:36:53 +02:00
|
|
|
local item = util.choice(types[ctype], pr)
|
|
|
|
local goodie = types[ctype][item]
|
2019-09-21 14:56:37 +02:00
|
|
|
local chance, max_stack
|
|
|
|
if type(goodie) == "table" then
|
|
|
|
chance = goodie.chance
|
|
|
|
max_stack = goodie.max_stack
|
|
|
|
else
|
|
|
|
chance = goodie
|
|
|
|
max_stack = goodies.max_stack_default
|
|
|
|
end
|
2015-09-02 19:57:24 +02:00
|
|
|
if pr:next(1, chance) <= 1 then
|
2019-09-21 14:56:37 +02:00
|
|
|
local max = math.min(max_stack, minetest.registered_items[item].stack_max)
|
2019-09-03 17:32:24 +02:00
|
|
|
local itemstr = item.." "..pr:next(1, max)
|
2015-09-02 19:57:24 +02:00
|
|
|
inv:set_stack(listname, pr:next(1, size), ItemStack(itemstr))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|