Explicit msgs when respawn pos changed due to bed

This commit is contained in:
Wuzzy 2019-02-20 19:39:12 +01:00
parent ec53db9352
commit 079b09c80f
3 changed files with 32 additions and 4 deletions

View file

@ -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 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." 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 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 end
if minetest.settings:get_bool("enable_bed_night_skip") == false then 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." beddesc = beddesc .. "\n" .. "In this strange world, going to bed won't skip the night, but you can skip thunderstorms."

View file

@ -143,19 +143,27 @@ local function lay_down(player, pos, bed_pos, state, skip)
return false return false
end end
local spawn_changed = false
if minetest.get_modpath("mcl_spawn") then if minetest.get_modpath("mcl_spawn") then
local spos = table.copy(bed_pos) local spos = table.copy(bed_pos)
spos.y = spos.y + 0.1 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 end
-- Check day of time and weather -- Check day of time and weather
local tod = minetest.get_timeofday() * 24000 local tod = minetest.get_timeofday() * 24000
-- Values taken from Minecraft Wiki with offset of +6000 -- 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 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 return false
end end
if spawn_changed then
minetest.chat_send_player(name, "New respawn position set!")
end
mcl_beds.player[name] = 1 mcl_beds.player[name] = 1
mcl_beds.pos[name] = pos mcl_beds.pos[name] = pos

View file

@ -32,12 +32,32 @@ end
-- Sets the player's spawn position to pos. -- Sets the player's spawn position to pos.
-- Set pos to nil to clear the spawn position. -- 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 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", "") player:set_attribute("mcl_beds:spawn", "")
else 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)) player:set_attribute("mcl_beds:spawn", minetest.pos_to_string(pos))
end end
return spawn_changed
end end
-- Respawn player at specified respawn position -- Respawn player at specified respawn position