summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkdohibs <nathanael.courant@laposte.net>2017-04-06 05:13:40 +0200
committerEkdohibs <nathanael.courant@laposte.net>2017-04-06 05:13:40 +0200
commitef68e058ec69d52dff78a604833229f79cf661c6 (patch)
tree26af3a7b18aeefc4a2e52e1ae2553e7495d1f37f
parent7680820d3e85ac06976b26e86211866cdf90a99d (diff)
downloadpipeworks-ef68e058ec69d52dff78a604833229f79cf661c6.tar
pipeworks-ef68e058ec69d52dff78a604833229f79cf661c6.tar.gz
pipeworks-ef68e058ec69d52dff78a604833229f79cf661c6.tar.bz2
pipeworks-ef68e058ec69d52dff78a604833229f79cf661c6.tar.xz
pipeworks-ef68e058ec69d52dff78a604833229f79cf661c6.zip
Don't lose extra movement when entering new tube or turning around.
-rw-r--r--item_transport.lua9
1 files changed, 6 insertions, 3 deletions
diff --git a/item_transport.lua b/item_transport.lua
index 40e0d2d..848b92b 100644
--- a/item_transport.lua
+++ b/item_transport.lua
@@ -249,8 +249,9 @@ luaentity.register_entity("pipeworks:tubed_item", {
moved = true
end
local vel = {x = velocity.x / speed, y = velocity.y / speed, z = velocity.z / speed, speed = speed}
+ local moved_by = vector.distance(pos, self.start_pos)
- if vector.distance(pos, self.start_pos) >= 1 then
+ if moved_by >= 1 then
self.start_pos = vector.add(self.start_pos, vel)
moved = true
end
@@ -269,6 +270,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
return
end
velocity = vector.multiply(velocity, -1)
+ self:setpos(vector.subtract(self.start_pos, vector.multiply(vel, moved_by - 1)))
self:setvelocity(velocity)
self:set_item(leftover:to_string())
return
@@ -295,7 +297,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
if minetest.get_item_group(rev_node.name,"tube") == 1 then
print("[Pipeworks] Warning - tubed item had to reverse direction at "..minetest.pos_to_string(self.start_pos))
velocity = vector.multiply(velocity, -1)
- self:setpos(self.start_pos)
+ self:setpos(vector.subtract(self.start_pos, vector.multiply(vel, moved_by - 1)))
self:setvelocity(velocity)
else
if drop_pos then
@@ -308,7 +310,8 @@ luaentity.register_entity("pipeworks:tubed_item", {
end
if new_velocity and not vector.equals(velocity, new_velocity) then
- self:setpos(self.start_pos)
+ local nvelr = math.abs(new_velocity.x + new_velocity.y + new_velocity.z)
+ self:setpos(vector.add(self.start_pos, vector.multiply(new_velocity, (moved_by - 1) / nvelr)))
self:setvelocity(new_velocity)
end
end