Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local status = "Idle"
- local cycles = 0
- local cyclesDone = 0
- -- Continuiesly updates terminal to inform user of status
- function uiLoop()
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("AutoMiner - tedski999, 2019")
- print("===========================")
- print("")
- print("Status: " .. status)
- print("Fuel: " .. turtle.getFuelLevel())
- print("Cycles: " .. cyclesDone .. "/" .. cycles)
- sleep(0.5)
- end
- end
- -- Main loop controlling the turtles actions
- function minerLoop()
- for i = 1, cycles do
- checkFuelSufficient()
- mineSlice()
- mineCorridor()
- cyclesDone = cyclesDone + 1
- end
- status = "Done!"
- end
- -- Refuel if needed to ... movements required per cycle: 34
- function checkFuelSufficient()
- while turtle.getFuelLevel() < 35 do
- turtle.select(16)
- if turtle.refuel(0) then
- turtle.refuel(1)
- else
- status = "Out of Fuel!"
- while not turtle.refuel(0) do
- sleep(0.5)
- end
- end
- end
- end
- -- Mines a strip on either side of the main corridor
- function mineSlice()
- status = "Mining slice..."
- turtle.dig()
- attemptForward()
- turtle.turnLeft()
- repeatMineForward(6)
- endLeftStrip()
- repeatMineForward(13)
- endRightStrip()
- repeatMineForward(6)
- turtle.digUp()
- attemptForward()
- turtle.digUp()
- turtle.turnRight()
- end
- -- Continue main corridor
- function mineCorridor()
- status = "Continuing main corridor..."
- mine3YForward()
- turtle.turnRight()
- mine3YForward()
- turtle.turnLeft()
- mine3YForward()
- turtle.turnLeft()
- mine3YForward()
- turtle.turnRight()
- turtle.turnRight()
- placeTorchForward()
- turtle.turnLeft()
- end
- -- Place a torch and turn around at the end of the left side stip
- function endLeftStrip()
- turtle.dig()
- placeTorchForward()
- turtle.digDown()
- attemptDown()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Place a torch and turn around at the end of the right side stip
- function endRightStrip()
- turtle.dig()
- turtle.digUp()
- attemptUp()
- turtle.dig()
- placeTorchForward()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Mines forward i times
- function repeatMineForward(i)
- for i = 1, i do
- turtle.dig()
- attemptForward()
- end
- end
- -- Mines a 1x3x1 column in front and moves into it
- function mine3YForward()
- turtle.dig()
- attemptForward()
- turtle.digUp()
- turtle.digDown()
- end
- -- Places a torch directly in front
- function placeTorchForward()
- if turtle.getItemCount(15) < 1 then
- status = "Out of Torches!"
- while turtle.getItemCount(15) < 1 do
- sleep(0.5)
- end
- end
- turtle.select(15)
- turtle.place()
- end
- -- Gravel/Sand proof movement
- function attemptForward()
- while not turtle.forward() do
- turtle.dig()
- end
- end
- -- Gravel/Sand proof movement
- function attemptUp()
- while not turtle.up() do
- turtle.digUp()
- end
- end
- -- Gravel/Sand proof movement
- function attemptDown()
- while not turtle.down() do
- turtle.digDown()
- end
- end
- ---- START POINT ----
- -- Initialization
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Enter number of cycles to be done: ")
- cycles = tonumber(read())
- if cycles == nil then
- print("Sorry, that's not a number!")
- elseif cycles > 20 then
- print("Sorry, max of 20 cycles!")
- elseif cycles < 1 then
- print("Sorry, input must be greater than 0!")
- else
- break
- end
- sleep(1)
- end
- -- Start main loop
- parallel.waitForAny(uiLoop, minerLoop)
- -- End
- term.clear()
- term.setCursorPos(1, 1)
- print("Completed " .. cycles .. " cycles.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement