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.
This commit is contained in:
Aaron Suen 2023-12-30 19:07:54 -05:00
parent abd71fca6e
commit ad128cfebe
2 changed files with 8 additions and 10 deletions

View File

@ -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", "")

View File

@ -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