From 1cd6b661c60446f6093c3c6d92cb9a0cce0f7433 Mon Sep 17 00:00:00 2001 From: Och Noe Date: Sun, 2 Feb 2020 20:25:24 +0100 Subject: [PATCH 1/5] Limit the speed near the target positition --- init.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index b2eb03e..d95360f 100644 --- a/init.lua +++ b/init.lua @@ -50,8 +50,15 @@ elevator.create_box = function(motorhash, pos, target, sender) obj:get_luaentity().target = target obj:get_luaentity().halfway = {x=pos.x, y=(pos.y+target.y)/2, z=pos.z} obj:get_luaentity().vmult = (target.y < pos.y) and -1 or 1 + -- FIX for "overshooting" + local delta_y = math.abs(pos.y-target.y) + local speed = elevator.SPEED + if (delta_y<10) then + speed = 2 + end + -- Set the speed. - obj:setvelocity({x=0, y=elevator.SPEED*obj:get_luaentity().vmult, z=0}) + obj:setvelocity({x=0, y=speed*obj:get_luaentity().vmult, z=0}) obj:setacceleration({x=0, y=elevator.ACCEL*obj:get_luaentity().vmult, z=0}) -- Set the tables. elevator.boxes[motorhash] = obj From 12124d0b77f8835e020604c98fbe42ea7683c1eb Mon Sep 17 00:00:00 2001 From: Och Noe Date: Tue, 25 Feb 2020 13:55:47 +0100 Subject: [PATCH 2/5] Speed and distance to brake before target now in constants --- init.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index d95360f..37fa377 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,4 @@ + -- Detect optional mods. local armor_path = minetest.get_modpath("3d_armor") @@ -10,7 +11,8 @@ elevator = { VISUAL_INCREASE = 1.75, VERSION = 8, -- Elevator interface/database version. PTIMEOUT = minetest.settings:get("elevator_time") or 120, -- Maximum time a box can go without players nearby. - + SLOW_DIST = 16 + SLOW_SPEED = 1.75 boxes = {}, -- Elevator boxes in action. lastboxes = {}, -- Player near box timeout. riding = {}, -- Players riding boxes. @@ -52,9 +54,11 @@ elevator.create_box = function(motorhash, pos, target, sender) obj:get_luaentity().vmult = (target.y < pos.y) and -1 or 1 -- FIX for "overshooting" local delta_y = math.abs(pos.y-target.y) + local speed = elevator.SPEED - if (delta_y<10) then - speed = 2 + if (delta_y Date: Fri, 1 May 2020 17:34:08 +0200 Subject: [PATCH 3/5] move into elevator table --- init.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 37fa377..89e9b02 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,3 @@ - -- Detect optional mods. local armor_path = minetest.get_modpath("3d_armor") @@ -11,8 +10,8 @@ elevator = { VISUAL_INCREASE = 1.75, VERSION = 8, -- Elevator interface/database version. PTIMEOUT = minetest.settings:get("elevator_time") or 120, -- Maximum time a box can go without players nearby. - SLOW_DIST = 16 - SLOW_SPEED = 1.75 + SLOW_DIST = 16, + SLOW_SPEED = 1.75, boxes = {}, -- Elevator boxes in action. lastboxes = {}, -- Player near box timeout. riding = {}, -- Players riding boxes. @@ -56,8 +55,8 @@ elevator.create_box = function(motorhash, pos, target, sender) local delta_y = math.abs(pos.y-target.y) local speed = elevator.SPEED - if (delta_y Date: Fri, 1 May 2020 18:22:02 +0200 Subject: [PATCH 4/5] Make elevators less deadly, add farming_undo support --- crafts.lua | 2 +- init.lua | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crafts.lua b/crafts.lua index 06cfa6e..09c75c9 100644 --- a/crafts.lua +++ b/crafts.lua @@ -56,7 +56,7 @@ elseif technic_path and chains_path then {"chains:chain", "default:diamond", "chains:chain"} }, }) -elseif technic_path and farming and farming.mod and farming.mod == "redo" then +elseif technic_path and farming and farming.mod and ( farming.mod == "redo" or farming.mod == "undo" ) then -- add alternative recipe with hemp rope minetest.register_craft({ output = "elevator:elevator", diff --git a/init.lua b/init.lua index 89e9b02..eee4d8a 100644 --- a/init.lua +++ b/init.lua @@ -314,6 +314,10 @@ local box_entity = { for y=self.lastpos.y,pos.y,((self.lastpos.y > pos.y) and -0.3 or 0.3) do local p = vector.round({x=pos.x, y=y, z=pos.z}) local node = get_node(p) + if vector.distance(p,self.target) < elevator.SLOW_DIST then + self.object:set_velocity({x=0, y=elevator.SLOW_SPEED*self.vmult, z=0}) + end + if node.name == "elevator:shaft" then -- Nothing, just continue on our way. elseif node.name == "elevator:elevator_on" or node.name == "elevator:elevator_off" then From 575bc0c119f9aa61c5e24411ad46701c52e17a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Fri, 1 May 2020 23:01:15 +0200 Subject: [PATCH 5/5] Improve luacheck, remove some unused variables --- .luacheckrc | 2 ++ helpers.lua | 2 +- init.lua | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index db7f279..67f13ed 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -15,10 +15,12 @@ read_globals = { -- Minetest "minetest", + "core", "vector", "VoxelManip", -- deps "default", "screwdriver", "farming", "armor", + "mcl_core", "mcl_sounds", } diff --git a/helpers.lua b/helpers.lua index ccd8ebb..2df4253 100644 --- a/helpers.lua +++ b/helpers.lua @@ -13,7 +13,7 @@ elevator.teleport_player_from_elevator = function(player) if node.name == "elevator:elevator_on" then local front = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) local front_above = vector.add(front, {x=0, y=1, z=0}) - local front_below = vector.subtract(front, {x=0, y=1, z=0}) + -- local front_below = vector.subtract(front, {x=0, y=1, z=0}) -- If the front isn't solid, it's ok to teleport the player. if not solid(front) and not solid(front_above) then player:setpos(front) diff --git a/init.lua b/init.lua index eee4d8a..68f79d4 100644 --- a/init.lua +++ b/init.lua @@ -53,7 +53,7 @@ elevator.create_box = function(motorhash, pos, target, sender) obj:get_luaentity().vmult = (target.y < pos.y) and -1 or 1 -- FIX for "overshooting" local delta_y = math.abs(pos.y-target.y) - + local speed = elevator.SPEED if (delta_y