From 8982e368ecb1e4146a74d75508eea5c593388f60 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 20 Feb 2019 16:09:39 +0100 Subject: [PATCH] Abort sleep if taking damage --- mods/ITEMS/mcl_beds/functions.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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)