Skip to content

Commit 0b025e6

Browse files
authoredApr 13, 2018
Add 'spawn' mod to spawn new players in suitable starting biomes (#2091)
Disabled in mgv6 and singlenode mapgens, by setting, or if 'static_spawnpoint' is set. Cleanup format of minetest.conf.example.
1 parent 8d8f2f7 commit 0b025e6

File tree

6 files changed

+187
-17
lines changed

6 files changed

+187
-17
lines changed
 

Diff for: ‎minetest.conf.example

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
# This file contains settings of Minetest Game that can be changed in minetest.conf
1+
# This file contains settings of Minetest Game that can be changed in
2+
# minetest.conf.
23
# By default, all the settings are commented and not functional.
34
# Uncomment settings by removing the preceding #.
45

5-
# Whether creative mode (fast digging of all blocks, unlimited resources) should be enabled
6+
# Whether creative mode (fast digging of all blocks, unlimited resources) should
7+
# be enabled.
68
#creative_mode = false
79

810
# Sets the behaviour of the inventory items when a player dies.
9-
# "bones": Store all items inside a bone node but drop items if inside protected area
10-
# "drop": Drop all items on the ground
11-
# "keep": Player keeps all items
11+
# "bones": Store items in a bone node but drop items if inside protected area.
12+
# "drop": Drop items on the ground.
13+
# "keep": Player keeps items.
1214
#bones_mode = "bones"
1315

14-
# The time in seconds after which the bones of a dead player can be looted by everyone
15-
# 0 to disable
16+
# The time in seconds after which the bones of a dead player can be looted by
17+
# everyone.
18+
# 0 to disable.
1619
#share_bones_time = 1200
1720

1821
# How much earlier the bones of a dead player can be looted by
1922
# everyone if the player dies in a protected area they don't own.
2023
# 0 to disable. By default it is "share_bones_time" divide by four.
2124
#share_bones_time_early = 300
2225

23-
# Whether fire should be enabled. If disabled, 'basic flame' nodes will disappear.
24-
# 'permanent flame' nodes will remain with either setting.
26+
# Whether fire should be enabled. If disabled, 'basic_flame' nodes will
27+
# disappear.
28+
# 'permanent_flame' nodes will remain with either setting.
2529
#enable_fire = true
2630

2731
# Enable flame sound.
@@ -30,24 +34,30 @@
3034
# Whether lavacooling should be enabled.
3135
#enable_lavacooling = true
3236

33-
# Whether the stuff in initial_stuff should be given to new players
37+
# Whether the stuff in initial_stuff should be given to new players.
3438
#give_initial_stuff = false
35-
#initial_stuff = default:pick_steel,default:axe_steel,default:shovel_steel,default:torch 99,default:cobble 99
39+
#initial_stuff = default:pick_steel,default:axe_steel,default:shovel_steel,
40+
default:torch 99,default:cobble 99
3641

37-
# Whether the TNT mod should be enabled
42+
# Whether the TNT mod should be enabled.
3843
#enable_tnt = <true in singleplayer, false in multiplayer>
3944

40-
# The radius of a TNT explosion
45+
# The radius of a TNT explosion.
4146
#tnt_radius = 3
4247

4348
# Enable the stairs mod ABM that replaces the old 'upside down'
4449
# stair and slab nodes in old maps with the new param2 versions.
4550
#enable_stairs_replace_abm = false
4651

47-
# Whether you allow respawning in beds
48-
# Default value is true
52+
# Whether to allow respawning in beds.
53+
# Default value is true.
4954
#enable_bed_respawn = true
5055

51-
# Whether players can skip night by sleeping
52-
# Default value is true
56+
# Whether players can skip night by sleeping.
57+
# Default value is true.
5358
#enable_bed_night_skip = true
59+
60+
# Whether the engine's spawn search, which does not check for a suitable
61+
# starting biome, is used.
62+
# Default value is false.
63+
#engine_spawn = false

Diff for: ‎mods/spawn/README.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Minetest Game mod: spawn
2+
========================
3+
See license.txt for license information.
4+
5+
Authors of source code
6+
----------------------
7+
paramat (MIT)

Diff for: ‎mods/spawn/depends.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default

Diff for: ‎mods/spawn/init.lua

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
-- Disable by mapgen, setting or if 'static_spawnpoint' is set
2+
--------------------------------------------------------------
3+
4+
local mg_name = minetest.get_mapgen_setting("mg_name")
5+
if mg_name == "v6" or mg_name == "singlenode" or
6+
minetest.settings:get("static_spawnpoint") or
7+
minetest.settings:get_bool("engine_spawn") then
8+
return
9+
end
10+
11+
12+
-- Parameters
13+
-------------
14+
15+
-- Resolution of search grid in nodes.
16+
local res = 64
17+
-- Number of points checked in the square search grid (edge * edge).
18+
local checks = 128 * 128
19+
-- Starting point for biome checks. This also sets the y co-ordinate for all
20+
-- points checked, so the suitable biomes must be active at this y.
21+
local pos = {x = 0, y = 8, z = 0}
22+
23+
24+
-- Table of suitable biomes
25+
26+
local biome_ids = {
27+
minetest.get_biome_id("taiga"),
28+
minetest.get_biome_id("coniferous_forest"),
29+
minetest.get_biome_id("deciduous_forest"),
30+
minetest.get_biome_id("grassland"),
31+
minetest.get_biome_id("savanna"),
32+
}
33+
34+
-- End of parameters
35+
--------------------
36+
37+
38+
-- Direction table
39+
40+
local dirs = {
41+
{x = 0, y = 0, z = 1},
42+
{x = -1, y = 0, z = 0},
43+
{x = 0, y = 0, z = -1},
44+
{x = 1, y = 0, z = 0},
45+
}
46+
47+
48+
-- Initial variables
49+
50+
local edge_len = 1
51+
local edge_dist = 0
52+
local dir_step = 0
53+
local dir_ind = 1
54+
local searched = false
55+
local success = false
56+
local spawn_pos = {}
57+
58+
59+
--Functions
60+
-----------
61+
62+
-- Get next position on square search spiral
63+
64+
local function next_pos()
65+
if edge_dist == edge_len then
66+
edge_dist = 0
67+
dir_ind = dir_ind + 1
68+
if dir_ind == 5 then
69+
dir_ind = 1
70+
end
71+
dir_step = dir_step + 1
72+
edge_len = math.floor(dir_step / 2) + 1
73+
end
74+
75+
local dir = dirs[dir_ind]
76+
local move = vector.multiply(dir, res)
77+
78+
edge_dist = edge_dist + 1
79+
80+
return vector.add(pos, move)
81+
end
82+
83+
84+
-- Spawn position search
85+
86+
local function search()
87+
for iter = 1, checks do
88+
local biome_data = minetest.get_biome_data(pos)
89+
-- Sometimes biome_data is nil
90+
local biome = biome_data and biome_data.biome
91+
for id_ind = 1, #biome_ids do
92+
local biome_id = biome_ids[id_ind]
93+
if biome == biome_id then
94+
local spawn_y = minetest.get_spawn_level(pos.x, pos.z)
95+
if spawn_y then
96+
spawn_pos = {x = pos.x, y = spawn_y, z = pos.z}
97+
return true
98+
end
99+
end
100+
end
101+
102+
pos = next_pos()
103+
end
104+
105+
return false
106+
end
107+
108+
109+
-- On new player spawn
110+
111+
-- Search for new player spawn once per server session. If successful, store
112+
-- position and reposition new players, otherwise leave them at engine spawn
113+
-- position.
114+
115+
minetest.register_on_newplayer(function(player)
116+
if not searched then
117+
success = search()
118+
searched = true
119+
end
120+
121+
if success then
122+
player:setpos(spawn_pos)
123+
end
124+
end)

Diff for: ‎mods/spawn/license.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
License of source code
2+
----------------------
3+
4+
The MIT License (MIT)
5+
Copyright (C) 2018 paramat
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
8+
software and associated documentation files (the "Software"), to deal in the Software
9+
without restriction, including without limitation the rights to use, copy, modify, merge,
10+
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
11+
persons to whom the Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all copies or
14+
substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
19+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
DEALINGS IN THE SOFTWARE.
22+
23+
For more details:
24+
https://opensource.org/licenses/MIT

Diff for: ‎settingtypes.txt

+4
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ share_bones_time (Bone share time) int 1200 0
4646

4747
# Replaces old stairs with new ones. Only required for older worlds.
4848
enable_stairs_replace_abm (Replace old stairs) bool false
49+
50+
# If enabled, use the engine's spawn search which does not check for a
51+
# suitable starting biome.
52+
engine_spawn (Use engine spawn search) bool false

0 commit comments

Comments
 (0)
Please sign in to comment.