diff options
Diffstat (limited to 'boost_cart/functions.lua')
-rw-r--r-- | boost_cart/functions.lua | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/boost_cart/functions.lua b/boost_cart/functions.lua index 9876eb2..1332578 100644 --- a/boost_cart/functions.lua +++ b/boost_cart/functions.lua @@ -159,23 +159,29 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype) end function boost_cart: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 = boost_cart:get_rail_direction( + pf_pos, pf_dir, ctrl, pf_switch, railtype) - pf_dir, pf_switch = boost_cart: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 @@ -217,7 +223,15 @@ end function boost_cart:get_rail_groups(additional_groups) -- Get the default rail groups and add more when a table is given - local groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1} + local groups = { + dig_immediate = 2, + attached_node = 1, + rail = 1, + connect_to_raillike = 1 + } + if minetest.raillike_group then + groups.connect_to_raillike = minetest.raillike_group("rail") + end if type(additional_groups) == "table" then for k, v in pairs(additional_groups) do groups[k] = v |