wv1106

excavate code computercraft updated

Jan 2nd, 2021 (edited)
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. --this code is for the computercrafted turtles (this mod is used in modpacks like ftb revelations and tekkit)
  2. --to run this program you need to type the name followed by how long how deep and how wide(to the left) you want to make it and if you want it to go up or down (1 = up -1 = down)
  3. --as an example "excavate 10 5 6 1" here I make the hole 10 long 5 deep and 6 wide to the left and go up
  4.  
  5. local tArgs = {...}
  6.  
  7. if #tArgs~=4 then
  8.  
  9.     print("specefie x, y and z and what direction (1 = up -1 = down)")
  10.     local xc, yc, zc, direct = read()
  11.    
  12. else
  13.     xc = tonumber(tArgs[1])-1
  14.     yc = tonumber(tArgs[2])-1
  15.     zc = tonumber(tArgs[3])-1
  16.  
  17.     direct = tonumber(tArgs[4])
  18.  
  19. end
  20.  
  21.  
  22. function info()
  23.     print("fuel: "..turtle.getFuelLevel())
  24.     print(" x: "..xc+1)
  25.     print(" y: "..yc+1)
  26.     print(" z: "..zc+1)
  27.     print("program by: wv1106 on reddit and pastebin")
  28. end
  29.  
  30. function nl()
  31.     if direct==1 then
  32.         turtle.digUp()
  33.         turtle.up()
  34.     elseif direct ==-1 then
  35.         turtle.digDown()
  36.         turtle.down()
  37.     else
  38.         print("1 = up -1 = down")
  39.     end
  40. end
  41.  
  42. function mine()
  43.     while turtle.detect() do
  44.         turtle.dig()
  45.     end
  46. end
  47.  
  48. function move()
  49.     while not turtle.forward() do
  50.         if turtle.attack() then
  51.             turtle.suck()
  52.         else
  53.             if turtle.getFuelLevel()<10 then
  54.                 turtle.refuel()
  55.             end
  56.         end
  57.     end
  58. end
  59.  
  60. function lturn()
  61.     turtle.turnLeft()
  62.     mine()
  63.     move()
  64.     turtle.turnLeft()
  65. end
  66.  
  67. function rturn()
  68.     turtle.turnRight()
  69.     mine()
  70.     move()
  71.     turtle.turnRight()
  72. end
  73.  
  74. function ehome()
  75.     turtle.turnRight()
  76.     for b=1,zc do
  77.         move()
  78.     end
  79.     turtle.turnRight()
  80. end
  81.  
  82.    
  83. function ohome()
  84.     turtle.turnLeft()
  85.     for b=1,zc do
  86.         move()
  87.     end
  88.     turtle.turnLeft()
  89.     for l=1,xc do
  90.         move()
  91.     end
  92.     turtle.turnLeft()
  93.     turtle.turnLeft()
  94. end    
  95.  
  96.  
  97. function layer()
  98.     for b=1,zc do
  99.         for l=1,xc do
  100.             mine()
  101.             move()
  102.         end
  103.         if (b % 2 == 0) then
  104.             lturn()
  105.         else
  106.             rturn()
  107.         end
  108.     end
  109.     for l=1,xc do
  110.         mine()
  111.         move()
  112.     end
  113.     if (zc % 2 == 0) then
  114.         ohome()
  115.     else
  116.         ehome()
  117.     end
  118. end
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. --here startts the actual program
  126.  
  127.  
  128. info()
  129.  
  130. for d=1,yc do
  131.     layer()
  132.     nl()
  133. end
  134. layer()
  135. for d=1,yc do
  136.     if direct==1 then
  137.    
  138.         while not turtle.down() do
  139.             turtle.attackUp()
  140.         end
  141.     elseif direct==-1 then
  142.         while not turtle.up() do
  143.             turtle.attackUp()
  144.         end
  145.     else
  146.         print("error direction not specefied")
  147.     end
  148. end
  149.  
  150. print("finished!")
Add Comment
Please, Sign In to add comment