From c277dc9623c5167f091f77051ed2dc891b8e2f4f Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Sun, 19 May 2024 19:55:18 +0200 Subject: [PATCH] Fix centrifuge distribution code --- turtle_code/centrifuges_platinum.lua | 39 ++++++++++++++++++---------- turtle_code/centrifuges_redstone.lua | 37 ++++++++++++++++---------- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/turtle_code/centrifuges_platinum.lua b/turtle_code/centrifuges_platinum.lua index 271649a..37906f0 100644 --- a/turtle_code/centrifuges_platinum.lua +++ b/turtle_code/centrifuges_platinum.lua @@ -201,9 +201,14 @@ function moveTo(x, y) end function resupplyItem(slot, num) + module = peripheral.wrap("right") + turtle.select(slot) - while (turtle.getItemCount(slot) < num) do - turtle.suck(num - turtle.getItemCount(slot)) + items = turtle.getItemCount(slot) + while (items < num) do + module.suckSneaky(1, num - items) + sleep(1) + items = turtle.getItemCount(slot) end end @@ -246,15 +251,17 @@ function supplyCentrifuge() module = peripheral.wrap("right") -- drop cells from below (side 0) - turtle.select(slot_cells_cur) - drop = cells_drop - if (turtle.getItemCount(slot_cells_cur) < drop) then - drop = drop - turtle.getItemCount(slot_cells_cur) - module.dropSneakyUp(0) - slot_cells_cur = slot_cells_cur + 1 + if (cells_drop > 0) then turtle.select(slot_cells_cur) - end - module.dropSneakyUp(0, drop) + drop = cells_drop + if (turtle.getItemCount(slot_cells_cur) < drop) then + drop = drop - turtle.getItemCount(slot_cells_cur) + module.dropSneakyUp(0) + slot_cells_cur = slot_cells_cur + 1 + turtle.select(slot_cells_cur) + end + module.dropSneakyUp(0, drop) + end -- drop input from above (side 1) turtle.select(slot_input_cur) @@ -357,16 +364,19 @@ function setupSlots(cells, input, output_1, output_2, output_3, output_4) end function enterSupplyLoop() + module = peripheral.wrap("right") + while true do print("Resupplying...") resupplyAll() - -- go to first centrifuge and wait to start + -- go to first centrifuge and wait to start (by checking ingredient) moveTo(1, 0) turtle.select(16) - while turtle.suckUp() do + while module.suckSneakyUp(1, input_drop) do putBack = turtle.getItemCount(16) - turtle.dropUp(putBack) + sleep(1) + module.dropSneakyUp(1, putBack) sleep(5) end @@ -411,4 +421,5 @@ function platinumLoop() end print("Centrifuges even item distribution program") -platinumLoop() + +redstoneLoop() diff --git a/turtle_code/centrifuges_redstone.lua b/turtle_code/centrifuges_redstone.lua index 7148a78..3efe4f3 100644 --- a/turtle_code/centrifuges_redstone.lua +++ b/turtle_code/centrifuges_redstone.lua @@ -201,9 +201,14 @@ function moveTo(x, y) end function resupplyItem(slot, num) + module = peripheral.wrap("right") + turtle.select(slot) - while (turtle.getItemCount(slot) < num) do - turtle.suck(num - turtle.getItemCount(slot)) + items = turtle.getItemCount(slot) + while (items < num) do + module.suckSneaky(1, num - items) + sleep(1) + items = turtle.getItemCount(slot) end end @@ -246,15 +251,17 @@ function supplyCentrifuge() module = peripheral.wrap("right") -- drop cells from below (side 0) - turtle.select(slot_cells_cur) - drop = cells_drop - if (turtle.getItemCount(slot_cells_cur) < drop) then - drop = drop - turtle.getItemCount(slot_cells_cur) - module.dropSneakyUp(0) - slot_cells_cur = slot_cells_cur + 1 + if (cells_drop > 0) then turtle.select(slot_cells_cur) - end - module.dropSneakyUp(0, drop) + drop = cells_drop + if (turtle.getItemCount(slot_cells_cur) < drop) then + drop = drop - turtle.getItemCount(slot_cells_cur) + module.dropSneakyUp(0) + slot_cells_cur = slot_cells_cur + 1 + turtle.select(slot_cells_cur) + end + module.dropSneakyUp(0, drop) + end -- drop input from above (side 1) turtle.select(slot_input_cur) @@ -357,16 +364,19 @@ function setupSlots(cells, input, output_1, output_2, output_3, output_4) end function enterSupplyLoop() + module = peripheral.wrap("right") + while true do print("Resupplying...") resupplyAll() - -- go to first centrifuge and wait to start + -- go to first centrifuge and wait to start (by checking ingredient) moveTo(1, 0) turtle.select(16) - while turtle.suckUp() do + while module.suckSneakyUp(1, input_drop) do putBack = turtle.getItemCount(16) - turtle.dropUp(putBack) + sleep(1) + module.dropSneakyUp(1, putBack) sleep(5) end @@ -411,4 +421,5 @@ function redstoneLoop() end print("Centrifuges even item distribution program") + redstoneLoop()