From a11f6ffaacf7d4607a03107a0da5ee8c1e2ca561 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 4 Feb 2019 16:53:06 +0100 Subject: [PATCH] Don't respawn on bed if bed is missing or blocked --- mods/ITEMS/mcl_beds/functions.lua | 4 +++- mods/PLAYER/mcl_spawn/init.lua | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 2843bdd4d..bb45a063c 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -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) diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index cc8463c3b..65853028d 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -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)