1 local world_path = minetest.get_worldpath()
2 local org_file = world_path .. "/beds_spawns"
3 local file = world_path .. "/beds_spawns"
6 -- check for PA's beds mod spawns
7 local cf = io.open(world_path .. "/beds_player_spawns", "r")
10 file = world_path .. "/beds_player_spawns"
14 function beds.read_spawns()
15 local spawns = beds.spawn
16 local input = io.open(file, "r")
17 if input and not bkwd then
19 local x = input:read("*n")
23 local y = input:read("*n")
24 local z = input:read("*n")
25 local name = input:read("*l")
26 spawns[name:sub(2)] = {x = x, y = y, z = z}
27 until input:read(0) == nil
29 elseif input and bkwd then
30 beds.spawn = minetest.deserialize(input:read("*all"))
33 os.rename(file, file .. ".backup")
40 function beds.save_spawns()
41 if not beds.spawn then
45 local output = io.open(org_file, "w")
46 for k, v in pairs(beds.spawn) do
47 table.insert(data, string.format("%.1f %.1f %.1f %s\n", v.x, v.y, v.z, k))
49 output:write(table.concat(data))
53 function beds.set_spawns()
54 for name,_ in pairs(beds.player) do
55 local player = minetest.get_player_by_name(name)
56 local p = player:getpos()
57 -- but don't change spawn location if borrowing a bed
58 if not minetest.is_protected(p, name) then