local size = 4 local posX, posY, posZ local direction = 0 posX = 0 posY = 0 posZ = 0 function up() while(not turtle.up()) do turtle.digUp() turtle.attackUp() end posZ = posZ-1 end function forward() while(not turtle.forward()) do local succ, data = turtle.inspect() if(succ and data.name == "minecraft:bedrock") then goBack() return end turtle.dig() turtle.attack() end updateXY(1) end function updateXY(dist) if(direction == 0) then posX = posX+dist elseif(direction == 1) then posY = posY+dist elseif(direction == 2) then posX = posX-dist elseif(direction == 3) then posY = posY-dist else print("invalid direction") end end function turnStart() if(posX>0) then while(direction ~= 2) do turnLeft() end elseif(posY>0) then while(direction ~= 3) do turnLeft() end elseif(posX<0) then while(direction ~= 0) do turnLeft() end elseif(posY<0) then while(direction ~= 0) do turnLeft() end else return false end return true end function goBack() print("Going back") while(posZ > 0) do up() end while(turnStart()) do go() end while(direction ~= 0) do turnRight() end end function down() while(turtle.attackDown()) do end if(turtle.detectDown()) then if(not turtle.digDown()) then goBack() return end end turtle.down() posZ = posZ+1 end function go() --print(posX..","..posY..","..posZ) local succ, data = turtle.inspect() if(succ and data.name == "minecraft:bedrock") then goBack() return end while(turtle.detect()) do turtle.dig() end while(turtle.detectUp()) do turtle.digUp() end if(turtle.detectDown()) then turtle.digDown() end while(turtle.attack()) do end if(not turtle.forward()) then print("Can't move. Going home...") goBack() else updateXY(1) end end function turnRight() turtle.turnRight() direction = (direction+1)%4 end function turnLeft() turtle.turnLeft() direction = (direction-1)%4 end local status, data = turtle.inspectDown() while(not status or data.name ~= "minecraft:bedrock" and posZ < 10) do print("New Layer") for i = 0, size-1 do print("row: "..i) for j = 0, size-2, 1 do go() end if(i+1 ~= size) then if( i%2 == 0) then turnRight() go() turnRight() else turnLeft() go() turnLeft() end else print("End layer") -- os.sleep(10) if(size%2==0) then print("turn right only. Mod is 0") turnRight() else print("U turn mod isn't 1") turnLeft() turnLeft() end end end status, data = turtle.inspectDown() if (not status or data.name ~= "minecraft:bedrock" and posZ < 10) then down() down() down() end end goBack()