Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- -----------------------------
- -- Digger
- -- pastebin get F2HSytaa digger
- -- -----------------------------
- function checkFuel()
- print('checkFuel')
- while turtle.getFuelLevel() < 10 do
- turtle.select(1)
- turtle.refuel(1)
- if turtle.getFuelLevel() < 10 then
- sleep(5)
- end
- if turtle.getItemCount(1) < 2 then
- goHome()
- goBack()
- end
- end
- end
- function forward()
- print('forward')
- checkFuel()
- while not turtle.forward() do
- if turtle.detect() then
- turtle.dig()
- else
- turtle.attack()
- end
- end
- if not skip_tracing then
- if direction == 0 then
- x_coord = x_coord + 1
- elseif direction == 1 then
- y_coord = y_coord + 1
- elseif direction == 2 then
- x_coord = x_coord - 1
- elseif direction == 3 then
- y_coord = y_coord - 1
- end
- end
- end
- function down()
- print('down')
- checkFuel()
- attempts = 0
- for i=1,3 do
- while not turtle.down() do
- if turtle.detectDown() then
- if attempts == 5 then
- goHome()
- exit()
- end
- attempts = attempts + 1
- turtle.digDown()
- else
- turtle.attackDown()
- end
- end
- end
- if not skip_tracing then
- z_coord = z_coord + 1
- end
- end
- function up()
- print('left')
- checkFuel()
- for i=1,3 do
- while not turtle.up() do
- if turtle.detectUp() then
- turtle.digUp()
- else
- turtle.attackUp()
- end
- end
- end
- if not skip_tracing then
- z_coord = z_coord - 1
- end
- end
- function right()
- print('right')
- turtle.turnRight()
- direction = direction + 1
- if direction == 4 then
- direction = 0
- end
- end
- function left()
- print('left')
- turtle.turnLeft()
- direction = direction - 1
- if direction == -1 then
- direction = 3
- end
- end
- function goHome()
- print('goHome')
- skip_tracing = true
- if direction == 0 then
- turtle.turnLeft()
- elseif direction == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif direction == 2 then
- turtle.turnRight()
- end
- if z_coord > 1 then
- for i = 1, z_coord - 1 do
- up()
- end
- end
- if y_coord > 1 then
- for i = 1, y_coord do
- forward()
- end
- end
- turtle.turnLeft()
- if x_coord > 1 then
- for i = 1, x_coord do
- forward()
- end
- end
- for i = 2, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turtle.suckUp()
- turtle.select(2)
- turtle.dropUp()
- end
- function goBack()
- print('goBack')
- turtle.turnLeft()
- turtle.turnLeft()
- if x_coord > 1 then
- for i = 1, x_coord do
- forward()
- end
- end
- turtle.turnRight()
- if y_coord > 1 then
- for i = 1, y_coord do
- forward()
- end
- end
- if z_coord > 1 then
- for i = 1, z_coord - 1 do
- down()
- end
- end
- if direction == 0 then
- turtle.turnLeft()
- elseif direction == 2 then
- turtle.turnRight()
- elseif direction == 3 then
- turtle.turnRight()
- turtle.turnRight()
- end
- skip_tracing = false
- end
- function dig()
- print('dig')
- turtle.digDown()
- turtle.digUp()
- turtle.dig()
- if turtle.getItemCount(16) > 0 then
- goHome()
- goBack()
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Place fuel in slot 1")
- print("Place chest with fuel above the turtle")
- print("Place chest for loot behind the turtle")
- write("Please enter quarry size ")
- lenth = read()
- x_coord = 0
- y_coord = 0
- z_coord = 1
- direction = 0
- even = true
- finished = false
- skip_tracing = false
- layer_changed = true
- forward()
- while not finished do
- dig()
- forward()
- if x_coord == tonumber(lenth) or x_coord == 0 then
- if (y_coord == tonumber(lenth) or y_coord == 0) and not layer_changed then
- -- Go to next layer
- down()
- right()
- right()
- layer_changed = true
- else
- -- Go to next line
- layer_changed = false
- if even then
- right()
- else
- left()
- end
- dig()
- forward()
- if even then
- right()
- else
- left()
- end
- even = not even
- end
- end
- end
- goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement