Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Usage (program name) <x> <y> <z>
- local tArgs = {...}
- xHome, yHome, zHome = gps.locate(3)
- xStart = tonumber( tArgs[1] )
- yStart = tonumber( tArgs[2] )
- zStart = tonumber( tArgs[3] )
- xCount = 0
- yCount = 0
- zCount = 0
- function checkIfFuel()
- return turtle.refuel(0)
- end
- function smartRefuel()
- local fuelLimit = turtle.getFuelLimit()
- if turtle.getFuelLevel() < fuelLimit / 4 then
- for i = 1, 16 do
- turtle.select(i)
- if checkIfFuel() then
- turtle.refuel()
- end
- end
- end
- end
- function inventoryDump()
- turtle.select(16)
- turtle.placeUp()
- for i = 15, 2, -1 do
- turtle.select(i)
- if turtle.getItemCount( turtle.getSelectedSlot() ) > 0 then
- turtle.dropUp()
- end
- end
- turtle.select(16)
- turtle.select(1)
- smartRefuel()
- end
- -- 4 for North, 1 for East, 2 for South, 3 for West
- function getDirection()
- local stX, stY, stZ
- local nwX, nwY, nwZ
- local clcX, clcZ
- local facing
- stX, stY, stZ = gps.locate(3)
- turtle.forward()
- sleep(1)
- nwX, nwY, nwZ = gps.locate(3)
- clcX = stX - nwX
- clcZ = stZ - nwZ
- if tonumber(clcX) ~= 0 then
- if tonumber(clcX) < 0 then
- facing = 1
- end
- if tonumber(clcX) > 0 then
- facing = 3
- end
- end
- if tonumber(clcZ) ~= 0 then
- if tonumber(clcZ) < 0 then
- facing = 2
- end
- if tonumber(clcZ) > 0 then
- facing = 4
- end
- end
- turtle.back()
- return facing
- end
- function faceNorth()
- local direction = getDirection()
- if tonumber(direction) == 3 then
- turtle.turnLeft()
- elseif tonumber(direction) == 4 then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif tonumber(direction) == 1 then
- turtle.turnRight()
- end
- end
- function safeBreakDown()
- if turtle.detectDown then
- turtle.digDown()
- end
- end
- function smartTurn(counter)
- if counter % 2 == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- function goToX()
- local homeCopy = xHome
- if homeCopy < xStart then
- turtle.turnLeft()
- while homeCopy ~= xStart do
- turtle.forward()
- homeCopy = homeCopy + 1
- xCount = xCount + 1
- end
- turtle.turnLeft()
- elseif homeCopy > xStart then
- turtle.turnRight()
- while homeCopy ~= xStart do
- turtle.forward()
- homeCopy = homeCopy - 1
- xCount = xCount - 1
- end
- end
- end
- function goToZ()
- local homeCopy = zHome
- if homeCopy < zStart then
- while homeCopy ~= zStart do
- turtle.forward()
- homeCopy = homeCopy + 1
- zCount = zCount + 1
- end
- elseif homeCopy > zStart then
- turtle.turnLeft()
- turtle.turnLeft()
- while homeCopy > zStart do
- turtle.forward()
- homeCopy = homeCopy - 1
- zCount = zCount - 1
- end
- end
- end
- function goToY()
- local homeCopy = yHome
- if homeCopy < yStart then
- while homeCopy ~= yStart do
- turtle.moveUp()
- homeCopy = homeCopy + 1
- yCount = yCount + 1
- end
- elseif homeCopy > yStart then
- while homeCopy > yStart do
- safeBreakDown()
- turtle.down()
- homeCopy = homeCopy - 1
- yCount = yCount - 1
- end
- end
- end
- function goToCoords()
- faceNorth()
- goToX()
- faceNorth()
- goToZ()
- goToY()
- smartRefuel()
- end
- function quarry()
- for i = 1, 3 do
- turtle.digDown()
- turtle.down()
- for j = 1, 20 do
- for k = 1, 19 do
- turtle.dig()
- turtle.forward()
- end
- smartRefuel()
- if j < 20 then
- smartTurn(j)
- turtle.dig()
- turtle.forward()
- smartTurn(j)
- end
- end
- turtle.turnLeft()
- for j = 1, 19 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- end
- function returnHome()
- for i = 1, 3 do
- turtle.up()
- end
- xMove = math.abs(xCount)
- yMove = math.abs(yCount)
- zMove = math.abs(zCount)
- for i = 1, math.abs(yMove) do
- turtle.up()
- end
- if xCount < 0 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- for i = 1, math.abs(xMove) do
- turtle.forward()
- end
- faceNorth()
- if zCount > 0 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- for i = 1, math.abs(zMove) do
- turtle.forward()
- end
- end
- function miner()
- goToCoords()
- faceNorth()
- quarry()
- returnHome()
- inventoryDump()
- end
- miner()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement