Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ####################################
- ------------------------------------
- -- Vril's tunneling program v 1.6 --
- ------------------------------------
- ####################################
- --]]
- function isnumber(myvar)
- local num
- if type(myvar)=="number" then return true end
- if type(myvar)~="string" then return false end
- num=tonumber(myvar)
- if num~=nil then return true end
- return false
- end
- function forceDigFront()
- while turtle.detect() do
- turtle.dig()
- sleep(0.2)
- end
- end
- function forceDigUp()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.5)
- end
- end
- function forceMoveForward()
- local can_move=true
- can_move=turtle.forward()
- while not can_move do
- print("There is a something on my way!")
- sleep(2)
- --
- turtle.dig()
- turtle.attack()
- --
- can_move=turtle.forward()
- end
- end
- function forceMoveBack()
- local can_move=true
- can_move=turtle.back()
- while not can_move do
- print("There is a something on my way!")
- sleep(2)
- can_move=turtle.back()
- end
- end
- function forceMoveUp()
- local can_move=true
- can_move=turtle.up()
- while not can_move do
- print("There is a something on my way!")
- sleep(2)
- --
- turtle.digUp()
- turtle.attackUp()
- --
- can_move=turtle.up()
- end
- end
- function forceMoveDown()
- local can_move=true
- can_move=turtle.down()
- while not can_move do
- print("There is a something on my way!")
- sleep(2)
- --
- turtle.digDown()
- turtle.attackDown()
- --
- can_move=turtle.down()
- end
- end
- function unloadAll()
- local i
- local dropcnt=0
- turtle.turnRight()
- turtle.turnRight()
- for i=1,16 do
- dropcnt=turtle.getItemCount(i)
- if i>9 then
- if dropcnt > 0 then
- turtle.select(i)
- turtle.drop()
- end
- elseif not slots[i] then
- if dropcnt > 0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function isFull()
- local i
- local num
- for i=1,16 do
- num=turtle.getItemCount(i)
- if num==0 then
- return false
- end
- end
- return true
- end
- function left()
- if tD[1]==1 and tD[2]==0 then
- tD[1]=0
- tD[2]=-1
- elseif tD[1]==0 and tD[2]==-1 then
- tD[1]=-1
- tD[2]=0
- elseif tD[1]==-1 and tD[2]==0 then
- tD[1]=0
- tD[2]=1
- elseif tD[1]==0 and tD[2]==1 then
- tD[1]=1
- tD[2]=0
- end
- turtle.turnLeft()
- end
- function right()
- if tD[1]==1 and tD[2]==0 then
- tD[1]=0
- tD[2]=1
- elseif tD[1]==0 and tD[2]==1 then
- tD[1]=-1
- tD[2]=0
- elseif tD[1]==-1 and tD[2]==0 then
- tD[1]=0
- tD[2]=-1
- elseif tD[1]==0 and tD[2]==-1 then
- tD[1]=1
- tD[2]=0
- end
- turtle.turnRight()
- end
- function turnL(num1,num2)
- while tD[1]~=num1 or tD[2]~=num2 do
- left()
- end
- end
- function turnR(num1,num2)
- while tD[1]~=num1 or tD[2]~=num2 do
- right()
- end
- end
- function toBase()
- local i
- local x=tX
- local y=tY
- local z=tZ
- if y<0 then
- turnL(0,1)
- for i=1,-y,1 do
- forceMoveForward()
- end
- elseif y>0 then
- turnL(0,-1)
- for i=1,y,1 do
- forceMoveForward()
- end
- end
- turnR(-1,0)
- if stairs == -1 and turtleFloor == 1 then
- forceMoveUp()
- end
- for i=1,x,1 do
- forceMoveForward()
- if stairs == 1 then
- forceMoveDown()
- z=z-1
- elseif stairs == -1 then
- forceMoveUp()
- z=z+1
- end
- end
- if stairs == -1 and turtleFloor == 1 then
- forceMoveDown()
- end
- if z<0 then
- for i=1,-z,1 do
- forceMoveUp()
- end
- elseif z>0 then
- for i=1,z,1 do
- forceMoveDown()
- end
- end
- turnR(1,0)
- end
- function toWork(x,y,z,d)
- local i
- if stairs == 0 then
- forceMoveUp()
- forceMoveUp()
- z=z-2
- end
- turnR(1,0)
- for i=1,x,1 do
- forceMoveForward()
- if stairs == -1 and z ~= 0 then
- forceMoveDown()
- z=z+1
- elseif stairs == 1 then
- forceMoveUp()
- z=z-1
- end
- end
- if y<0 then
- turnR(0,-1)
- for i=1,-y,1 do
- forceMoveForward()
- end
- elseif y>0 then
- turnR(0,1)
- for i=1,y,1 do
- forceMoveForward()
- end
- end
- if z<0 then
- for i=1,-z,1 do
- forceMoveDown()
- end
- elseif z>0 then
- for i=1,z,1 do
- forceMoveUp()
- end
- end
- turnL(d[1],d[2])
- end
- function moveDig(n)
- local i
- local x,y,z,d
- local d={}
- if n<0 then
- n=-n
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,n do
- -----------work break start
- if isFull() then
- x,y,z,d[1],d[2]=tX,tY,tZ,tD[1],tD[2]
- if stairs == 1 and turtleFloor == 1 then
- forceMoveUp()
- end
- toBase()
- if stairs == 1 and turtleFloor == 1 then
- forceMoveDown()
- end
- unloadAll()
- if stairs == -1 and turtleFloor ~= 3 then
- forceMoveUp()
- end
- toWork(x,y,z,d)
- if stairs == -1 and turtleFloor ~= 3 then
- forceMoveDown()
- end
- end
- -----------work break end
- forceDigFront()
- turtle.suck()
- forceMoveForward()
- tX=tX-tD[1]
- tY=tY-tD[2]
- end
- turtle.turnLeft()
- turtle.turnLeft()
- else
- for i=1,n do
- -----------work break start
- if isFull() then
- x,y,z,d[1],d[2]=tX,tY,tZ,tD[1],tD[2]
- if stairs == 1 and turtleFloor == 1 then
- forceMoveUp()
- end
- toBase()
- if stairs == 1 and turtleFloor == 1 then
- forceMoveDown()
- end
- unloadAll()
- if stairs == -1 and turtleFloor ~= 3 then
- forceMoveUp()
- end
- toWork(x,y,z,d)
- if stairs == -1 and turtleFloor ~= 3 then
- forceMoveDown()
- end
- end
- -----------work break end
- forceDigFront()
- turtle.suck()
- forceMoveForward()
- tX=tX+tD[1]
- tY=tY+tD[2]
- end
- end
- end
- function moveDigUp(n)
- local i
- if n<0 then
- n=-n
- for i=1,n do
- turtle.digDown()
- turtle.suckDown()
- forceMoveDown()
- tZ=tZ-1
- end
- else
- for i=1,n do
- forceDigUp()
- turtle.suckUp()
- forceMoveUp()
- tZ=tZ+1
- end
- end
- end
- function makeBung()
- local i
- turtle.select(9)
- --s v1.6
- if stairs == 1 then
- moveDigUp(-1)
- left()
- left()
- moveDig(1)
- right()
- right()
- end
- --s v1.6
- forceDigFront()
- turtle.place()
- left()
- moveDig(1)
- right()
- forceDigFront()
- turtle.place()
- left()
- moveDig(1)
- right()
- forceDigFront()
- turtle.place()
- moveDigUp(-1)
- forceDigFront()
- turtle.place()
- right()
- moveDig(1)
- left()
- forceDigFront()
- turtle.place()
- right()
- moveDig(1)
- left()
- forceDigFront()
- turtle.place()
- moveDigUp(-1)
- forceDigFront()
- turtle.place()
- left()
- moveDig(1)
- right()
- forceDigFront()
- turtle.place()
- left()
- moveDig(1)
- right()
- forceDigFront()
- turtle.place()
- right()
- moveDig(2)
- moveDigUp(2)
- left()
- end
- ------------------------------------
- --global variables:
- tX,tY,tZ=0,0,0
- tD={1,0}
- slots={false,false,false,false,false,false,false,false,false}
- stairs = 0
- turtleFloor = 3
- --Locals:
- local dist = 0
- local light = 0
- local i
- local l_cnt = 0
- local args={...}
- if #args <1 or not isnumber(args[1]) then
- print("Usage: tunnel <distance> [<interval>]")
- print(" <distance> - length of the tunnel.")
- print(" [<interval>] - (optional)Set the light block every <interval> blocks.")
- print(" slots 1,2,3,4 - blocks for left wall/right wall/ceiling/floor.")
- print(" slots 5,6,7,8 - light blocks(left/right/ceiling/floor).")
- print(" Example1: 'tunnel 20 4' - turtle will")
- print("dig tunnel with length 20")
- print("setting light every 4 blocks.")
- print(" Example2: 'tunnel 20 4 st' - stairs up")
- print(" Example3: 'tunnel 20 4 -st' - stairs down")
- return
- end
- print("*'tunneling' prog. is active!")
- print(" *Label: ",os.getComputerLabel())
- print(" *Fuel Level:",turtle.getFuelLevel())
- for i=1,9 do
- if turtle.getItemCount(i) > 0 then
- slots[i]=true
- else
- slots[i]=false
- end
- end
- dist = tonumber(args[1])
- if dist<1 then dist=1 end
- light=dist+1
- if args[2]~=nil and isnumber(args[2]) then
- light = tonumber(args[2])
- if light<1 then light=1 end
- else
- for i=5,8 do slots[i]=false end
- end
- print("Start digging ",dist," blocks front. ")
- if args[3]~=nil then
- if args[3]=="st" then
- stairs=1
- print("Stairs up.")
- end
- if args[3]=="-st" then
- stairs=-1
- print("Stairs down.")
- end
- end
- if args[2]~=nil then
- if args[2]=="st" then
- stairs=1
- print("Stairs up.")
- end
- if args[2]=="-st" then
- stairs=-1
- print("Stairs down.")
- end
- end
- moveDigUp(2)
- turtleFloor = 3 -- <== oO
- right()
- moveDig(1)
- left()
- l_cnt = light-1
- for i=1,dist do
- l_cnt=l_cnt+1
- if i==1 then moveDig(1)
- else
- if stairs~=1 then
- moveDig(1)
- end
- end
- right()
- forceDigUp()
- forceDigFront()
- if slots[2] then
- turtle.select(2)
- turtle.place()
- end
- if slots[3] then
- turtle.select(3)
- turtle.placeUp()
- end
- left()
- left()
- moveDig(1)
- forceDigUp()
- if l_cnt >= light then
- if slots[7] then
- turtle.select(7)
- turtle.placeUp()
- elseif slots[3] then
- turtle.select(3)
- turtle.placeUp()
- end
- else
- if slots[3] then
- turtle.select(3)
- turtle.placeUp()
- end
- end
- moveDig(1)
- forceDigUp()
- forceDigFront()
- if slots[1] then
- turtle.select(1)
- turtle.place()
- end
- if slots[3] then
- turtle.select(3)
- turtle.placeUp()
- end
- moveDigUp(-1)
- turtleFloor = 2 -- <== oO
- forceDigFront()
- if l_cnt >= light then
- if slots[5] then
- turtle.select(5)
- turtle.place()
- elseif slots[1] then
- turtle.select(1)
- turtle.place()
- end
- else
- if slots[1] then
- turtle.select(1)
- turtle.place()
- end
- end
- right()
- right()
- moveDig(2)
- forceDigFront()
- if l_cnt >= light then
- if slots[6] then
- turtle.select(6)
- turtle.place()
- elseif slots[2] then
- turtle.select(2)
- turtle.place()
- end
- else
- if slots[2] then
- turtle.select(2)
- turtle.place()
- end
- end
- moveDigUp(-1)
- turtleFloor = 1 -- <== oO
- forceDigFront()
- turtle.digDown()
- if slots[2] then
- turtle.select(2)
- turtle.place()
- end
- if slots[4] then
- turtle.select(4)
- turtle.placeDown()
- end
- left()
- left()
- moveDig(1)
- turtle.digDown()
- if l_cnt >= light then
- l_cnt=0
- if slots[8] then
- turtle.select(8)
- turtle.placeDown()
- elseif slots[4] then
- turtle.select(4)
- turtle.placeDown()
- end
- else
- if slots[4] then
- turtle.select(4)
- turtle.placeDown()
- end
- end
- moveDig(1)
- forceDigFront()
- turtle.digDown()
- if slots[4] then
- turtle.select(4)
- turtle.placeDown()
- end
- if slots[1] then
- turtle.select(1)
- turtle.place()
- end
- right()
- right()
- moveDig(2)
- left()
- if stairs~=1 then
- moveDigUp(2+stairs)
- else
- moveDigUp(2)
- moveDig(1)
- moveDigUp(1)
- end
- turtleFloor = 3 -- <== oO
- end
- if stairs == -1 then
- moveDigUp(1)
- end
- --s v1.3
- if slots[9] then
- makeBung()
- end
- --e v1.3
- if stairs == 1 then
- moveDigUp(-1)
- end
- toBase()
- for i=1,9 do
- slots[i]=false
- end
- unloadAll()
- print(" *Tunneling application quits!")
- print(" *Fuel level=",turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement