Carts: Check for last pathfinder predition too Minor fix to reduce cart jitter slightly
authorSmallJoker <mk939@ymail.com>
Sun, 30 Jul 2017 17:55:36 +0000 (19:55 +0200)
committersfan5 <sfan5@live.de>
Sun, 19 Nov 2017 21:57:28 +0000 (22:57 +0100)
mods/carts/functions.lua

index 96a12d2b50eefe852b0d8bce624494014066215c..9b7e2c653d7a57ea985f1d406501e6d20358b651 100644 (file)
@@ -159,23 +159,29 @@ function carts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
 end
 
 function carts:pathfinder(pos_, old_pos, old_dir, ctrl, pf_switch, railtype)
+       if vector.equals(old_pos, pos_) then
+               return true
+       end
+
        local pos = vector.round(pos_)
        local pf_pos = vector.round(old_pos)
        local pf_dir = vector.new(old_dir)
 
        for i = 1, 3 do
-               if vector.equals(pf_pos, pos) then
-                       -- Success! Cart moved on correctly
-                       return true
-               end
+               pf_dir, pf_switch = carts:get_rail_direction(
+                       pf_pos, pf_dir, ctrl, pf_switch, railtype)
 
-               pf_dir, pf_switch = carts:get_rail_direction(pf_pos, pf_dir, ctrl, pf_switch, railtype)
                if vector.equals(pf_dir, {x=0, y=0, z=0}) then
                        -- No way forwards
                        return false
                end
 
                pf_pos = vector.add(pf_pos, pf_dir)
+
+               if vector.equals(pf_pos, pos) then
+                       -- Success! Cart moved on correctly
+                       return true
+               end
        end
        -- Cart not found
        return false