Adding better bed handling.

Now the bed will freeze you no matter of speed thus
removing the need to ask the player to stop before going
to bed, it is rather buggy when the map is still loading
but that's going to be addressed later.
This commit is contained in:
sergiotarxz 2022-02-12 17:39:52 +01:00
parent eb9ac2bb10
commit 60f07bbfd7
4 changed files with 121 additions and 14 deletions

View File

@ -204,8 +204,13 @@ local function on_globalstep(dtime)
local data = bed.userdata.saved[in_bed[p]]
if data then
local player = minetest.get_player_by_name(in_bed[p])
if vector.distance(player:get_pos(), data.spawn_pos) > 2 then
local freezed = player:get_attribute('bed:freezed')
if freezed == nil then
local name = player:get_player_name()
local yaw = bed.userdata.saved[name].spawn_yaw
player:move_to(data.spawn_pos)
freeze_maybe_jail_user(player, yaw)
player:set_attribute('bed:freezed', 'true')
end
end
end
@ -314,6 +319,7 @@ minetest.register_node(
end
local dir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.chat_send_all(('%d'):format(dir))
local botpos = vector.add(pos, minetest.facedir_to_dir(dir))
if minetest.is_protected(botpos, placer:get_player_name()) and
@ -375,6 +381,8 @@ minetest.register_node(
bed.userdata.temp[name].in_bed = false
take_player_from_bed(clicker)
unfreeze_user(clicker);
clicker:set_attribute('bed:freezed', nil)
meta:set_string("player", "")
elseif meta:get_string("player") == "" and not default.player_attached[name]
@ -401,19 +409,9 @@ minetest.register_node(
end
end
-- No sleeping while moving
if vector.length(clicker:get_velocity()) > 0.001 then
minetest.chat_send_player(name, minetest.colorize("#FFFF00", S("You have to stop moving before going to bed!")))
return itemstack
end
put_pos.y = put_pos.y + 0.6
local yaw = 0
if node.param2 ~= 2 then
yaw = (node.param2 / 2.0) * math.pi
end
local yaw = math.pi * 2 - minetest.dir_to_yaw(dir)
bed.userdata.temp[name].in_bed = true

23
mods/freeze/LICENSE Normal file
View File

@ -0,0 +1,23 @@
MIT License
Copyright (c) 2018 IhrFussel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Texture is by Shara RedCat (CC BY-SA 3.0)

86
mods/freeze/init.lua Normal file
View File

@ -0,0 +1,86 @@
local trap = nil
local mode = nil
local scope = "public" -- Set scope of the chat message (public or private)
function freeze_maybe_jail_user(player, yaw)
trap = player:get_player_name()
mode = "a"
local pos = player:get_pos()
pos.y = pos.y - 0.25
minetest.add_entity(pos, "freeze:fe")
end
function unfreeze_user(player)
mode = "d"
trap = player:get_player_name()
end
minetest.register_entity("freeze:fe", {
physical = false,
collisionbox = {-0.00,-0.00,-0.00, 0.00,0.00,0.00},
visual = "sprite",
visual_size = {x=0, y=0},
textures = {"freeze_t.png"},
is_visible = true,
makes_footstep_sound = false,
on_activate = function(self, staticdata)
self.object:set_armor_groups({immortal = 1})
if not trap or not mode or self.trapped then
return
end
local playerobj = minetest.get_player_by_name(trap)
if not playerobj then
return
end
if mode == "a" then
local yaw = bed.userdata.saved[trap].spawn_yaw
local yaw_in_degrees = (yaw + math.pi) / math.pi * 180
minetest.chat_send_player(trap, ('%.02f %d'):format(yaw, yaw_in_degrees))
playerobj:set_attach(self.object, "", {x=0,y=0,z=0}, {x=yaw_in_degrees,y=0,z=90})
self.trapped = trap
trap = nil
mode = nil
end
end,
on_step = function(self,dtime)
if not trap or not mode then
return
end
if mode == "d" and trap == self.trapped then
local pobj = minetest.get_player_by_name(trap)
if not pobj then
return
end
pobj:set_detach()
if scope == "public" then
minetest.chat_send_all("*** "..trap.." can move again.")
else
minetest.chat_send_player(trap,"You can move now again.")
end
trap = nil
mode = nil
self.object:remove()
end
end,
})
minetest.register_on_leaveplayer(function(player)
local ppos = player:get_pos()
for _, obj in ipairs(minetest.get_objects_inside_radius(ppos, 2)) do
obj:remove()
end
end)

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B