Rename things

This commit is contained in:
2024-04-30 18:02:26 +02:00
parent b8689fb78f
commit 46f9ef0df6
14 changed files with 417 additions and 10 deletions

75
turtle_code/README.md Normal file
View File

@ -0,0 +1,75 @@
## miner setup
- place one ender chest, then 4 turtles facing away from it around it, with fuel and preferably labels set, like this:
![Mining Turtle Setup](../images/mining_setup.png)
- give each turtle compare blocks before starting the program like this
![Mining Turtle Compare Blocks](../images/mining_turtle_compare_blocks.png)
**execute commands**:
- `pastebin get gGy2HWcF mine`
- `mine`
## boiler builder
- **give the turtle fuel beforehand**
- place turtle infront (facing away) from a resupply station like this:
![Boiler Turtle Station Setup](../images/boiler_turtle_station_setup.png)
- the boilers are built infront of the turtle to the right, make sure the ground is even and is at least 2 blocks deep for the water
- provide low pressure boilers, liquid fueled fireboxes and liquiducts in the resupply station like this:
![Boiler Turtle Resupply Station](../images/boiler_turtle_resupply_station.png)
- follow the instructions of the turtle after placing it and starting the program, required items will look like this:
![Boiler Turtle Required Items](../images/boiler_turtle_required_items.png)
**execute commands**:
- `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 <name>`
- `pastebin get nFSUKiYE lava`
- `refuel`
- `lava 10`
## IBF Distribution turtle
- **give the turtle fuel beforehand**
- place above me interface, set the interface to keep 4 dust (titanium/chrome/tungsten)
Like this:
![IBF Setup](../images/ibf_setup.png)
**execute commands**:
- `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
**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

473
turtle_code/boiler.lua Normal file
View File

@ -0,0 +1,473 @@
xRelPos = 0 -- "positive = forward"
yRelPos = 0 -- "positive = right"
zRelPos = 0 -- "positive = upwards"
facing = {
x = 1,
y = 0
}
-- slots for all the items needed
slot_bucket1 = 1
slot_bucket2 = 2
slot_lff = 3 -- 18 pieces + 1 for resupply
slot_lpb1 = 4 -- 1 stack
slot_lpb2 = 5 -- 10 pieces -> 64 + 10 = 74, 72 + 2 extra for 1 in each slot for resupply
slot_liquiduct = 6 -- 12 pieces + 1 for resupply
slot_aq_acc = 7
slot_steam_cons = 8
slot_energy_bridge = 9
slot_hv_prod = 10
slot_mfsu = 11
slot_glass_fiber = 12
slot_trash = 16
num_lff = 19
num_lpb1 = 64
num_lpb2 = 10
num_liquiduct = 13
num_aq_acc = 2
num_steam_cons = 2
num_energy_bridge = 2
num_hv_prod = 2
num_mfsu = 1
num_glass_fiber = 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
-- ask user to place <number> items with name <name> in slot <slot>
function initSlot(name, slot, number)
turtle.select(slot)
print("Please put ", number, " ", name, " in the selected slot.")
while turtle.getItemCount(slot) < number do
sleep(1)
end
print("Got all required ", name)
end
function initSlots(num)
-- setup building slots
initSlot("Water Bucket", slot_bucket1, 1)
initSlot("Water Bucket", slot_bucket2, 1)
initSlot("Liquid Fueled Firebox", slot_lff, 1)
initSlot("Low Pressure Boiler", slot_lpb1, 1)
initSlot("Low Pressure Boiler", slot_lpb2, 1)
initSlot("Liquiduct", slot_liquiduct, 1)
initSlot("Aqueous Accumulators", slot_aq_acc, num_aq_acc * num)
initSlot("Steam Consumers", slot_steam_cons, num_steam_cons * num)
initSlot("Energy Bridges", slot_energy_bridge, num_energy_bridge * num)
initSlot("HV Producers", slot_hv_prod, num_hv_prod * num)
initSlot("MFSUs", slot_mfsu, num_mfsu * num)
initSlot("Glass Fiber", slot_glass_fiber, num_glass_fiber * num)
end
function placeLeftRight(slot)
turtle.select(slot)
-- figure out whether to place left or right first depending on current rotation
if (facing.y ~= 0) then
-- if already facing left or right, place, turn twice, place is enough
else
turnRight()
end
forcePlace()
turnRight(); turnRight()
forcePlace()
-- don't care about end rotation
end
function placeDown(slot)
-- doesn't care about turtle rotation at all
turtle.select(slot_trash)
turtle.digDown()
turtle.select(slot)
forcePlaceDown()
end
function toNextLayer()
forceUpwards()
end
function placeLayer(slots_down, slots_left_right, forwardX, forwardY)
localFacingX = forwardX
localFacingY = forwardY
for i=1, 7 do
if i ~= 1 then
-- placeLeftRight does not necessarily rotate back
faceTo(localFacingX, localFacingY)
forceForward()
end
if (slots_down[i] ~= nil) then
placeDown(slots_down[i])
end
if (slots_left_right[i] ~= nil) then
placeLeftRight(slots_left_right[i])
end
end
end
function placeLowestLayer(forwardX, forwardY)
localFacingX = forwardX
localFacingY = forwardY
for i = 1, 2 do
placeDown(slot_bucket1)
placeLeftRight(slot_lff)
faceTo(localFacingX, localFacingY)
forceForward()
turtle.select(slot_trash)
turtle.digDown()
forceForward()
placeDown(slot_bucket2)
placeLeftRight(slot_lff)
faceTo(-localFacingX, -localFacingY)
forceForward()
turtle.select(slot_bucket1)
forcePlaceDown()
placeLeftRight(slot_lff)
turtle.select(slot_bucket2)
forcePlaceDown()
placeDown(slot_aq_acc)
faceTo(localFacingX, localFacingY)
forceForward()
if i == 1 then
forceForward()
placeLeftRight(slot_liquiduct)
faceTo(localFacingX, localFacingY)
forceForward()
end
end
end
function buildUnit()
-- build a single setup consisting of 2 boilers
-- the initial positioning is like this, where b is the boiler, l is the liquiducts/glass fiber on top, and ^ is the turtle, looking north
-- bbb
-- bbb
-- bbb
-- llll
-- bbb
-- bbb
-- bbb
-- ^
-- keep track of correct facing
localFacingX = facing.x
localFacingY = facing.y
forceForward()
-- turtle layer 1
placeLowestLayer(localFacingX, localFacingY)
localFacingX = -1 * localFacingX; localFacingY = -1 * localFacingY
toNextLayer()
-- turtle layer 2
placeLayer(
{slot_lff, slot_lff, slot_lff, slot_liquiduct, slot_lff, slot_lff, slot_lff},
{slot_lpb2, slot_lpb2, slot_lpb2, nil, slot_lpb2, slot_lpb1, slot_lpb1},
localFacingX, localFacingY
)
localFacingX = -1 * localFacingX; localFacingY = -1 * localFacingY
toNextLayer()
-- turtle layers 3-5
for i = 3, 5 do
placeLayer(
{slot_lpb1, slot_lpb1, slot_lpb1, nil, slot_lpb1, slot_lpb1, slot_lpb1},
{slot_lpb1, slot_lpb1, slot_lpb1, nil, slot_lpb1, slot_lpb1, slot_lpb1},
localFacingX, localFacingY
)
localFacingX = -1 * localFacingX; localFacingY = -1 * localFacingY
toNextLayer()
end
-- turtle layer 6
placeLayer(
{slot_lpb2, slot_lpb1, slot_lpb1, nil, slot_lpb1, slot_lpb1, slot_lpb1},
{nil, slot_liquiduct, nil, slot_glass_fiber, nil, slot_liquiduct},
localFacingX, localFacingY
)
localFacingX = -1 * localFacingX; localFacingY = -1 * localFacingY
toNextLayer()
-- turtle layer 7
placeLayer(
{slot_liquiduct, slot_steam_cons, slot_liquiduct, nil, slot_liquiduct, slot_steam_cons, slot_liquiduct},
{nil, nil, nil, nil, nil, nil, nil},
localFacingX, localFacingY
)
localFacingX = -1 * localFacingX; localFacingY = -1 * localFacingY
toNextLayer()
-- turtle layer 8
placeLayer(
{nil, slot_energy_bridge, slot_hv_prod, slot_mfsu, slot_hv_prod, slot_energy_bridge, nil},
{nil, nil, nil, nil, nil, nil, nil},
localFacingX, localFacingY
)
localFacingX = -1 * localFacingX; localFacingY = -1 * localFacingY
faceTo(localFacingX, localFacingY)
-- end
forceForward(); forceForward(); forceForward()
turnRight();
forceForward()
turnRight(); turnRight()
forceDownwards()
turtle.select(slot_glass_fiber)
turtle.digDown()
forceDownwards()
forcePlace()
turnRight(); turnRight(); forceForward(); turnRight(); turnRight()
forcePlace() -- place mined glass fiber back
forceDownwards()
forcePlaceUp()
forceDownwards(); forceDownwards(); forceDownwards()
turtle.select(slot_liquiduct)
forcePlaceDown()
end
function throwTrash()
turtle.select(slot_trash)
turtle.drop()
end
function resupplyItem(name, slot, min_num)
module = peripheral.wrap("right")
module.link()
if (turtle.getItemCount(slot) < min_num) then
module.resupply(slot)
end
if (turtle.getItemCount(slot) >= min_num) then
return
end
-- start complaining
print("Insufficient ", name, " in resupply station, waiting...")
while (turtle.getItemCount(slot) < min_num) do
sleep(1)
module.resupply(slot)
end
print("Got Items, continuing...")
end
function resupplyAll()
-- expected position of the resupply station
moveTo(0, 0)
faceTo(-1, 0)
resupplyItem("Liquid Fueled Fireboxes", slot_lff, num_lff)
resupplyItem("Low Pressure Boilers", slot_lpb1, num_lpb1)
resupplyItem("Low Pressure Boilers", slot_lpb2, num_lpb2)
resupplyItem("Liquiducts", slot_liquiduct, num_liquiduct)
end
print("-- This program can not restart after the turtle was unloaded --")
print("-- Keep the turtle loaded the entire time while it is building --")
print("")
print("Boilers will be built infront of the turtle, stretching to the right.")
print("Please place a resupply station with liquiducts, liquid fueled fireboxes and low pressure boilers behind the turtle.")
num_boilers = 0
while num_boilers < 1 or num_boilers > 16 do
print("How many pairs of boilers do you want to build?")
write ("> ") input = io.read()
num_boilers = tonumber(input)
if (num_boilers < 1) then print("Enter at least 1") end
if (num_boilers > 16) then print("Can build a maximum of 16 pairs at once") end
end
initSlots(num_boilers)
resupplyAll()
for i = 1, num_boilers do
moveTo(1, i * 4 - 3)
faceTo(1, 0)
buildUnit()
-- move back in x direction only
faceTo(-1, 0)
forceForward(); forceForward(); forceForward(); forceForward(); forceForward()
forceDownwards()
moveTo(0, 0)
throwTrash()
resupplyAll()
end
faceTo(1, 0)
print("Finished building ", num_boilers, " boilers.")

View File

@ -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 <cells> slots for cells and <input> 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()

View File

@ -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 <cells> slots for cells and <input> 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
print("Centrifuges even item distribution program")
redstoneLoop()

4
turtle_code/crank.lua Normal file
View File

@ -0,0 +1,4 @@
while true do
turtle.attack()
end

206
turtle_code/ibf.lua Normal file
View File

@ -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

424
turtle_code/mining.lua Normal file
View File

@ -0,0 +1,424 @@
maxCompareSlot = 0 -- all slots up to this one are used for comparing, initialized in initCompareSlots
currentCompareSlot = 1 -- current compare slot (does not have to be saved)
startupWait = 5 -- time in seconds to wait after reading state before resuming
xRelPos = 0 -- "positive = forward"
yRelPos = 0 -- "positive = right"
zRelPos = 0 -- "positive = upwards"
facing = {
x = 1,
y = 0
}
holeCounter = {
line = 0,
hole = 0
}
function printPos()
print("At (", xRelPos, ", ", yRelPos, ", ", zRelPos, ") facing (", facing.x, ", ", facing.y, ")")
end
function startupTimer()
print("Waiting ", startupWait, "s before starting... ")
sleep(startupWait)
print("Starting!")
end
function setupResume()
if fs.exists("startup") then
return
end
local file = fs.open("startup", "w") --Startup File
file.writeLine( --The below is on the left because spacing
[[
print("Resuming Miner")
local event
if fs.exists("state") then
os.run({},"]]..shell.getRunningProgram()..[[")
else
print("Never mind, no save file found")
fs.delete("startup")
end
]])
file.close()
end
-- get all lines from a file, returns an empty
-- list/table if the file does not exist
function lines_from(file)
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
function readState()
if not fs.exists("state") then
initCompareSlots()
return
end
print("Reading state after restart")
local file = fs.open("state", "r")
xRelPos = tonumber(file.readLine())
yRelPos = tonumber(file.readLine())
zRelPos = tonumber(file.readLine())
facing.x = tonumber(file.readLine())
facing.y = tonumber(file.readLine())
holeCounter.line = tonumber(file.readLine())
holeCounter.hole = tonumber(file.readLine())
maxCompareSlot = tonumber(file.readLine())
file.close()
print("Read state:")
printPos()
startupTimer()
end
function writeState()
if fs.exists("state") then
fs.delete("state")
end
file = fs.open("state", "w")
file.writeLine(tostring(xRelPos))
file.writeLine(tostring(yRelPos))
file.writeLine(tostring(zRelPos))
file.writeLine(tostring(facing.x))
file.writeLine(tostring(facing.y))
file.writeLine(tostring(holeCounter.line))
file.writeLine(tostring(holeCounter.hole))
file.writeLine(tostring(maxCompareSlot))
file.close()
end
-- helper functions for movement
function forward()
xRelPos = xRelPos + facing.x
yRelPos = yRelPos + facing.y
writeState()
if turtle.forward() then
return true
end
xRelPos = xRelPos - facing.x
yRelPos = yRelPos - facing.y
writeState()
turtle.dig()
turtle.attack()
return false
end
function upwards()
zRelPos = zRelPos + 1
writeState()
if turtle.up() then
return true
end
zRelPos = zRelPos - 1
writeState()
turtle.digUp()
turtle.attackUp()
return false
end
function downwards()
zRelPos = zRelPos - 1
writeState()
if turtle.down() then
return true
end
zRelPos = zRelPos + 1
writeState()
turtle.digDown()
turtle.attackDown()
return false
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
writeState()
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
writeState()
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
-- should only be called once when manually starting, not when restarting
function initCompareSlots()
print("Setting up compare slots...")
while true do
if (turtle.getItemCount(maxCompareSlot + 1) == 0) then
break
end
maxCompareSlot = maxCompareSlot + 1
end
print("Found ", maxCompareSlot, " compare slots!")
end
-- checks slots 1..maxCompareSlot against currently looked at block
-- make sure that the selected slot == currentCompareSlot at all times
function blockIsWorth()
if (maxCompareSlot <= 0) then
-- special case
return true
end
lastCompareSlot = currentCompareSlot
while true do
if turtle.compare() then
return false
end
-- cycle currentCompareSlot, fmod would work perfectly if indices started at 0 -_-
nextCompareSlot = currentCompareSlot + 1
if nextCompareSlot > maxCompareSlot then
nextCompareSlot = 1
end
if (nextCompareSlot == lastCompareSlot) then
break
end
currentCompareSlot = nextCompareSlot
turtle.select(currentCompareSlot)
end
return true
end
function checkForItems()
dir = math.fmod(zRelPos, 2)
-- alternatingly check relative facing (left, forward, right) and (right, forward, left) blocks, so at the end we can face backwards when going up and check without turning at all
-- -> two turns per mined level
if (dir == 0) then
faceTo(0, -1) -- just to be safe, but this should never really do anything except for the first level
if blockIsWorth() then
turtle.dig()
end
turnRight()
if blockIsWorth() then
turtle.dig()
end
turnRight()
if blockIsWorth() then
turtle.dig()
end
else
faceTo(0, 1)
if blockIsWorth() then
turtle.dig()
end
turnLeft()
if blockIsWorth() then
turtle.dig()
end
turnLeft()
if blockIsWorth() then
turtle.dig()
end
end
end
-- Digs straight down right where it is, taking resources with it
function digHole()
print("Digging Hole (", holeCounter.line, ", ", holeCounter.hole, ")")
-- go down
turtle.digDown()
while downwards() do
checkForItems()
turtle.digDown()
end
-- go back up
-- look at the remaining direction (-1, 0) and check blocks
faceTo(-1, 0)
while zRelPos < 0 do
if blockIsWorth() then
turtle.dig()
end
upwards()
end
end
function shouldReturnItems()
if turtle.getItemCount(11) == 0 then
return false
end
return true
end
-- moves to the chest and deposits items, but only when deemed necessary by shouldReturnItems
function returnItems()
if not shouldReturnItems() then
return
end
-- chest coordinates are -1, 0, so go to 0, 0 facing "backwards"
moveTo(0, 0)
faceTo(-1, 0)
local droppedAll = true
while true do
droppedAll = true
-- already facing right direction, put items
for slot = 1, maxCompareSlot do
-- put away compare slots' items except one
turtle.select(slot)
turtle.drop(turtle.getItemCount(slot) - 1)
if (turtle.getItemCount(slot) ~= 1) then
droppedAll = false
end
end
for slot = maxCompareSlot + 1, 16 do
-- then drop everything else
turtle.select(slot)
turtle.drop()
if (turtle.getItemCount(slot) ~= 0) then
droppedAll = false
end
end
if (droppedAll) then
break
end
end
-- necessary so the next mined block doesn't go in random places
turtle.select(currentCompareSlot)
end
function moveToNext()
if not (zRelPos == 0) then
return -- we're resuming, don't move, don't increase hole
end
print("Moving to the next hole")
xPos = 1
yPos = 1
-- find out where the next hole should be
for i = 1, holeCounter.line do
if math.fmod(i, 2) == 0 then
xPos = xPos + 2
yPos = 1
else
xPos = xPos + 3
yPos = 0
end
end
for i = 1, holeCounter.hole do
xPos = xPos - 1
yPos = yPos + 2
end
moveTo(xPos, yPos)
-- update holeCounter
-- if the xPos we calculated is 1 that means we need to start the next line
if xPos == 0 then
holeCounter.line = holeCounter.line + 1
holeCounter.hole = 0
else
holeCounter.hole = holeCounter.hole + 1
end
end
setupResume()
readState()
while true do
moveToNext()
digHole()
print("Returning to chest")
returnItems()
end