1
0
Fork 0

Don't respawn on bed if bed is missing or blocked

This commit is contained in:
Wuzzy 2019-02-04 16:53:06 +01:00
parent a285827980
commit a11f6ffaac
2 changed files with 20 additions and 3 deletions

View File

@ -228,7 +228,9 @@ function mcl_beds.on_rightclick(pos, player)
if not mcl_beds.player[name] then
lay_down(player, ppos, pos)
if minetest.get_modpath("mcl_spawn") then
mcl_spawn.set_spawn_pos(player, player:get_pos()) -- save respawn position when entering bed
local spos = table.copy(pos)
spos.y = spos.y + 0.1
mcl_spawn.set_spawn_pos(player, spos) -- save respawn position when entering bed
end
else
lay_down(player, nil, nil, false)

View File

@ -33,8 +33,23 @@ end
minetest.register_on_respawnplayer(function(player)
local pos = mcl_spawn.get_spawn_pos(player)
if pos then
player:set_pos(pos)
return true
-- Check if bed is still there
-- and the spawning position is free of solid or damaging blocks.
local node_bed = minetest.get_node(pos)
local node_up1 = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
local node_up2 = minetest.get_node({x=pos.x,y=pos.y+2,z=pos.z})
local bgroup = minetest.get_item_group(node_bed.name, "bed")
local def1 = minetest.registered_nodes[node_up1.name]
local def2 = minetest.registered_nodes[node_up2.name]
if (bgroup == 1 or bgroup == 2) and
(not def1.walkable) and (not def2.walkable) and
(def1.damage_per_second == nil or def2.damage_per_second <= 0) and
(def1.damage_per_second == nil or def2.damage_per_second <= 0) then
player:set_pos(pos)
return true
else
minetest.chat_send_player(player:get_player_name(), "Your spawn bed was missing or blocked.")
end
end
end)