From 0966a3908173743b8c7ecf3f6db734b3a248c22a Mon Sep 17 00:00:00 2001 From: Ryan Schmitz Date: Mon, 26 Jun 2023 22:08:39 -0600 Subject: [PATCH 1/2] Second chest item on second belt line I'm not sure if this will work, but I would like to add the option to put a second item in the chest and have it go down the second line of the belt --- spawn-belt/control.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spawn-belt/control.lua b/spawn-belt/control.lua index dd52dc1..3ed96d7 100644 --- a/spawn-belt/control.lua +++ b/spawn-belt/control.lua @@ -161,14 +161,14 @@ function find_entity_after(belt, type) return nil; end -function get_chest_item(chest) +function get_chest_item(num, chest) inventory = chest.get_inventory(defines.inventory.chest); if inventory ~= nil and inventory.valid == true and inventory.is_empty() == false - and inventory[1].valid == true - and inventory[1].valid_for_read == true then - return inventory[1].name; + and inventory[num].valid == true + and inventory[num].valid_for_read == true then + return inventory[num].name; end return nil; end @@ -212,6 +212,7 @@ end function tick_belts(tick) for k, belt in ipairs(belts) do + itemtwo = nil; if belt.entity.valid ~= true then table.remove(belts, k); destroy_globals(); @@ -222,7 +223,8 @@ function tick_belts(tick) if tick.tick % entity_detection_rate == 0 then chest = find_entity_before(belt, "container"); if chest ~= nil then - belt.item = get_chest_item(chest); + belt.item = get_chest_item(1, chest); + itemtwo = get_chest_item(2, chest); end end @@ -246,7 +248,11 @@ function tick_belts(tick) end line2 = belt.entity.get_transport_line(2); if line2.can_insert_at_back() then - line2.insert_at_back({name = belt.item}); + if itemtwo then + line2.insert_at_back({name = itemtwo}); + else + line2.insert_at_back({name = belt.item}); + end end end elseif belt.entity.name == "void-belt" then From 814ba4cac87c05f2163ae7fa93f086d05dd38675 Mon Sep 17 00:00:00 2001 From: Ryan Schmitz Date: Tue, 27 Jun 2023 00:39:36 -0600 Subject: [PATCH 2/2] fixed second item on line I was able to test the modification, figured out the flaw, and updated it so it works --- spawn-belt/control.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spawn-belt/control.lua b/spawn-belt/control.lua index 3ed96d7..2e4ee10 100644 --- a/spawn-belt/control.lua +++ b/spawn-belt/control.lua @@ -212,7 +212,6 @@ end function tick_belts(tick) for k, belt in ipairs(belts) do - itemtwo = nil; if belt.entity.valid ~= true then table.remove(belts, k); destroy_globals(); @@ -224,7 +223,7 @@ function tick_belts(tick) chest = find_entity_before(belt, "container"); if chest ~= nil then belt.item = get_chest_item(1, chest); - itemtwo = get_chest_item(2, chest); + belt.itemtwo = get_chest_item(2, chest); end end @@ -248,8 +247,8 @@ function tick_belts(tick) end line2 = belt.entity.get_transport_line(2); if line2.can_insert_at_back() then - if itemtwo then - line2.insert_at_back({name = itemtwo}); + if belt.itemtwo then + line2.insert_at_back({name = belt.itemtwo}); else line2.insert_at_back({name = belt.item}); end