Skip to content

Commit

Permalink
findSpawnPos: Add setting for max height above water level
Browse files Browse the repository at this point in the history
Increase default from 6 to 16 to help with mgv7 and mgfractal
Large-scale or alternative mapgens can result in a lowland spawn point not
being found, causing a spawn at (0, 0, 0) possibly buried underground
The max height is now settable to allow correct player spawn
in any mapgen or when using custom noise parameters
  • Loading branch information
paramat committed Oct 29, 2015
1 parent 182b3fd commit c0a7c67
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions builtin/settingtypes.txt
Expand Up @@ -693,6 +693,12 @@ enable_pvp (Player versus Player) bool true
# If this is set, players will always (re)spawn at the given position.
static_spawnpoint (Static spawnpoint) string

# Maximum distance above water level for player spawn.
# Larger values result in spawn points closer to (x = 0, z = 0).
# Smaller values may result in a suitable spawn point not being found,
# resulting in a spawn at (0, 0, 0) possibly buried underground.
vertical_spawn_range (Vertical spawn range) int 16

# If enabled, new players cannot join with an empty password.
disallow_empty_password (Disallow empty passwords) bool false

Expand Down
7 changes: 7 additions & 0 deletions minetest.conf.example
Expand Up @@ -829,6 +829,13 @@
# type: string
# static_spawnpoint =

# Maximum distance above water level for player spawn.
# Larger values result in spawn points closer to (x = 0, z = 0).
# Smaller values may result in a suitable spawn point not being found,
# resulting in a spawn at (0, 0, 0) possibly buried underground.
# type: int
# vertical_spawn_range = 16

# If enabled, new players cannot join with an empty password.
# type: bool
# disallow_empty_password = false
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Expand Up @@ -245,6 +245,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("default_privs", "interact, shout");
settings->setDefault("player_transfer_distance", "0");
settings->setDefault("enable_pvp", "true");
settings->setDefault("vertical_spawn_range", "16");
settings->setDefault("disallow_empty_password", "false");
settings->setDefault("disable_anticheat", "false");
settings->setDefault("enable_rollback_recording", "false");
Expand Down
8 changes: 4 additions & 4 deletions src/server.cpp
Expand Up @@ -3269,7 +3269,7 @@ v3f Server::findSpawnPos()
}

s16 water_level = map.getWaterLevel();

s16 vertical_spawn_range = g_settings->getS16("vertical_spawn_range");
bool is_good = false;

// Try to find a good place a few times
Expand All @@ -3282,9 +3282,9 @@ v3f Server::findSpawnPos()

// Get ground height at point
s16 groundheight = map.findGroundLevel(nodepos2d);
if (groundheight <= water_level) // Don't go underwater
continue;
if (groundheight > water_level + 6) // Don't go to high places
// Don't go underwater or to high places
if (groundheight <= water_level ||
groundheight > water_level + vertical_spawn_range)
continue;

v3s16 nodepos(nodepos2d.X, groundheight, nodepos2d.Y);
Expand Down

0 comments on commit c0a7c67

Please sign in to comment.