Put sand into chests in sand-flooded pyramids

This commit is contained in:
Wuzzy 2019-08-20 03:14:39 +02:00
parent acc22a5576
commit fb6cbbea66
2 changed files with 19 additions and 11 deletions

View File

@ -30,17 +30,24 @@ else
table.insert(chest_stuff, {name="farming:apple", max = 3}) table.insert(chest_stuff, {name="farming:apple", max = 3})
end end
function tsm_pyramids.fill_chest(pos) function tsm_pyramids.fill_chest(pos, stype, flood_sand)
minetest.after(2, function() minetest.after(2, function()
local sand = "default:sand"
if stype == "desert" then
sand = "default:desert_sand"
end
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
if n and n.name and n.name == "default:chest" then if n and n.name and n.name == "default:chest" then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", 8*4) inv:set_size("main", 8*4)
if math.random(1,10) < 7 then
return
end
local stacks = {} local stacks = {}
-- Fill with sand in sand-flooded pyramids
if flood_sand then
table.insert(stacks, {name=sand, count = math.random(1,40)})
end
-- Add treasures
if math.random(1,10) >= 7 then
if minetest.get_modpath("treasurer") ~= nil then if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"}) stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
else else
@ -49,6 +56,7 @@ function tsm_pyramids.fill_chest(pos)
table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)}) table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)})
end end
end end
end
for s=1,#stacks do for s=1,#stacks do
if not inv:contains_item("main", stacks[s]) then if not inv:contains_item("main", stacks[s]) then
inv:set_stack("main", math.random(1,32), stacks[s]) inv:set_stack("main", math.random(1,32), stacks[s])

View File

@ -635,7 +635,7 @@ function tsm_pyramids.make_room(pos, stype, room_id)
local filled = 0 local filled = 0
while filled < 8 do while filled < 8 do
for c=1, #chests do for c=1, #chests do
tsm_pyramids.fill_chest(chests[c]) tsm_pyramids.fill_chest(chests[c], stype, room.flood_sand ~= false)
filled = filled + 1 filled = filled + 1
end end
end end