Don't lose extra movement when entering new tube or turning around.

This commit is contained in:
Ekdohibs 2017-04-06 05:13:40 +02:00
parent 7680820d3e
commit ef68e058ec

View File

@ -249,8 +249,9 @@ luaentity.register_entity("pipeworks:tubed_item", {
moved = true moved = true
end end
local vel = {x = velocity.x / speed, y = velocity.y / speed, z = velocity.z / speed, speed = speed} 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) self.start_pos = vector.add(self.start_pos, vel)
moved = true moved = true
end end
@ -269,6 +270,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
return return
end end
velocity = vector.multiply(velocity, -1) velocity = vector.multiply(velocity, -1)
self:setpos(vector.subtract(self.start_pos, vector.multiply(vel, moved_by - 1)))
self:setvelocity(velocity) self:setvelocity(velocity)
self:set_item(leftover:to_string()) self:set_item(leftover:to_string())
return return
@ -295,7 +297,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
if minetest.get_item_group(rev_node.name,"tube") == 1 then 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)) print("[Pipeworks] Warning - tubed item had to reverse direction at "..minetest.pos_to_string(self.start_pos))
velocity = vector.multiply(velocity, -1) 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) self:setvelocity(velocity)
else else
if drop_pos then if drop_pos then
@ -308,7 +310,8 @@ luaentity.register_entity("pipeworks:tubed_item", {
end end
if new_velocity and not vector.equals(velocity, new_velocity) then 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) self:setvelocity(new_velocity)
end end
end end