1 Commits

Author SHA1 Message Date
whosit
e0cc038f43 Fix find_nether_ground_y causing freezing (#89)
Refactor the function to use a while loop.
Remove useless recursive call causing freezing.
2025-09-16 20:50:59 +02:00
2 changed files with 12 additions and 5 deletions

View File

@@ -57,8 +57,8 @@ nether.fogColor = { -- only used if climate_api is installed
-- Settings -- Settings
nether.DEPTH_CEILING = -25000 -- The y location of the Nether's celing nether.DEPTH_CEILING = -5000 -- The y location of the Nether's celing
nether.DEPTH_FLOOR = -31000 -- The y location of the Nether's floor nether.DEPTH_FLOOR = -11000 -- The y location of the Nether's floor
nether.FASTTRAVEL_FACTOR = 8 -- 10 could be better value for Minetest, since there's no sprint, but ex-Minecraft players will be mathing for 8 nether.FASTTRAVEL_FACTOR = 8 -- 10 could be better value for Minetest, since there's no sprint, but ex-Minecraft players will be mathing for 8
nether.PORTAL_BOOK_LOOT_WEIGHTING = 0.9 -- Likelyhood of finding the Book of Portals (guide) in dungeon chests. Set to 0 to disable. nether.PORTAL_BOOK_LOOT_WEIGHTING = 0.9 -- Likelyhood of finding the Book of Portals (guide) in dungeon chests. Set to 0 to disable.
nether.NETHER_REALM_ENABLED = true -- Setting to false disables the Nether and Nether portal nether.NETHER_REALM_ENABLED = true -- Setting to false disables the Nether and Nether portal

View File

@@ -495,8 +495,13 @@ function nether.find_nether_ground_y(target_x, target_z, start_y, player_name)
local minp = {x = minp_schem.x, y = 0, z = minp_schem.z} local minp = {x = minp_schem.x, y = 0, z = minp_schem.z}
local maxp = {x = maxp_schem.x, y = 0, z = maxp_schem.z} local maxp = {x = maxp_schem.x, y = 0, z = maxp_schem.z}
for y = start_y, math_max(NETHER_FLOOR + BLEND, start_y - 4096), -1 do local sample_pos = vector.new(target_x, 0, target_z) -- reuse to avoid making new tables
local nval_cave = nobj_cave_point:get_3d({x = target_x, y = y, z = target_z}) local y = start_y
local limit_y = math_max(NETHER_FLOOR + BLEND, start_y - 4096)
while y >= limit_y do
sample_pos.y = y
local nval_cave = nobj_cave_point:get_3d(sample_pos)
if nval_cave > TCAVE then -- Cavern if nval_cave > TCAVE then -- Cavern
air = air + 1 air = air + 1
@@ -509,12 +514,14 @@ function nether.find_nether_ground_y(target_x, target_z, start_y, player_name)
if nether.volume_is_natural_and_unprotected(minp, maxp, player_name) then if nether.volume_is_natural_and_unprotected(minp, maxp, player_name) then
return portal_y return portal_y
else -- Restart search a little lower else -- Restart search a little lower
nether.find_nether_ground_y(target_x, target_z, y - 16, player_name) air = 0 -- space above is unsuitable
y = y - 16
end end
else -- Not enough space, reset air to zero else -- Not enough space, reset air to zero
air = 0 air = 0
end end
end end
y = y - 1
end end
return math_max(start_y, NETHER_FLOOR + BLEND) -- Fallback return math_max(start_y, NETHER_FLOOR + BLEND) -- Fallback