From 60f07bbfd72e84407d74b7454a5a1190e19d95fd Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Sat, 12 Feb 2022 17:39:52 +0100 Subject: [PATCH] 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. --- mods/bed/init.lua | 26 +++++---- mods/freeze/LICENSE | 23 ++++++++ mods/freeze/init.lua | 86 ++++++++++++++++++++++++++++++ mods/freeze/textures/freeze_t.png | Bin 0 -> 96 bytes 4 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 mods/freeze/LICENSE create mode 100644 mods/freeze/init.lua create mode 100644 mods/freeze/textures/freeze_t.png diff --git a/mods/bed/init.lua b/mods/bed/init.lua index f812908..b94a87e 100644 --- a/mods/bed/init.lua +++ b/mods/bed/init.lua @@ -204,9 +204,14 @@ 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 - player:move_to(data.spawn_pos) - end + 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 diff --git a/mods/freeze/LICENSE b/mods/freeze/LICENSE new file mode 100644 index 0000000..c8f48db --- /dev/null +++ b/mods/freeze/LICENSE @@ -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) diff --git a/mods/freeze/init.lua b/mods/freeze/init.lua new file mode 100644 index 0000000..a29bd4d --- /dev/null +++ b/mods/freeze/init.lua @@ -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) diff --git a/mods/freeze/textures/freeze_t.png b/mods/freeze/textures/freeze_t.png new file mode 100644 index 0000000000000000000000000000000000000000..849e622c21d5ce13642a012f6388f3b71e3684b1 GIT binary patch literal 96 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;bAV5XE0A7ZWqS)qF_r}R1v5B2 myO9RuaC^EqhHzX@RuBYo3>X+wtFF}mSqz@8elF{r5}E)Ch!Z0K literal 0 HcmV?d00001