Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs ~= 2 then
- print("Usage: strip <# of strips> <strip depth>")
- return
- end
- local stripCount=tonumber(tArgs[1])
- local stripDepth=tonumber(tArgs[2])
- local heading="forward"
- local xPos,zPos=0,0
- function faceLeft()
- if heading =="forward" then
- turtle.turnLeft()
- elseif heading=="backward" then
- turtle.turnRight()
- elseif heading=="left" then
- elseif heading=="right" then
- turtle.turnLeft()
- turtle.turnLeft()
- else
- print("error invalid heading fL")
- return
- end
- heading="left"
- end
- function faceRight()
- if heading=="forward" then
- turtle.turnRight()
- elseif heading=="backward" then
- turtle.turnLeft()
- elseif heading=="left" then
- turtle.turnRight()
- turtle.turnRight()
- elseif heading=="right" then
- else
- print("error invalid heading fR")
- return
- end
- heading="right"
- end
- function faceForward()
- if heading=="forward" then
- elseif heading=="backward" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif heading=="left" then
- turtle.turnRight()
- elseif heading=="right" then
- turtle.turnLeft()
- else
- print("error invalid heading fF")
- return
- end
- heading="forward"
- end
- function faceBackward()
- if heading=="forward" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif heading=="backward" then
- elseif heading=="left" then
- turtle.turnLeft()
- elseif heading=="right" then
- turtle.turnRight()
- else
- print("error invalid heading fB")
- return
- end
- heading="backward"
- end
- function canRTH()
- local xDistance=math.abs(xPos)
- local zDistance=math.abs(zPos)
- if (xDistance + zDistance + 2) > turtle.getFuelLevel() then
- return false
- else
- return true
- end
- end
- function moveForward()
- while not turtle.forward() do
- if turtle.detect() then
- turtle.dig()
- sleep(0.8)
- end
- if turtle.attack() then
- end
- end
- end
- function goTo(x,z)
- local distanceToTarget = xPos-x+zPos-z
- if canRTH() and distanceToTarget+2<turtle.getFuelLevel() then
- if z>zPos then
- faceForward()
- for i=1,z-zPos do
- if turtle.detect() then
- turtle.dig()
- end
- moveForward()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.suck()
- zPos=zPos+1
- print("forwards1")
- end
- end
- if z<zPos then
- faceBackward()
- for i=1,zPos-z do
- if turtle.detect() then
- turtle.dig()
- end
- moveForward()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.suck()
- zPos=zPos-1
- print("backwards1")
- end
- end
- if x>xPos then
- faceRight()
- for i=1,x-xPos do
- if turtle.detect() then
- turtle.dig()
- end
- moveForward()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.suck()
- xPos=xPos+1
- print("right1")
- end
- end
- if x<xPos then
- faceLeft()
- for i=1,xPos-x do
- if turtle.detect() then
- turtle.dig()
- end
- moveForward()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.suck()
- xPos=xPos-1
- print("left1")
- end
- end
- else
- local lastX,lastZ=xPos,zPos
- returnToHome()
- print("I need fuel in slot 1, then press enter")
- io.read()
- turtle.select(1)
- turtle.refuel()
- print("Resuming..")
- goTo(lastX,lastZ)
- end
- end
- function returnToHome()
- goTo(0,zPos)
- goTo(0,0)
- faceLeft()
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- faceForward()
- end
- goTo(0,1)
- for i=1,stripCount do
- sleep(1)
- goTo(-stripDepth,i*3)
- goTo(0,i*3)
- goTo(stripDepth,i*3)
- end
- returnToHome()
- print("Finished. Mined " .. stripCount .. "strips for " .. stripDepth .. " blocks each.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement