Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- TODO: fill liquid/air and remove falling blocks
- 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(1)
- 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(1)
- end
- end
- end
- end
- -- Mines a strip on either side of the main corridor
- function mineSlice()
- status = "Mining slice..."
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- repeatMineForward(6)
- endLeftStrip()
- repeatMineForward(13)
- endRightStrip()
- repeatMineForward(6)
- turtle.digUp()
- turtle.forward()
- 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()
- turtle.down()
- 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()
- turtle.up()
- turtle.dig()
- placeTorchForward()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Mines forward i times
- function repeatMineForward(i)
- for i = 1, i do
- turtle.dig()
- turtle.forward()
- end
- end
- -- Mines a 1x3x1 column in front and moves into it
- function mine3YForward()
- turtle.dig()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- end
- -- Places a torch directly in front
- function placeTorchForward()
- turtle.select(15)
- turtle.place()
- 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("That's not a number!")
- sleep(1)
- else
- break
- end
- end
- -- Start main loop
- parallel.waitForAny(uiLoop, minerLoop)
- -- End
- term.clear()
- term.setCursorPos(1, 1)
- print("AutoMiner Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement