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 0000000..849e622 Binary files /dev/null and b/mods/freeze/textures/freeze_t.png differ