Refuse to teleport outside of map
parent
b7da2a5fb8
commit
0d433daa23
|
@ -9,7 +9,6 @@ Version: 0.2.0
|
|||
|
||||
## Known bugs and limitations
|
||||
- Will only search for biomes in the same height as you.
|
||||
- Might teleport you outside the map boundaries if you're close to one.
|
||||
|
||||
## Authors
|
||||
- paramat (MIT License)
|
||||
|
|
18
init.lua
18
init.lua
|
@ -1,6 +1,12 @@
|
|||
local S = minetest.get_translator("findbiome")
|
||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||
|
||||
local mod_biomeinfo = minetest.get_modpath("biomeinfo") ~= nil
|
||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||
|
||||
-- Calculate the maximum playable limit
|
||||
local mapgen_limit = tonumber(minetest.get_mapgen_setting("mapgen_limit"))
|
||||
local chunksize = tonumber(minetest.get_mapgen_setting("chunksize"))
|
||||
local playable_limit = math.max(mapgen_limit - (chunksize + 1) * 16, 0)
|
||||
|
||||
-- Parameters
|
||||
-------------
|
||||
|
@ -22,6 +28,10 @@ local dirs = {
|
|||
{x = 1, y = 0, z = 0},
|
||||
}
|
||||
|
||||
local function is_valid_pos(pos)
|
||||
return math.abs(pos.x) > playable_limit or math.abs(pos.y) > playable_limit or math.abs(pos.z) > playable_limit
|
||||
end
|
||||
|
||||
function find_biome(pos, biomes)
|
||||
pos = vector.round(pos)
|
||||
-- Pos: Starting point for biome checks. This also sets the y co-ordinate for all
|
||||
|
@ -69,11 +79,12 @@ function find_biome(pos, biomes)
|
|||
local spawn_y = minetest.get_spawn_level(pos.x, pos.z)
|
||||
if spawn_y then
|
||||
spawn_pos = {x = pos.x, y = spawn_y, z = pos.z}
|
||||
-- FIXME: Don't return true when spawn_pos is out of map bounds
|
||||
if is_valid_pos(spawn_pos) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
pos = next_pos()
|
||||
end
|
||||
|
@ -95,11 +106,12 @@ function find_biome(pos, biomes)
|
|||
local spawn_y = minetest.get_spawn_level(pos.x, pos.z)
|
||||
if spawn_y then
|
||||
spawn_pos = {x = pos.x, y = spawn_y, z = pos.z}
|
||||
-- FIXME: Don't return true when spawn_pos is out of map bounds
|
||||
if is_valid_pos(spawn_pos) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
pos = next_pos()
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue