From 9212a3df74cfe5b39028be971638962f22828f0c Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Fri, 26 Aug 2022 22:32:38 -0600 Subject: [PATCH] oops, can't initialize the contents of puzzle chests every time or players get endless stuff --- df_caverns/underworld.lua | 15 +++++++++++++++ df_underworld_items/puzzle_chest.lua | 10 ++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/df_caverns/underworld.lua b/df_caverns/underworld.lua index 8cf8f1c..6ad18f7 100644 --- a/df_caverns/underworld.lua +++ b/df_caverns/underworld.lua @@ -490,6 +490,21 @@ minetest.register_on_generated(function(minp, maxp, seed) end) elseif building.building_type == "small building" then mapgen_helper.place_schematic_on_data(data, data_param2, area, building.pos, small_building_schematic, building.rotation) + local pos = building.pos + minetest.after(1, function() + local puzzle_chest = minetest.find_node_near(pos, 4, {"df_underworld_items:puzzle_chest_closed"}, true) + if puzzle_chest then + local def = minetest.registered_nodes["df_underworld_items:puzzle_chest_closed"] + def.can_dig(puzzle_chest) -- initializes the inventory + local meta = minetest.get_meta(puzzle_chest) + local inv = meta:get_inventory() + for i = 1, math.random(1,8) do + local item = ItemStack(df_underworld_items.colour_items[math.random(1,#df_underworld_items.colour_items)]) + --item:set_count(math.random(1,4)) + inv:add_item("main", item) + end + end + end) elseif building.building_type == "medium building" then mapgen_helper.place_schematic_on_data(data, data_param2, area, building.pos, medium_building_schematic, building.rotation) if name_generator_path then diff --git a/df_underworld_items/puzzle_chest.lua b/df_underworld_items/puzzle_chest.lua index 130c2ca..92e94a7 100644 --- a/df_underworld_items/puzzle_chest.lua +++ b/df_underworld_items/puzzle_chest.lua @@ -7,14 +7,7 @@ end local initialize = function(pos, meta) if not meta:contains("key") then local inv = meta:get_inventory() - inv:set_size("main", 8) - - for i = 1, math.random(1,8) do - local item = ItemStack(df_underworld_items.colour_items[math.random(1,#df_underworld_items.colour_items)]) - --item:set_count(math.random(1,4)) - inv:add_item("main", item) - end - + inv:set_size("main", 8) local next_seed = math.random() * 2^21 math.randomseed(pos.x + pos.y^8 + pos.z^16) -- Key is consistent with location @@ -81,6 +74,7 @@ local show_formspec = function(pos, node, clicker, itemstack, pointed_thing) local nodemeta = "nodemeta:"..pos.x..","..pos.y..","..pos.z formspec = formspec .. "list["..nodemeta..";main;0.6,5.4;8,1;]" + .. "listring[]" if meta:get_string("solved") ~= "true" then minetest.sound_play("dfcaverns_puzzle_chest_open", {pos = pos}) meta:set_string("solved", "true")