Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = 3
- print ("## Nick's chunk excavator v" .. version)
- local testing = false
- local size = { x = 4, y = 4, z = 4 }
- local turns = 0
- if testing then print ("## (operating in test mode!)") end
- print ("## (size: " .. size.x .. "x" .. size.y .. ")")
- -- Main loop
- function Excavate ()
- while Refuel() == false do end
- GoForward (1)
- GoDown (1)
- -- Left/right
- local a, b, c = 1, 1, 1
- while a <= size.x do
- -- Up/down
- b = 1
- while b <= size.y do
- -- Forward/backward
- c = size.z
- GoForward (c)
- if b ~= size.y then
- GoDown (1)
- turtle.turnRight()
- turtle.turnRight()
- end
- turns = turns + 2
- b = b + 1
- end
- if b % 2 == 0 then
- TurnToward (2)
- GoForward (c)
- end
- GoUp (b - 2)
- if a ~= size.x then
- if turns % 2 == 0 then
- GoLeft()
- turtle.turnLeft()
- turns = turns - 1
- else
- GoRight()
- turtle.turnRight()
- turns = turns + 1
- end
- end
- a = a + 1
- end
- -- Return home
- if a % 2 == 0 then
- TurnToward (2)
- GoForward (c - 2)
- end
- TurnToward (3)
- GoForward (a - 2)
- GoUp (1)
- GoLeft()
- end
- -- Methods
- function Refuel ()
- for i = 1, 16 do
- turtle.select (i)
- if turtle.refuel (0) then
- turtle.refuel (1)
- return true
- end
- end
- return false
- end
- function TurnToward (direction)
- while turns % 4 ~= direction do
- if turns % 4 > direction then
- turtle.turnLeft()
- turns = turns - 1
- else
- turtle.turnRight()
- turns = turns + 1
- end
- end
- end
- function GoForward (meters)
- for m = 1, meters do
- while turtle.detect() do
- if not testing then turtle.dig() end
- os.sleep (0.5)
- end
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
- Refuel()
- end
- turtle.forward()
- end
- end
- function GoUp (meters)
- for m = 1, meters do
- while turtle.detectUp() do
- if not testing then turtle.digUp() end
- os.sleep (0.5)
- end
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
- Refuel()
- end
- turtle.up()
- end
- end
- function GoDown (meters)
- for m = 1, meters do
- while turtle.detectDown() do
- if not testing then turtle.digDown() end
- os.sleep (0.5)
- end
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
- Refuel()
- end
- turtle.down()
- end
- end
- function GoLeft ()
- turtle.turnLeft()
- turns = turns - 1
- GoForward (1)
- end
- function GoRight ()
- turtle.turnRight()
- turns = turns + 1
- GoForward (1)
- end
- -- Here we go
- Excavate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement