From 079b09c80f1a01d8ac0a4041c9c83e3963be4c2e Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 20 Feb 2019 19:39:12 +0100 Subject: [PATCH] Explicit msgs when respawn pos changed due to bed --- mods/ITEMS/mcl_beds/api.lua | 2 +- mods/ITEMS/mcl_beds/functions.lua | 12 ++++++++++-- mods/PLAYER/mcl_spawn/init.lua | 22 +++++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_beds/api.lua b/mods/ITEMS/mcl_beds/api.lua index 708f529c8f..b6f18ea424 100644 --- a/mods/ITEMS/mcl_beds/api.lua +++ b/mods/ITEMS/mcl_beds/api.lua @@ -37,7 +37,7 @@ local beduse = "To use a bed, stand close to it and right-click the bed to sleep if minetest.settings:get_bool("enable_bed_respawn") == false then beddesc = beddesc .. "\n" .. "In local folklore, legends are told of other worlds where setting the start point for your next life would be possible. But this world is not one of them." else - beddesc = beddesc .. "\n" .. "By sleeping in a bed, you set the starting point for your next life. If you die, you will start your next life at this bed, unless it is obstructed or destroyed." + beddesc = beddesc .. "\n" .. "By using a bed, you set the starting point for your next life. If you die, you will start your next life at this bed, unless it is obstructed or destroyed." end if minetest.settings:get_bool("enable_bed_night_skip") == false then beddesc = beddesc .. "\n" .. "In this strange world, going to bed won't skip the night, but you can skip thunderstorms." diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 2232f6da45..e20bb8c517 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -143,19 +143,27 @@ local function lay_down(player, pos, bed_pos, state, skip) return false end + local spawn_changed = false if minetest.get_modpath("mcl_spawn") then local spos = table.copy(bed_pos) spos.y = spos.y + 0.1 - mcl_spawn.set_spawn_pos(player, spos) -- save respawn position when entering bed + spawn_changed = mcl_spawn.set_spawn_pos(player, spos) -- save respawn position when entering bed end -- Check day of time and weather local tod = minetest.get_timeofday() * 24000 -- Values taken from Minecraft Wiki with offset of +6000 if tod < 18541 and tod > 5458 and (not weather_mod or (mcl_weather.get_weather() ~= "thunder")) then - minetest.chat_send_player(name, "You can only sleep at night or during a thunderstorm.") + if spawn_changed then + minetest.chat_send_player(name, "New respawn position set! But you can only sleep at night or during a thunderstorm.") + else + minetest.chat_send_player(name, "You can only sleep at night or during a thunderstorm.") + end return false end + if spawn_changed then + minetest.chat_send_player(name, "New respawn position set!") + end mcl_beds.player[name] = 1 mcl_beds.pos[name] = pos diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index f97f1700cb..5c8a797eb0 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -32,12 +32,32 @@ end -- Sets the player's spawn position to pos. -- Set pos to nil to clear the spawn position. -mcl_spawn.set_spawn_pos = function(player, pos, type) +-- If message is set, informs the player with a chat message when the spawn position +-- changed. +mcl_spawn.set_spawn_pos = function(player, pos, message) + local spawn_changed = false if pos == nil then + if player:get_attribute("mcl_beds:spawn") ~= "" then + spawn_changed = true + if message then + minetest.chat_send_player(player:get_player_name(), "Respawn position cleared!") + end + end player:set_attribute("mcl_beds:spawn", "") else + local oldpos = minetest.string_to_pos(player:get_attribute("mcl_beds:spawn")) + if oldpos then + -- We don't bother sending a message if the new spawn pos is basically the same + if vector.distance(pos, oldpos) > 0.1 then + spawn_changed = true + if message then + minetest.chat_send_player(player:get_player_name(), "New respawn position set!") + end + end + end player:set_attribute("mcl_beds:spawn", minetest.pos_to_string(pos)) end + return spawn_changed end -- Respawn player at specified respawn position