Code: Select all
@@ -34,6 +34,17 @@
     end
     return false
 end
+-- is any entity in the list that's belt-ish facing toward the loader
+function are_belt_facing(entities, direction)
+    for _,entity in pairs(entities) do
+        if (entity.type == "transport-belt" or
+            entity.type == "underground-belt" or
+            entity.type == "splitter") and
+            entity.direction == direction
+        then return true end
+    end
+    return false
+end
 -- if there's a loadable thing behind but not ahead, turn around
 -- if there's a loadable thing ahead but not behind, turn around and switch mode
@@ -44,12 +55,18 @@
     if event.revived then return end
     local snap2back = settings.get_player_settings(game.players[event.player_index])["deadlock-loaders-snap-to-back"].value
     local snap2front = settings.get_player_settings(game.players[event.player_index])["deadlock-loaders-snap-to-front"].value
+    -- needs a setting
+    local snap2belt = true
     -- no need to check anything if all configs are off
-    if not snap2back and not snap2front then return end
+    if not snap2back and not snap2front and not snap2belt then return end
     -- check neighbours and snap if necessary
     local belt_end = get_neighbour_entities(built, built.direction)
     local loading_end = get_neighbour_entities(built, opposite[built.direction])
-    if snap2back and not are_loadable(belt_end) and are_loadable(loading_end) then
+    if snap2belt and are_belt_facing(belt_end, opposite[built.direction]) then
+        built.rotate( {by_player = event.player_index} )
+    elseif snap2belt and are_belt_facing(belt_end, built.direction) then
+        -- there's a belt facing away from the belt-end, do nothing and skip any potential inventory snapping
+    elseif snap2back and not are_loadable(belt_end) and are_loadable(loading_end) then
         built.rotate( {by_player = event.player_index} )
     elseif snap2front and are_loadable(belt_end) and not are_loadable(loading_end) then
         built.direction = opposite[built.direction]








