Skip to content

Commit

Permalink
Fix a crash in ambient sound biome checking when the player is halfwa…
Browse files Browse the repository at this point in the history
…y between level 2 and level 3. Also add API to puzzle chests

This fixes issue #39
  • Loading branch information
FaceDeer committed Oct 22, 2022
1 parent 5ea9ee9 commit a6cd433
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
7 changes: 6 additions & 1 deletion df_caverns/level3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions df_caverns/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions df_caverns/underworld.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a6cd433

Please sign in to comment.