From ad128cfebe685930e044ce547550a53be0f068f5 Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Sat, 30 Dec 2023 19:07:54 -0500 Subject: [PATCH] Fix "wandering tool" bug Instead of calculating tool position offset based on its current position (incorrectly assuming its current pos at the time of a tool action start is its "home" position), just set and remember its home position at the time we calculate the entity properties. --- mods/nc_api_visinv/init.lua | 1 + mods/nc_doors/craft_catapult.lua | 17 +++++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mods/nc_api_visinv/init.lua b/mods/nc_api_visinv/init.lua index a0fe3d84..39e9de77 100644 --- a/mods/nc_api_visinv/init.lua +++ b/mods/nc_api_visinv/init.lua @@ -82,6 +82,7 @@ local function itemcheck(self) y = rp.y + scale - 31/64, z = rp.z } + self.homepos = op if tweenfrom then nodemeta:set_string("tweenfrom", "") diff --git a/mods/nc_doors/craft_catapult.lua b/mods/nc_doors/craft_catapult.lua index 5f51a72b..f218fdc5 100644 --- a/mods/nc_doors/craft_catapult.lua +++ b/mods/nc_doors/craft_catapult.lua @@ -106,17 +106,14 @@ local function toolfx(toolpos, actpos) for _, ent in pairs(minetest.luaentities) do local target = ent.is_stack and ent.poskey and toolfxqueue[ent.poskey] - if target then + if target and ent.homepos then local obj = ent.object - local pos = obj:get_pos() - if pos then - obj:set_pos(vector.add(target, - vector.subtract(pos, - ent.pos))) - minetest.after(0.1, function() - obj:move_to(pos) - end) - end + obj:set_pos(vector.add(target, + vector.subtract(ent.homepos, + ent.pos))) + minetest.after(0.1, function() + obj:move_to(ent.homepos) + end) end end toolfxqueue = nil