Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local location = {0,0,0}
- local origin = {0,0,0}
- local dir=1
- local modX= {0,1,0,-1}
- local modZ = {1,0,-1,0}
- local max = {144,2,72}
- turtle.select(1)
- function turnLeft()
- turtle.turnLeft()
- dir = dir - 1
- if dir < 1 then dir = 4 end
- end
- function turnAround()
- turnLeft()
- turnLeft()
- end
- function turnRight()
- turtle.turnRight()
- dir = dir + 1
- if dir > 4 then dir = 1 end
- end
- function addLocStep()
- location[1] = location[1] + modX[dir]
- location[3] = location[3] + modZ[dir]
- end
- function subLocStep()
- location[1] = location[1] - modX[dir]
- location[3] = location[3] - modZ[dir]
- end
- function forward()
- local b = turtle.forward()
- if b then
- addLocStep()
- return true
- else
- return false
- end
- end
- function back()
- local b = turtle.back()
- if b then
- subLocStep()
- return true
- else
- return false
- end
- end
- function dig()
- c=0
- while turtle.detect() do
- turtle.dig()
- c = c+1
- if c > 10 then
- sleep(0.1)
- c=0
- end
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0)
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- end
- end
- function digForward()
- while forward() == false do
- dig()
- end
- end
- function digBack()
- while back() == false do
- turnAround()
- dig()
- turnAround()
- sleep(0)
- end
- end
- function turnOriginLeft()
- while dir ~= 4 do
- turnLeft()
- end
- end
- function turnOriginRight()
- while dir ~= 2 do
- turnLeft()
- end
- end
- function turnOriginDown()
- while dir ~= 3 do
- turnLeft()
- end
- end
- function turnOriginUp()
- while dir ~= 1 do
- turnLeft()
- end
- end
- local input = ""
- while input ~= "start" do
- input = read()
- sleep(0)
- end
- function checkInventory()
- if turtle.getItemCount(9) > 0 then
- return true
- else
- return false
- end
- end
- function getLocCopy()
- local copy = {}
- for i,n in ipairs(location) do
- copy[i] = n
- end
- return copy
- end
- function doDropOff(goBack)
- local orgDir = dir
- local orgPos = getLocCopy()
- moveToOrigin()
- turnOriginDown()
- forward()
- forward()
- dropAll()
- moveToOrigin()
- if goBack then
- moveTo(origin[1],orgPos[3])
- moveTo(orgPos[1],orgPos[3])
- while orgDir ~= dir do
- turnLeft()
- sleep(0)
- end
- end
- end
- function dropAll()
- for i=1,9,1 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- function moveToOrigin()
- moveTo(origin[1],location[3])
- moveTo(origin[1],origin[3])
- end
- function turnToX(x)
- if location[1] < x then
- turnOriginRight()
- elseif location[1] > x then
- turnOriginLeft()
- end
- end
- function turnToZ(z)
- if location[3] < z then
- turnOriginUp()
- elseif location[3] > z then
- turnOriginDown()
- end
- end
- function moveTo(x,z)
- turnToX(x)
- while location[1] ~= x do
- forward()
- sleep(0)
- end
- turnToZ(z)
- while location[3]~=z do
- forward()
- sleep(0)
- end
- end
- for x=1,max[1],1 do
- for z=1,max[3],1 do
- if x ~= 1 and z == 1 then
- else
- --print(tostring(x).."/"..tostring(z).." /// " .. tostring(location[1]) .. "/"..tostring(location[2]).."/"..tostring(location[3]))
- digForward()
- digDown()
- if checkInventory() then
- doDropOff(true)
- end
- end
- end
- if x < max[1] then
- turnOriginLeft()
- digForward()
- digDown()
- if x % 2 == 1 then
- turnOriginDown()
- else
- turnOriginUp()
- end
- end
- --turnOriginDown()
- --digBack()
- end
- doDropOff(false)
Add Comment
Please, Sign In to add comment