Skip to content

Commit 5c3e4b1

Browse files
authoredAug 28, 2019
Spawn: Avoid spawning outside small worlds
Previously, the value of 'mapgen_limit' was not used to limit the spawn position. If a friendly-biome spawn point is not found within a small world, spawn point falls back to the engine spawn point, which has a larger chance of success.
1 parent 553b0f9 commit 5c3e4b1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

Diff for: ‎mods/spawn/init.lua

+13
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ local success = false
5656
local spawn_pos = {}
5757

5858

59+
-- Get world 'mapgen_limit' and 'chunksize' to calculate 'spawn_limit'.
60+
-- This accounts for how mapchunks are not generated if they or their shell exceed
61+
-- 'mapgen_limit'.
62+
63+
local mapgen_limit = tonumber(minetest.get_mapgen_setting("mapgen_limit"))
64+
local chunksize = tonumber(minetest.get_mapgen_setting("chunksize"))
65+
local spawn_limit = math.max(mapgen_limit - (chunksize + 1) * 16, 0)
66+
67+
5968
--Functions
6069
-----------
6170

@@ -100,6 +109,10 @@ local function search()
100109
end
101110

102111
pos = next_pos()
112+
-- Check for position being outside world edge
113+
if math.abs(pos.x) > spawn_limit or math.abs(pos.z) > spawn_limit then
114+
return false
115+
end
103116
end
104117

105118
return false

0 commit comments

Comments
 (0)
Please sign in to comment.