From c13f0817c3333740c4d3a364e3823cfdbecd536a Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Sun, 31 Dec 2023 15:01:11 +0100 Subject: [PATCH 1/6] Add IBF distribution --- New Attempts/IBF.lua | 206 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 New Attempts/IBF.lua diff --git a/New Attempts/IBF.lua b/New Attempts/IBF.lua new file mode 100644 index 0000000..c07e41e --- /dev/null +++ b/New Attempts/IBF.lua @@ -0,0 +1,206 @@ +xRelPos = 0 -- "positive = forward" +yRelPos = 0 -- "positive = right" +zRelPos = 0 -- "positive = upwards" + +facing = { + x = 1, + y = 0 +} + +slot_dust = 1 +slot_empty = 2 +num_dust = 4 + +function printPos() + print("At (", xRelPos, ", ", yRelPos, ", ", zRelPos, ") facing (", facing.x, ", ", facing.y, ")") +end + +-- helper functions for movement +function forward() + xRelPos = xRelPos + facing.x + yRelPos = yRelPos + facing.y + + if turtle.forward() then + return true + end + + xRelPos = xRelPos - facing.x + yRelPos = yRelPos - facing.y + + turtle.dig() + turtle.attack() + return false +end + +function forceForward() + -- try moving forward until it works + while not forward() do end +end + +function upwards() + zRelPos = zRelPos + 1 + if turtle.up() then + return true + end + zRelPos = zRelPos - 1 + turtle.digUp() + turtle.attackUp() + return false +end + +function forceUpwards() + -- try moving upwards until it works + while not upwards() do end +end + +function downwards() + zRelPos = zRelPos - 1 + if turtle.down() then + return true + end + zRelPos = zRelPos + 1 + turtle.digDown() + turtle.attackDown() + return false +end + +function forceDownwards() + -- try moving upwards until it works + while not downwards() do end +end + +function forcePlace() + -- try placing until it works + while not turtle.place() do + turtle.dig() + turtle.attack() + end +end + +function forcePlaceDown() + -- try placing until it works + while not turtle.placeDown() do + turtle.digDown() + turtle.attackDown() + end +end + +function forcePlaceUp() + -- try placing until it works + while not turtle.placeUp() do + turtle.digUp() + turtle.attackUp() + end +end + +function turnRight() + if facing.x == 1 and facing.y == 0 then -- facing forward + facing.x = 0 + facing.y = 1 + elseif facing.x == 0 and facing.y == 1 then -- facing right + facing.x = -1 + facing.y = 0 + elseif facing.x == -1 and facing.y == 0 then -- facing backward + facing.x = 0 + facing.y = -1 + elseif facing.x == 0 and facing.y == -1 then -- facing left + facing.x = 1 + facing.y = 0 + else + print("turnRight: This should never happen") + end + turtle.turnRight() +end + +function turnLeft() + if facing.x == 1 and facing.y == 0 then -- facing forward + facing.x = 0 + facing.y = -1 + elseif facing.x == 0 and facing.y == 1 then -- facing right + facing.x = 1 + facing.y = 0 + elseif facing.x == -1 and facing.y == 0 then -- facing backward + facing.x = 0 + facing.y = 1 + elseif facing.x == 0 and facing.y == -1 then -- facing left + facing.x = -1 + facing.y = 0 + else + print("turnLeft: This should never happen") + end + turtle.turnLeft() +end + +function faceTo(x, y) + if (x == facing.x) and (y == facing.y) then + return + end + if (x == 1 and facing.x == -1) or (x == -1 and facing.x == 1) or (y == 1 and facing.y == -1) or (y == -1 and facing.y == 1) then + turnRight() + turnRight() + elseif (facing.y == -1 and x == 1) or (facing.y == 1 and x == -1) or (facing.x == 1 and y == 1) or (facing.x == -1 and y == -1) then + turnRight() + elseif (facing.y == -1 and x == -1) or (facing.y == 1 and x == 1) or (facing.x == 1 and y == -1) or (facing.x == -1 and y == 1) then + turnLeft() + else + print("faceTo: This should never happen") + end +end + +function moveTo(x, y) + if (yRelPos > y) then + faceTo(0, -1) + while yRelPos > y do + forward() + end + elseif (yRelPos < y) then + faceTo(0, 1) + while yRelPos < y do + forward() + end + end + + if (xRelPos > x) then + faceTo(-1, 0) + while xRelPos > x do + forward() + end + elseif (xRelPos < x) then + faceTo(1, 0) + while xRelPos < x do + forward() + end + end +end + +function resupplyItem(slot, num) + turtle.select(slot) + while (turtle.getItemCount(slot) < num) do + sleep(1) + turtle.suckDown(num - turtle.getItemCount(slot)) + end +end + +print("Industrial Blast Furnace even item distribution program") + +while true do + resupplyItem(slot_dust, num_dust) + + for i = 1, 4 do + forceForward(); forceForward() + + -- check if anything is still in the furnace + -- use different slot than dust slot since the item type may have changed + turtle.select(slot_empty) + while turtle.suckDown() do + turtle.dropDown() + sleep(5) + end + + turtle.select(slot_dust) + turtle.dropDown(1) + + forceForward(); forceForward() + turnLeft() + end +end From f86998cb7213c04a5ca1a791f9e97710b03dce3e Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Sun, 28 Apr 2024 14:03:48 +0200 Subject: [PATCH 2/6] Latest --- New Attempts/Boiler.lua | 2 +- New Attempts/Commands.md | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/New Attempts/Boiler.lua b/New Attempts/Boiler.lua index a582c32..197caf8 100644 --- a/New Attempts/Boiler.lua +++ b/New Attempts/Boiler.lua @@ -97,7 +97,7 @@ function forcePlace() while not turtle.place() do turtle.dig() turtle.attack() - enda + end end function forcePlaceDown() diff --git a/New Attempts/Commands.md b/New Attempts/Commands.md index d947085..d7c6bc1 100644 --- a/New Attempts/Commands.md +++ b/New Attempts/Commands.md @@ -53,6 +53,14 @@ Like this: - `pastebin get iq0Xe2KF ibf` - `ibf` +## IBF Distribution turtle + +- place above me interface with the dust to smelt set to 4 + +**execute commands**: +- pastebin get iq0Xe2KF ibf +- ibf + ## grindstone turtle Place an engineering turtle (turtle with crescent hammer, 3 iron + 1 silver) facing the crank of a grindstone From 21b85d9b135971abc0d7b36412d19acb1d713323 Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Mon, 29 Apr 2024 17:58:44 +0200 Subject: [PATCH 3/6] Add initial version of automated centrifuge usage --- New Attempts/Centrifuges.lua | 417 +++++++++++++++++++++++++++++++++++ 1 file changed, 417 insertions(+) create mode 100644 New Attempts/Centrifuges.lua diff --git a/New Attempts/Centrifuges.lua b/New Attempts/Centrifuges.lua new file mode 100644 index 0000000..0a5f49e --- /dev/null +++ b/New Attempts/Centrifuges.lua @@ -0,0 +1,417 @@ + +xRelPos = 0 -- "positive = forward" +yRelPos = 0 -- "positive = right" +zRelPos = 0 -- "positive = upwards" + +facing = { + x = 1, + y = 0 +} + +cells_drop = 0 +slot_cells_min = 0 +slot_cells_max = 0 +slot_cells_cur = 0 + +input_drop = 0 +slot_input_min = 0 +slot_input_max = 0 +slot_input_cur = 0 + +output_1_take = 0 +slot_output_1_min = 0 +slot_output_1_max = 0 +slot_output_1_cur = 0 + +output_2_take = 0 +slot_output_2_min = 0 +slot_output_2_max = 0 +slot_output_2_cur = 0 + +output_3_take = 0 +slot_output_3_min = 0 +slot_output_3_max = 0 +slot_output_3_cur = 0 + +output_4_take = 0 +slot_output_4_min = 0 +slot_output_4_max = 0 +slot_output_4_cur = 0 + +function printPos() + print("At (", xRelPos, ", ", yRelPos, ", ", zRelPos, ") facing (", facing.x, ", ", facing.y, ")") +end + +-- helper functions for movement +function forward() + xRelPos = xRelPos + facing.x + yRelPos = yRelPos + facing.y + + if turtle.forward() then + return true + end + + xRelPos = xRelPos - facing.x + yRelPos = yRelPos - facing.y + + turtle.dig() + turtle.attack() + return false +end + +function forceForward() + -- try moving forward until it works + while not forward() do end +end + +function upwards() + zRelPos = zRelPos + 1 + if turtle.up() then + return true + end + zRelPos = zRelPos - 1 + turtle.digUp() + turtle.attackUp() + return false +end + +function forceUpwards() + -- try moving upwards until it works + while not upwards() do end +end + +function downwards() + zRelPos = zRelPos - 1 + if turtle.down() then + return true + end + zRelPos = zRelPos + 1 + turtle.digDown() + turtle.attackDown() + return false +end + +function forceDownwards() + -- try moving upwards until it works + while not downwards() do end +end + +function forcePlace() + -- try placing until it works + while not turtle.place() do + turtle.dig() + turtle.attack() + end +end + +function forcePlaceDown() + -- try placing until it works + while not turtle.placeDown() do + turtle.digDown() + turtle.attackDown() + end +end + +function forcePlaceUp() + -- try placing until it works + while not turtle.placeUp() do + turtle.digUp() + turtle.attackUp() + end +end + +function turnRight() + if facing.x == 1 and facing.y == 0 then -- facing forward + facing.x = 0 + facing.y = 1 + elseif facing.x == 0 and facing.y == 1 then -- facing right + facing.x = -1 + facing.y = 0 + elseif facing.x == -1 and facing.y == 0 then -- facing backward + facing.x = 0 + facing.y = -1 + elseif facing.x == 0 and facing.y == -1 then -- facing left + facing.x = 1 + facing.y = 0 + else + print("turnRight: This should never happen") + end + turtle.turnRight() +end + +function turnLeft() + if facing.x == 1 and facing.y == 0 then -- facing forward + facing.x = 0 + facing.y = -1 + elseif facing.x == 0 and facing.y == 1 then -- facing right + facing.x = 1 + facing.y = 0 + elseif facing.x == -1 and facing.y == 0 then -- facing backward + facing.x = 0 + facing.y = 1 + elseif facing.x == 0 and facing.y == -1 then -- facing left + facing.x = -1 + facing.y = 0 + else + print("turnLeft: This should never happen") + end + turtle.turnLeft() +end + +function faceTo(x, y) + if (x == facing.x) and (y == facing.y) then + return + end + if (x == 1 and facing.x == -1) or (x == -1 and facing.x == 1) or (y == 1 and facing.y == -1) or (y == -1 and facing.y == 1) then + turnRight() + turnRight() + elseif (facing.y == -1 and x == 1) or (facing.y == 1 and x == -1) or (facing.x == 1 and y == 1) or (facing.x == -1 and y == -1) then + turnRight() + elseif (facing.y == -1 and x == -1) or (facing.y == 1 and x == 1) or (facing.x == 1 and y == -1) or (facing.x == -1 and y == 1) then + turnLeft() + else + print("faceTo: This should never happen") + end +end + +function moveTo(x, y) + if (yRelPos > y) then + faceTo(0, -1) + while yRelPos > y do + forward() + end + elseif (yRelPos < y) then + faceTo(0, 1) + while yRelPos < y do + forward() + end + end + + if (xRelPos > x) then + faceTo(-1, 0) + while xRelPos > x do + forward() + end + elseif (xRelPos < x) then + faceTo(1, 0) + while xRelPos < x do + forward() + end + end +end + +function resupplyItem(slot, num) + turtle.select(slot) + while (turtle.getItemCount(slot) < num) do + turtle.suck(num - turtle.getItemCount(slot)) + end +end + +function resupplyAll() + -- clean entire inventory + moveTo(0, 2); faceTo(-1, 0) + for i = 1, 16 do + while turtle.getItemCount(i) > 0 do + turtle.select(i) + turtle.drop() + end + end + + -- get ingredient + moveTo(0, 1); faceTo(-1, 0) + slot_input_cur = slot_input_min + for i = slot_input_min, slot_input_max do + if (turtle.getItemCount(i) < 64) then + resupplyItem(i, 64) + end + end + + -- get cells + moveTo(0, 0); faceTo(-1, 0) + slot_cells_cur = slot_cells_min + for i = slot_cells_min, slot_cells_max do + if (turtle.getItemCount(i) < 64) then + resupplyItem(i, 64) + end + end +end + +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 + turtle.select(slot_cells_cur) + end + module.dropSneakyUp(0, drop) + + -- drop input from above (side 1) + turtle.select(slot_input_cur) + drop = input_drop + if (turtle.getItemCount(slot_input_cur) < drop) then + drop = drop - turtle.getItemCount(slot_input_cur) + module.dropSneakyUp(1) + slot_input_cur = slot_input_cur + 1 + turtle.select(slot_input_cur) + end + module.dropSneakyUp(1, drop) +end + +function emptyCentrifuge() + module = peripheral.wrap("right") + + -- get output 1 + turtle.select(slot_output_1_cur) + take = output_1_take + if (turtle.getItemCount(slot_output_1_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_1_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_1_cur = slot_output_1_cur + 1 + turtle.select(slot_output_1_cur) + end + -- if no input is ready, move on immediately + if module.suckSneakyUp(2, take) == false then + return + end + + -- get output 2 + turtle.select(slot_output_2_cur) + take = output_2_take + if (turtle.getItemCount(slot_output_2_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_2_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_2_cur = slot_output_2_cur + 1 + turtle.select(slot_output_2_cur) + end + module.suckSneakyUp(2, take) + + -- get output 3 + turtle.select(slot_output_3_cur) + take = output_3_take + if (turtle.getItemCount(slot_output_3_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_3_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_3_cur = slot_output_3_cur + 1 + turtle.select(slot_output_3_cur) + end + module.suckSneakyUp(2, take) + + -- get output 4 + turtle.select(slot_output_4_cur) + take = output_4_take + if (turtle.getItemCount(slot_output_4_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_4_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_4_cur = slot_output_4_cur + 1 + turtle.select(slot_output_4_cur) + end + module.suckSneakyUp(2, take) +end + +-- sets up slot numbers with slots for cells and slots for input ingredient, and output 1 through 4 numbers of slots +function setupSlots(cells, input, output_1, output_2, output_3, output_4) + slot_cells_min = 1 + slot_cells_max = cells + slot_cells_cur = slot_cells_min + cells_drop = cells + + slot_input_min = slot_cells_max + 1 + slot_input_max = slot_input_min + input - 1 + slot_input_cur = slot_input_min + input_drop = input + + slot_output_1_min = 1 + slot_output_1_max = output_1 + slot_output_1_cur = slot_output_1_min + output_1_take = output_1 + + slot_output_2_min = slot_output_1_max + 1 + slot_output_2_max = slot_output_2_min + output_2 - 1 + slot_output_2_cur = slot_output_2_min + output_2_take = output_2 + + slot_output_3_min = slot_output_2_max + 1 + slot_output_3_max = slot_output_3_min + output_3 - 1 + slot_output_3_cur = slot_output_3_min + output_3_take = output_3 + + slot_output_4_min = slot_output_3_max + 1 + slot_output_4_max = slot_output_4_min + output_4 - 1 + slot_output_4_cur = slot_output_4_min + output_4_take = output_4 +end + +function enterSupplyLoop() + while true do + print("Resupplying...") + resupplyAll() + + -- go to first centrifuge and wait to start + moveTo(1, 0) + turtle.select(16) + while turtle.suckUp() do + putBack = turtle.getItemCount(16) + turtle.dropUp(putBack) + sleep(5) + end + + print("Putting cells and ingredient in the centrifuges...") + -- putting in ingredients on the way there + for i = 1, 7, 2 do + for j = 0, 7, 1 do -- moving right + moveTo(i, j) + supplyCentrifuge() + end + for j = 7, 0, -1 do -- moving left + moveTo(i + 1, j) + supplyCentrifuge() + end + end + + sleep(5) + -- wait a little so all centrifuges are ready for having their outputs taken + + print("Getting outputs from the centrifuges...") + -- getting outputs out on the way back + for i = 7, 1, -2 do + for j = 0, 7, 1 do -- moving right + moveTo(i + 1, j) + emptyCentrifuge() + end + for j = 7, 0, -1 do -- moving left + moveTo(i, j) + emptyCentrifuge() + end + end + end +end + +function redstoneLoop() + print("Supplying Redstone Centrifuges") + setupSlots(4, 10, 1, 5, 1, 3) -- 4 slots cells, 10 slots redstone + print("Starting in 5s...") + sleep(5) + + enterSupplyLoop() +end + +function platinumLoop() + print("Supplying Platinum Dust Centrifuges") + setupSlots(0, 1, 1, 0, 0, 0) -- 0 slots cells, 1 slot platinum dust + print("Starting in 5s...") + sleep(5) + + enterSupplyLoop() +end + +print("Centrifuges even item distribution program") +redstoneLoop() From b8689fb78f001c398de86360d9fce021dc4ef785 Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Tue, 30 Apr 2024 00:25:23 +0200 Subject: [PATCH 4/6] Fix small problem --- New Attempts/Centrifuges.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/New Attempts/Centrifuges.lua b/New Attempts/Centrifuges.lua index 0a5f49e..83ea340 100644 --- a/New Attempts/Centrifuges.lua +++ b/New Attempts/Centrifuges.lua @@ -208,6 +208,12 @@ function resupplyItem(slot, num) end function resupplyAll() + -- reset current slot numbers + slot_output_1_cur = slot_output_1_min + slot_output_2_cur = slot_output_2_min + slot_output_3_cur = slot_output_3_min + slot_output_4_cur = slot_output_4_min + -- clean entire inventory moveTo(0, 2); faceTo(-1, 0) for i = 1, 16 do @@ -414,4 +420,5 @@ function platinumLoop() end print("Centrifuges even item distribution program") + redstoneLoop() From 46f9ef0df6eb5341009aa8406f52e7549c1e8c3f Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Tue, 30 Apr 2024 18:02:26 +0200 Subject: [PATCH 5/6] Rename things --- Notes.md => README.md | 0 .../chrome_calcs.md | 0 .../iridium_calcs.md | 0 .../titanium_calcs.md | 0 original_code/README.md | 3 + .../boiler_build.lua | 0 .../Quarry.lua => original_code/quarry.lua | 0 .../Commands.md => turtle_code/README.md | 0 .../Boiler.lua => turtle_code/boiler.lua | 0 turtle_code/centrifuges_platinum.lua | 414 ++++++++++++++++++ .../centrifuges_redstone.lua | 10 - .../Crank.lua => turtle_code/crank.lua | 0 New Attempts/IBF.lua => turtle_code/ibf.lua | 0 .../Mining.lua => turtle_code/mining.lua | 0 14 files changed, 417 insertions(+), 10 deletions(-) rename Notes.md => README.md (100%) rename {material calculations => material_calculations}/chrome_calcs.md (100%) rename {material calculations => material_calculations}/iridium_calcs.md (100%) rename {material calculations => material_calculations}/titanium_calcs.md (100%) create mode 100644 original_code/README.md rename Original Programs/Boiler Build.lua => original_code/boiler_build.lua (100%) rename Original Programs/Quarry.lua => original_code/quarry.lua (100%) rename New Attempts/Commands.md => turtle_code/README.md (100%) rename New Attempts/Boiler.lua => turtle_code/boiler.lua (100%) create mode 100644 turtle_code/centrifuges_platinum.lua rename New Attempts/Centrifuges.lua => turtle_code/centrifuges_redstone.lua (98%) rename New Attempts/Crank.lua => turtle_code/crank.lua (100%) rename New Attempts/IBF.lua => turtle_code/ibf.lua (100%) rename New Attempts/Mining.lua => turtle_code/mining.lua (100%) diff --git a/Notes.md b/README.md similarity index 100% rename from Notes.md rename to README.md diff --git a/material calculations/chrome_calcs.md b/material_calculations/chrome_calcs.md similarity index 100% rename from material calculations/chrome_calcs.md rename to material_calculations/chrome_calcs.md diff --git a/material calculations/iridium_calcs.md b/material_calculations/iridium_calcs.md similarity index 100% rename from material calculations/iridium_calcs.md rename to material_calculations/iridium_calcs.md diff --git a/material calculations/titanium_calcs.md b/material_calculations/titanium_calcs.md similarity index 100% rename from material calculations/titanium_calcs.md rename to material_calculations/titanium_calcs.md diff --git a/original_code/README.md b/original_code/README.md new file mode 100644 index 0000000..49a5ff2 --- /dev/null +++ b/original_code/README.md @@ -0,0 +1,3 @@ +# Original Programs + +The code in this directory is not by me and only here for reference. diff --git a/Original Programs/Boiler Build.lua b/original_code/boiler_build.lua similarity index 100% rename from Original Programs/Boiler Build.lua rename to original_code/boiler_build.lua diff --git a/Original Programs/Quarry.lua b/original_code/quarry.lua similarity index 100% rename from Original Programs/Quarry.lua rename to original_code/quarry.lua diff --git a/New Attempts/Commands.md b/turtle_code/README.md similarity index 100% rename from New Attempts/Commands.md rename to turtle_code/README.md diff --git a/New Attempts/Boiler.lua b/turtle_code/boiler.lua similarity index 100% rename from New Attempts/Boiler.lua rename to turtle_code/boiler.lua diff --git a/turtle_code/centrifuges_platinum.lua b/turtle_code/centrifuges_platinum.lua new file mode 100644 index 0000000..271649a --- /dev/null +++ b/turtle_code/centrifuges_platinum.lua @@ -0,0 +1,414 @@ + +xRelPos = 0 -- "positive = forward" +yRelPos = 0 -- "positive = right" +zRelPos = 0 -- "positive = upwards" + +facing = { + x = 1, + y = 0 +} + +cells_drop = 0 +slot_cells_min = 0 +slot_cells_max = 0 +slot_cells_cur = 0 + +input_drop = 0 +slot_input_min = 0 +slot_input_max = 0 +slot_input_cur = 0 + +output_1_take = 0 +slot_output_1_min = 0 +slot_output_1_max = 0 +slot_output_1_cur = 0 + +output_2_take = 0 +slot_output_2_min = 0 +slot_output_2_max = 0 +slot_output_2_cur = 0 + +output_3_take = 0 +slot_output_3_min = 0 +slot_output_3_max = 0 +slot_output_3_cur = 0 + +output_4_take = 0 +slot_output_4_min = 0 +slot_output_4_max = 0 +slot_output_4_cur = 0 + +function printPos() + print("At (", xRelPos, ", ", yRelPos, ", ", zRelPos, ") facing (", facing.x, ", ", facing.y, ")") +end + +-- helper functions for movement +function forward() + xRelPos = xRelPos + facing.x + yRelPos = yRelPos + facing.y + + if turtle.forward() then + return true + end + + xRelPos = xRelPos - facing.x + yRelPos = yRelPos - facing.y + + turtle.dig() + turtle.attack() + return false +end + +function forceForward() + -- try moving forward until it works + while not forward() do end +end + +function upwards() + zRelPos = zRelPos + 1 + if turtle.up() then + return true + end + zRelPos = zRelPos - 1 + turtle.digUp() + turtle.attackUp() + return false +end + +function forceUpwards() + -- try moving upwards until it works + while not upwards() do end +end + +function downwards() + zRelPos = zRelPos - 1 + if turtle.down() then + return true + end + zRelPos = zRelPos + 1 + turtle.digDown() + turtle.attackDown() + return false +end + +function forceDownwards() + -- try moving upwards until it works + while not downwards() do end +end + +function forcePlace() + -- try placing until it works + while not turtle.place() do + turtle.dig() + turtle.attack() + end +end + +function forcePlaceDown() + -- try placing until it works + while not turtle.placeDown() do + turtle.digDown() + turtle.attackDown() + end +end + +function forcePlaceUp() + -- try placing until it works + while not turtle.placeUp() do + turtle.digUp() + turtle.attackUp() + end +end + +function turnRight() + if facing.x == 1 and facing.y == 0 then -- facing forward + facing.x = 0 + facing.y = 1 + elseif facing.x == 0 and facing.y == 1 then -- facing right + facing.x = -1 + facing.y = 0 + elseif facing.x == -1 and facing.y == 0 then -- facing backward + facing.x = 0 + facing.y = -1 + elseif facing.x == 0 and facing.y == -1 then -- facing left + facing.x = 1 + facing.y = 0 + else + print("turnRight: This should never happen") + end + turtle.turnRight() +end + +function turnLeft() + if facing.x == 1 and facing.y == 0 then -- facing forward + facing.x = 0 + facing.y = -1 + elseif facing.x == 0 and facing.y == 1 then -- facing right + facing.x = 1 + facing.y = 0 + elseif facing.x == -1 and facing.y == 0 then -- facing backward + facing.x = 0 + facing.y = 1 + elseif facing.x == 0 and facing.y == -1 then -- facing left + facing.x = -1 + facing.y = 0 + else + print("turnLeft: This should never happen") + end + turtle.turnLeft() +end + +function faceTo(x, y) + if (x == facing.x) and (y == facing.y) then + return + end + if (x == 1 and facing.x == -1) or (x == -1 and facing.x == 1) or (y == 1 and facing.y == -1) or (y == -1 and facing.y == 1) then + turnRight() + turnRight() + elseif (facing.y == -1 and x == 1) or (facing.y == 1 and x == -1) or (facing.x == 1 and y == 1) or (facing.x == -1 and y == -1) then + turnRight() + elseif (facing.y == -1 and x == -1) or (facing.y == 1 and x == 1) or (facing.x == 1 and y == -1) or (facing.x == -1 and y == 1) then + turnLeft() + else + print("faceTo: This should never happen") + end +end + +function moveTo(x, y) + if (yRelPos > y) then + faceTo(0, -1) + while yRelPos > y do + forward() + end + elseif (yRelPos < y) then + faceTo(0, 1) + while yRelPos < y do + forward() + end + end + + if (xRelPos > x) then + faceTo(-1, 0) + while xRelPos > x do + forward() + end + elseif (xRelPos < x) then + faceTo(1, 0) + while xRelPos < x do + forward() + end + end +end + +function resupplyItem(slot, num) + turtle.select(slot) + while (turtle.getItemCount(slot) < num) do + turtle.suck(num - turtle.getItemCount(slot)) + end +end + +function resupplyAll() + -- reset current slot numbers + slot_output_1_cur = slot_output_1_min + slot_output_2_cur = slot_output_2_min + slot_output_3_cur = slot_output_3_min + slot_output_4_cur = slot_output_4_min + + -- clean entire inventory + moveTo(0, 2); faceTo(-1, 0) + for i = 1, 16 do + while turtle.getItemCount(i) > 0 do + turtle.select(i) + turtle.drop() + end + end + + -- get ingredient + moveTo(0, 1); faceTo(-1, 0) + slot_input_cur = slot_input_min + for i = slot_input_min, slot_input_max do + if (turtle.getItemCount(i) < 64) then + resupplyItem(i, 64) + end + end + + -- get cells + moveTo(0, 0); faceTo(-1, 0) + slot_cells_cur = slot_cells_min + for i = slot_cells_min, slot_cells_max do + if (turtle.getItemCount(i) < 64) then + resupplyItem(i, 64) + end + end +end + +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 + turtle.select(slot_cells_cur) + end + module.dropSneakyUp(0, drop) + + -- drop input from above (side 1) + turtle.select(slot_input_cur) + drop = input_drop + if (turtle.getItemCount(slot_input_cur) < drop) then + drop = drop - turtle.getItemCount(slot_input_cur) + module.dropSneakyUp(1) + slot_input_cur = slot_input_cur + 1 + turtle.select(slot_input_cur) + end + module.dropSneakyUp(1, drop) +end + +function emptyCentrifuge() + module = peripheral.wrap("right") + + -- get output 1 + turtle.select(slot_output_1_cur) + take = output_1_take + if (turtle.getItemCount(slot_output_1_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_1_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_1_cur = slot_output_1_cur + 1 + turtle.select(slot_output_1_cur) + end + -- if no input is ready, move on immediately + if module.suckSneakyUp(2, take) == false then + return + end + + -- get output 2 + turtle.select(slot_output_2_cur) + take = output_2_take + if (turtle.getItemCount(slot_output_2_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_2_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_2_cur = slot_output_2_cur + 1 + turtle.select(slot_output_2_cur) + end + module.suckSneakyUp(2, take) + + -- get output 3 + turtle.select(slot_output_3_cur) + take = output_3_take + if (turtle.getItemCount(slot_output_3_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_3_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_3_cur = slot_output_3_cur + 1 + turtle.select(slot_output_3_cur) + end + module.suckSneakyUp(2, take) + + -- get output 4 + turtle.select(slot_output_4_cur) + take = output_4_take + if (turtle.getItemCount(slot_output_4_cur) + take > 64) then + take_now = 64 - turtle.getItemCount(slot_output_4_cur) + take = take - take_now + module.suckSneakyUp(2, take_now) + slot_output_4_cur = slot_output_4_cur + 1 + turtle.select(slot_output_4_cur) + end + module.suckSneakyUp(2, take) +end + +-- sets up slot numbers with slots for cells and slots for input ingredient, and output 1 through 4 numbers of slots +function setupSlots(cells, input, output_1, output_2, output_3, output_4) + slot_cells_min = 1 + slot_cells_max = cells + slot_cells_cur = slot_cells_min + cells_drop = cells + + slot_input_min = slot_cells_max + 1 + slot_input_max = slot_input_min + input - 1 + slot_input_cur = slot_input_min + input_drop = input + + slot_output_1_min = 1 + slot_output_1_max = output_1 + slot_output_1_cur = slot_output_1_min + output_1_take = output_1 + + slot_output_2_min = slot_output_1_max + 1 + slot_output_2_max = slot_output_2_min + output_2 - 1 + slot_output_2_cur = slot_output_2_min + output_2_take = output_2 + + slot_output_3_min = slot_output_2_max + 1 + slot_output_3_max = slot_output_3_min + output_3 - 1 + slot_output_3_cur = slot_output_3_min + output_3_take = output_3 + + slot_output_4_min = slot_output_3_max + 1 + slot_output_4_max = slot_output_4_min + output_4 - 1 + slot_output_4_cur = slot_output_4_min + output_4_take = output_4 +end + +function enterSupplyLoop() + while true do + print("Resupplying...") + resupplyAll() + + -- go to first centrifuge and wait to start + moveTo(1, 0) + turtle.select(16) + while turtle.suckUp() do + putBack = turtle.getItemCount(16) + turtle.dropUp(putBack) + sleep(5) + end + + print("Putting cells and ingredient in the centrifuges...") + -- putting in ingredients on the way there + for i = 1, 7, 2 do + for j = 0, 7, 1 do -- moving right + moveTo(i, j) + supplyCentrifuge() + end + for j = 7, 0, -1 do -- moving left + moveTo(i + 1, j) + supplyCentrifuge() + end + end + + sleep(5) + -- wait a little so all centrifuges are ready for having their outputs taken + + print("Getting outputs from the centrifuges...") + -- getting outputs out on the way back + for i = 7, 1, -2 do + for j = 0, 7, 1 do -- moving right + moveTo(i + 1, j) + emptyCentrifuge() + end + for j = 7, 0, -1 do -- moving left + moveTo(i, j) + emptyCentrifuge() + end + end + end +end + +function platinumLoop() + print("Supplying Platinum Dust Centrifuges") + setupSlots(0, 1, 1, 1, 0, 0) -- 0 slots cells, 1 slot platinum dust + print("Starting in 5s...") + sleep(5) + + enterSupplyLoop() +end + +print("Centrifuges even item distribution program") +platinumLoop() diff --git a/New Attempts/Centrifuges.lua b/turtle_code/centrifuges_redstone.lua similarity index 98% rename from New Attempts/Centrifuges.lua rename to turtle_code/centrifuges_redstone.lua index 83ea340..7148a78 100644 --- a/New Attempts/Centrifuges.lua +++ b/turtle_code/centrifuges_redstone.lua @@ -410,15 +410,5 @@ function redstoneLoop() enterSupplyLoop() end -function platinumLoop() - print("Supplying Platinum Dust Centrifuges") - setupSlots(0, 1, 1, 0, 0, 0) -- 0 slots cells, 1 slot platinum dust - print("Starting in 5s...") - sleep(5) - - enterSupplyLoop() -end - print("Centrifuges even item distribution program") - redstoneLoop() diff --git a/New Attempts/Crank.lua b/turtle_code/crank.lua similarity index 100% rename from New Attempts/Crank.lua rename to turtle_code/crank.lua diff --git a/New Attempts/IBF.lua b/turtle_code/ibf.lua similarity index 100% rename from New Attempts/IBF.lua rename to turtle_code/ibf.lua diff --git a/New Attempts/Mining.lua b/turtle_code/mining.lua similarity index 100% rename from New Attempts/Mining.lua rename to turtle_code/mining.lua From 0ead4d60848cfd87262f334f5036f7c930bc1f2a Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Tue, 30 Apr 2024 18:19:30 +0200 Subject: [PATCH 6/6] Add centrifuge distribution programs --- images/centrifuge_turtle_setup.png | 3 ++ original_code/README.md | 5 ++- turtle_code/README.md | 65 +++++++++++++++++------------- 3 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 images/centrifuge_turtle_setup.png diff --git a/images/centrifuge_turtle_setup.png b/images/centrifuge_turtle_setup.png new file mode 100644 index 0000000..ff430c4 --- /dev/null +++ b/images/centrifuge_turtle_setup.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11f74231caa9eb91033b1b01dffff0df40fe58d27decfac8ece69af38e4697ad +size 1073994 diff --git a/original_code/README.md b/original_code/README.md index 49a5ff2..a324a2a 100644 --- a/original_code/README.md +++ b/original_code/README.md @@ -1,3 +1,6 @@ # Original Programs -The code in this directory is not by me and only here for reference. +The code in this directory is not written by me and only here for reference. + +## quarry program +`quarry -oreQuarry true -enderChest 16 -doRefuel false -dumpCompareItems false -invert false -rednet false -dim 16 16 70` diff --git a/turtle_code/README.md b/turtle_code/README.md index d7c6bc1..06e6614 100644 --- a/turtle_code/README.md +++ b/turtle_code/README.md @@ -1,3 +1,24 @@ +## grindstone turtle + +Place an engineering turtle (turtle with crescent hammer, 3 iron + 1 silver) facing the crank of a grindstone + +**execute commands**: +- `pastebin get pRPJkvnv startup` +- `startup` + +same for the killing turtles in xp farm + +## lava refuel setup + +- place at edge of lava lake in the nether +- place 1 bucket of lava in first slot + +**execute commands**: +- `label set ` +- `pastebin get nFSUKiYE lava` +- `refuel` +- `lava 10` + ## miner setup - place one ender chest, then 4 turtles facing away from it around it, with fuel and preferably labels set, like this: @@ -14,6 +35,7 @@ ## boiler builder - **give the turtle fuel beforehand** +- give the turtle a **resupply module on its right side** - place turtle infront (facing away) from a resupply station like this: ![Boiler Turtle Station Setup](../images/boiler_turtle_station_setup.png) @@ -29,18 +51,7 @@ - `pastebin get ZJt5uwjW boiler` - `boiler` -## lava refuel setup - -- place at edge of lava lake in the nether -- place 1 bucket of lava in first slot - -**execute commands**: -- `label set ` -- `pastebin get nFSUKiYE lava` -- `refuel` -- `lava 10` - -## IBF Distribution turtle +## IBF distribution turtle - **give the turtle fuel beforehand** - place above me interface, set the interface to keep 4 dust (titanium/chrome/tungsten) @@ -53,23 +64,19 @@ Like this: - `pastebin get iq0Xe2KF ibf` - `ibf` -## IBF Distribution turtle +## centrifuge turtle -- place above me interface with the dust to smelt set to 4 +Place a turtle with an **inventory module** connected on the right like in the following image: + +![Centrifuge Turtle Setup](../images/centrifuge_turtle_setup.png) + +The leftmost interface should have a stack of cells, the middle one a stack of ingredients, e.g., redstone dust, and the rightmost should be empty. + +This program **does not** survive reboots/unloading! Keep it chunk-loaded and do not restart the server after starting the turtle. + +Make sure the turtle always has enough resources to keep going. If it has to wait too long, it will break eventually!! If this happens, manually take out all products from the centrifuges to fix it. **execute commands**: -- pastebin get iq0Xe2KF ibf -- ibf - -## grindstone turtle - -Place an engineering turtle (turtle with crescent hammer, 3 iron + 1 silver) facing the crank of a grindstone - -**execute commands**: -- `pastebin get pRPJkvnv startup` -- `startup` - -same for the killing turtles in xp farm - -# quarry program -quarry -oreQuarry true -enderChest 16 -doRefuel false -dumpCompareItems false -invert false -rednet false -dim 16 16 70 +- `pastebin get 1reqCa4x cent` (for **redstone**) +- `pastebin get 793PtXnD cent` (for **platinum**) +- `cent`