Add random chests into dungeons

This commit is contained in:
Wuzzy 2017-05-24 10:55:25 +02:00
parent e65a8731de
commit 231f12e3fa
2 changed files with 81 additions and 5 deletions

View File

@ -1 +1,3 @@
mcl_init
mcl_core
mcl_chests

View File

@ -1,5 +1,62 @@
-- FIXME: Rarely, dungoens can overlap and destroy each other
local pr = PseudoRandom(os.time())
-- Get loot for dungeon chests
local get_loot = function()
local items = mcl_loot.get_multi_loot({
{
stacks_min = 1,
stacks_max = 3,
items = {
{ itemstring = "mobs:nametag", weight = 20 },
{ itemstring = "mcl_mobitems:saddle", weight = 20 },
{ itemstring = "mcl_jukebox:record_1", weight = 15 },
{ itemstring = "mcl_jukebox:record_4", weight = 15 },
-- TODO: Iron Horse Armor
{ itemstring = "mcl_core:iron_ingot", weight = 15 },
{ itemstring = "mcl_core:apple_gold", weight = 15 },
-- TODO: Enchanted Book
{ itemstring = "mcl_books:book", weight = 10 },
-- TODO: Gold Horse Armor
{ itemstring = "mcl_core:gold_ingot", weight = 5 },
-- TODO: Diamond Horse Armor
{ itemstring = "mcl_core:diamond", weight = 5 },
-- TODO: Enchanted Golden Apple
{ itemstring = "mcl_core:apple_gold", weight = 2 },
}
},
{
stacks_min = 1,
stacks_max = 4,
items = {
{ itemstring = "mcl_farming:wheat_item", weight = 20, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_farming:bread", weight = 20 },
{ itemstring = "mcl_core:coal_lump", weight = 15, amount_min = 1, amount_max = 4 },
{ itemstring = "mesecons:redstone", weight = 15, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_farming:beetroot_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_farming:melon_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_farming:pumpkin_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_core:iron_ingot", weight = 10, amount_min = 1, amount_max = 4 },
{ itemstring = "bucket:bucket_empty", weight = 10 },
{ itemstring = "mcl_core:gold_ingot", weight = 5, amount_min = 1, amount_max = 4 },
},
},
{
stacks_min = 3,
stacks_max = 3,
items = {
{ itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 },
},
}}, pr)
return items
end
-- Buffer for LuaVoxelManip
local lvm_buffer = {}
@ -18,6 +75,9 @@ minetest.register_on_generated(function(minp, maxp)
local c_cobble = minetest.get_content_id("mcl_core:cobble")
local c_mossycobble = minetest.get_content_id("mcl_core:mossycobble")
-- Remember chest positions to set metadata later
local chest_posses = {}
-- Calculate the number of dungeon spawn attempts
local sizevector = vector.subtract(maxp, minp)
sizevector = vector.add(sizevector, 1)
@ -90,14 +150,12 @@ minetest.register_on_generated(function(minp, maxp)
end
end
if openings > 0 then
--minetest.log("error", minetest.pos_to_string({x=x,y=y,z=z}).."; openings: "..openings)
end
end
-- Check conditions. If okay, start generating
if ceilingfloor_ok and openings >= 1 and openings <= 5 then
local chestsLeft = 2
if ceilingfloor_ok and openings >= 0 and openings <= 5000 then
-- Ceiling and floor
local maxx, maxy, maxz = x+dim.x+1, y+dim.y+1, z+dim.z+1
for tx = x, maxx do
@ -120,7 +178,13 @@ minetest.register_on_generated(function(minp, maxp)
-- Room interiour
else
data[p_pos] = c_air
-- Chest
if ty == y + 1 and chestsLeft > 0 and math.random(1,6) == 1 then
chestsLeft = chestsLeft - 1
table.insert(chest_posses, {x=tx, y=ty, z=tz})
else
data[p_pos] = c_air
end
end
end
end
@ -137,4 +201,14 @@ minetest.register_on_generated(function(minp, maxp)
vm:write_to_map()
end
for c=1, #chest_posses do
minetest.set_node(chest_posses[c], {name="mcl_chests:chest", param2=3})
local meta = minetest.get_meta(chest_posses[c])
local inv = meta:get_inventory()
local items = get_loot()
for i=1, math.min(#items, inv:get_size("main")) do
inv:set_stack("main", i, ItemStack(items[i]))
end
end
end)