Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --The local postition tracker, dont have any refrence to real world
- local posx = 0
- local posy = 0
- local posz = 0
- --The local direction set at start, 1 forward, 2 right, 3 back, 4 left
- local direction = 1
- -- Move and update position
- function move()
- if direction == 1 then
- posx = posx + 1
- elseif direction == 2 then
- posz = posz + 1
- elseif direction == 3 then
- posx = posx - 1
- elseif direction == 4 then
- posz = posz - 1
- end
- turtle.forward()
- end
- -- Turn and change direction
- function turnRight()
- direction = direction + 1
- turtle.turnRight()
- end
- -- Turn and change diretction
- function turnLeft()
- direction = direction - 1
- turtle.turnLeft()
- end
- -- make a 3 high tunnel forward
- function tunnelForward()
- if turtle.detect() then
- turtle.dig()
- end
- move()
- if turtle.detectUp() then
- turtle.digUp()
- end
- if turtle.detectDown() then
- turtle.digDown()
- end
- end
- -- Make the robot go to the startingposition
- function goHome()
- if posx > 0 then
- while(direction ~= 3) do
- turnRight()
- end
- for k=1,math.abs(posx),1 do
- move()
- end
- elseif posx < 0 then
- while(direction ~= 1) do
- turnRight()
- end
- for k=1,math.abs(posx),1 do
- move()
- end
- end
- if posz > 0 then
- while(direction ~= 4) do
- turnRight()
- end
- for k=1,math.abs(posz),1 do
- move()
- end
- elseif posz < 0 then
- while(direction ~= 2) do
- turnRight()
- end
- for k=1,math.abs(posz),1 do
- move()
- end
- end
- end
- -----Main funtion-----
- print("Dig v101 by Coffedahl")
- sleep(10)
- print("Please have some chests in slot 1 and fuel in slot 2")
- --get size of tunnel
- print("Please enter length of tunnel:")
- local length = io.read()
- print("Please enter width of tunnel:")
- local width = io.read()
- print("Starting dig")
- --Refuel
- turtle.select(2)
- turtle.refuel()
- turtle.select(1)
- local dig_direction = 1
- for i=1,width,1 do
- for o=1,length,1 do
- tunnelForward()
- if turtle.getItemCount(16) > 0 then
- turtle.select(1)
- turtle.placeDown()
- for e=2,16,1 do
- turtle.select(e)
- turtle.dropDown()
- end
- turtle.select(1)
- end
- end
- if dig_direction == 1 then
- turnRight()
- tunnelForward()
- turnRight()
- dig_direction = 2
- elseif dig_direction == 2 then
- turnLeft()
- tunnelForward()
- turnLeft()
- dig_direction = 1
- end
- if i == width - 1 then
- dig_direction = 0
- end
- end
- goHome()
- print("Done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement