From e294a56eee47e63a2768e9ef5a34b9fd28d21673 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 9 Oct 2014 17:21:08 +0200 Subject: [PATCH] Add optional Treasurer support --- depends.txt | 4 +++- init.lua | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/depends.txt b/depends.txt index 331d858..1157f82 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,3 @@ -default \ No newline at end of file +default +farming? +treasurer? diff --git a/init.lua b/init.lua index d40b4de..9216973 100644 --- a/init.lua +++ b/init.lua @@ -23,14 +23,22 @@ function pyramids.fill_chest(pos) local inv = meta:get_inventory() inv:set_size("main", 8*4) if math.random(1,10) < 7 then return end - for i=0,2,1 do - local stuff = chest_stuff[math.random(1,#chest_stuff)] - if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then stuff = chest_stuff[1] end - local stack = {name=stuff.name, count = math.random(1,stuff.max)} - if not inv:contains_item("main", stack) then - inv:set_stack("main", math.random(1,32), stack) + local stacks = {} + if minetest.get_modpath("treasurer") ~= nil then + stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"}) + else + for i=0,2,1 do + local stuff = chest_stuff[math.random(1,#chest_stuff)] + if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then stuff = chest_stuff[1] end + table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)}) end end + for s=1,#stacks do + if not inv:contains_item("main", stacks[s]) then + inv:set_stack("main", math.random(1,32), stacks[s]) + end + end + end end) end