From a6cd433ecfdc0f816c3f49d117aa7d3fb54e3f0c Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sat, 22 Oct 2022 10:02:34 -0600 Subject: [PATCH] Fix a crash in ambient sound biome checking when the player is halfway between level 2 and level 3. Also add API to puzzle chests This fixes issue https://github.com/FaceDeer/dfcaverns/issues/39 --- df_caverns/level3.lua | 7 ++++++- df_caverns/shared.lua | 1 + df_caverns/underworld.lua | 21 ++++++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/df_caverns/level3.lua b/df_caverns/level3.lua index 9c2fc34..5972c9d 100644 --- a/df_caverns/level3.lua +++ b/df_caverns/level3.lua @@ -47,7 +47,12 @@ df_caverns.register_biome_check(function(pos, heat, humidity) end local biome = get_biome(heat, humidity) if biome == "bloodnether" then - if subterrane.get_cavern_value("cavern layer 3", pos) < 0 then + local cavern_value = subterrane.get_cavern_value("cavern layer 3", pos) + if cavern_value == nil then + -- this shouldn't happen, the pos.y check above should prevent it. + return nil + end + if cavern_value < 0 then return "nethercap" end return "bloodthorn" diff --git a/df_caverns/shared.lua b/df_caverns/shared.lua index bf8120a..ffdf1e1 100644 --- a/df_caverns/shared.lua +++ b/df_caverns/shared.lua @@ -28,6 +28,7 @@ df_caverns.register_biome_check = function(func) table.insert(get_biome_at_pos_list, func) end df_caverns.get_biome = function(pos) + pos = vector.round(pos) local heat = minetest.get_heat(pos) local humidity = minetest.get_humidity(pos) for _, val in pairs(get_biome_at_pos_list) do diff --git a/df_caverns/underworld.lua b/df_caverns/underworld.lua index 6ad18f7..bdd32f0 100644 --- a/df_caverns/underworld.lua +++ b/df_caverns/underworld.lua @@ -17,6 +17,17 @@ if mapgen_helper.log_location_enabled then log_location = mapgen_helper.log_first_location end +-- Exposed as a global so that other mods can override it. +df_caverns.populate_puzzle_chest = function(pos) + local meta = minetest.get_meta(pos) + 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 + local name_pit = function() end local name_ruin = function() end @@ -81,8 +92,6 @@ if named_waypoints_path then end end - - local c_slade = df_caverns.node_id.slade local c_slade_block = df_caverns.node_id.slade_block local c_air = df_caverns.node_id.air @@ -496,13 +505,7 @@ minetest.register_on_generated(function(minp, maxp, seed) 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 + df_caverns.populate_puzzle_chest(puzzle_chest) end end) elseif building.building_type == "medium building" then