Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local finished = false
- local n = 0
- local orientation = 0
- function d()
- return turtle.detect()
- end
- function dd()
- return turtle.detectDown()
- end
- function l()
- turtle.turnLeft()
- orientation = orientation - 90
- if (orientation == -360) then
- orientation = 0
- elseif (orientation == -270) then
- orientation = 90
- end
- end
- function r()
- turtle.turnRight()
- orientation = orientation + 90
- if (orientation == 360) then
- orientation = 0
- elseif (orientation == 270) then
- orientation = -90
- end
- end
- function f()
- turtle.forward()
- end
- function b()
- turtle.back()
- end
- function selectBuildMaterial()
- local foundBuildMaterial = false
- local buildMaterialIndex = 1
- for i = 1, 16 do
- turtle.select(i)
- if (not turtle.refuel(0)) and (not foundBuildMaterial) and (turtle.getItemCount() > 0) then
- foundBuildMaterial = true
- buildMaterialIndex = i
- end
- end
- if not foundBuildMaterial then
- finished = true
- else
- turtle.select(buildMaterialIndex)
- end
- end
- function refuel()
- local foundFuel = false
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) and (not foundFuel) then
- turtle.refuel(1)
- foundFuel = true
- end
- end
- if not foundFuel then
- finished = true
- end
- selectBuildMaterial()
- end
- while not finished do
- if (turtle.getFuelLevel() <= 0) then
- refuel()
- end
- if (orientation ~= 0) then
- if (orientation < 0) then
- r()
- if d() then
- l()
- else
- f()
- if dd() then
- b()
- l()
- else
- b()
- end
- end
- elseif (orientation > 0) then
- l()
- if d() then
- r()
- else
- f()
- if dd() then
- b()
- r()
- else
- b()
- end
- end
- end
- end
- if d() then
- r()
- if d() then
- l()
- l()
- if d() then
- finished = true
- else
- f()
- if dd() then
- finished = true
- end
- end
- else
- f()
- if dd() then
- b()
- l()
- l()
- if d() then
- finished = true
- else
- f()
- if dd() then
- finished = true
- end
- end
- end
- end
- else
- f()
- if dd() then
- b()
- r()
- if d() then
- l()
- l()
- if d() then
- finished = true
- else
- f()
- if dd() then
- finished = true
- end
- end
- else
- f()
- if dd() then
- b()
- l()
- l()
- if d() then
- finished = true
- else
- f()
- if dd() then
- finished = true
- end
- end
- end
- end
- end
- end
- if (turtle.getItemCount() <= 0) then
- selectBuildMaterial()
- end
- turtle.placeDown()
- n = n+1
- if n>10000 then
- finished = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement