diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index f763a23c98..495927a1fe 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -194,6 +194,7 @@ function mcl_beds.sleep() end end +-- Throw all players out of bed function mcl_beds.kick_players() for name, _ in pairs(mcl_beds.player) do local player = minetest.get_player_by_name(name) @@ -201,6 +202,14 @@ function mcl_beds.kick_players() end end +-- Throw a player out of bed +function mcl_beds.kick_player(player) + local name = player:get_player_name() + if mcl_beds.player[name] ~= nil then + lay_down(player, nil, nil, false) + end +end + function mcl_beds.skip_night() minetest.set_timeofday(0.25) -- tod = 6000 end @@ -305,3 +314,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) mcl_beds.sleep() end end) + +minetest.register_on_player_hpchange(function(player, hp_change) + if hp_change < 0 then + mcl_beds.kick_player(player) + end +end)