Advertisement
Guest User

piddumine

a guest
Nov 1st, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.78 KB | None | 0 0
  1.  
  2.  
  3. function ckFuel()
  4.         if turtle.getFuelLevel() == 0 then
  5.                 turtle.refuel(1)
  6.         end
  7. end
  8.  
  9. function digFW()
  10.         while not turtle.forward() do
  11.                 ckFuel()
  12.                 turtle.dig()
  13.         end
  14. end
  15.  
  16. function digUP()
  17.         while not turtle.up() do
  18.                 ckFuel()
  19.                 turtle.digUp()
  20.         end
  21.         ckFuel()
  22.         turtle.down()
  23. end
  24.  
  25. function tunnelLength()
  26.         local l = 10
  27.         print("Set Tunnel's Length, default is 10")
  28.         print("Tunnel's length?")
  29.         l = read()
  30.         if l == "" then
  31.         l = 10
  32.         end
  33.         return l
  34. end
  35.  
  36. function tunnelWidth()
  37.     local w = 1
  38.     print("Set Tunnel's Width, default is 1")
  39.     print("Tunnel's width?")
  40.     w = read()
  41.     if w == "" then
  42.         w = 1
  43.     end
  44.     return w
  45. end
  46.  
  47. function gridRows()
  48.         local r = 10
  49.         print("Set Grid's raws, default is 10")
  50.         print("Grid's Raws?")
  51.         r = read()
  52.         if r == "" then
  53.         r = 10
  54.         end
  55.         return r
  56. end
  57.  
  58. function gridColumns()
  59.         local c = 10
  60.         print("Set Grid's columns, default is 10")
  61.         print("Grid's columns?")
  62.         c = read()
  63.         if c == "" then
  64.                 c = 10
  65.         end
  66.         return c
  67. end
  68.  
  69. function placeTorch()
  70.         turtle.select(2)
  71.         if turtle.compareTo(3) then
  72.                 turtle.select(2)
  73.                 turtle.placeDown()
  74.                 turtle.select(1)
  75.         end
  76. end
  77.  
  78. function digSides(j,width,torches)
  79.     if j%2 == 0 then
  80.         turtle.turnRight()
  81.         ckFuel()
  82.         digWalls(width/2,torches)
  83.         turtle.turnLeft()
  84.     elseif j%2 == 1 then
  85.         turtle.turnLeft()
  86.         ckFuel()
  87.         digWalls(width/2,torches)
  88.         turtle.turnRight()
  89.     end
  90. end
  91.        
  92.  function digWalls(length,torches)
  93.     for i=1, length do
  94.         ckFuel()
  95.         digFW()
  96.         ckFuel()
  97.         turtle.digDown()
  98.         turtle.suckDown()
  99.         ckFuel()
  100.         digUP()
  101.         if torches == "y" then
  102.                 if i%10 == 0 then
  103.                         placeTorch()
  104.                 end
  105.         end
  106.     end
  107.  
  108.     -- check fuel than back to the starting point
  109.     for i = 1 , length do
  110.         ckFuel()
  111.         turtle.back()
  112.     end
  113.  
  114.     if turtle.getFuelLevel() == 0 then
  115.             print("Turtle as no more fuel!!!")
  116.     end
  117.  
  118. function digTunnel(length,width,torches)
  119.     for i=1, length do
  120.         ckFuel()
  121.         digFW()
  122.         ckFuel()
  123.         turtle.digDown()
  124.         turtle.suckDown()
  125.         ckFuel()
  126.         digUP()
  127.         if width ~= 1 then
  128.             for j=2, width do
  129.                 if j <= 3 then
  130.                     digSides(j,width,torches)
  131.                 end
  132.             end
  133.         end
  134.         if torches == "y" then
  135.                 if i%10 == 0 then
  136.                         placeTorch()
  137.                 end
  138.         end
  139.     end
  140.  
  141.     -- check fuel than back to the starting point
  142.     for i = 1 , length do
  143.         ckFuel()
  144.         turtle.back()
  145.     end
  146.  
  147.     if turtle.getFuelLevel() == 0 then
  148.             print("Turtle as no more fuel!!!")
  149.     end
  150. end
  151.  
  152. function tripleFW()
  153.   ckFuel()
  154.   turtle.forward()
  155.   ckFuel()
  156.   turtle.forward()
  157.   ckFuel()
  158.   turtle.forward()
  159.   ckFuel()
  160. end
  161.  
  162. function digGridTunnel(rows,columns,step,torches)
  163.     for r=1,rows do
  164.         ckFuel()
  165.         digFW()
  166.         ckFuel()
  167.         turtle.digDown()
  168.         turtle.suckDown()
  169.         ckFuel()
  170.         digUP()
  171.         if torches == "y" then
  172.             if r%10 == 0 then
  173.                                             placeTorch()
  174.             end
  175.   end  
  176.  
  177.     if tonumber(columns) == 1 or tonumber(columns)%2 == 1 then
  178.         if r ~= 0 and r ~= 1 and r%step == 0 then
  179.             ckFuel()
  180.             turtle.turnRight()
  181.             digTunnel(2,torches)
  182.             turtle.turnLeft()
  183.     turtle.turnLeft()
  184.     ckFuel()
  185.     digTunnel(2,torches)
  186.     turtle.turnRight()
  187.                         end
  188.                 end
  189.         end
  190.  if tonumber(columns) >1 and tonumber(columns)%2 ==0 then
  191.    turtle.turnRight()
  192.    ckFuel()
  193.    digTunnel(2,torches)
  194.    turtle.turnLeft()
  195.    ckFuel()
  196. elseif tonumber(columns)%2 == 0 then
  197.   turtle.turnLeft()
  198.   ckFuel()
  199.   digTunnel(2,torches)
  200.   turtle.turnRight()
  201.   ckFuel()
  202. end
  203. end
  204.  
  205. function digGrid(rows,columns,step,torches)
  206.     if step == 0 then
  207.             step = 3
  208.     end
  209.     digGridTunnel(rows,1,step,torches)
  210.     ckFuel()
  211.     turtle.turnRight()
  212.     digTunnel(3,torches)
  213.     ckFuel()
  214.     tripleFW()
  215.     turtle.turnRight()
  216.     if tonumber(columns) >2 then
  217.             digGridTunnel(rows,2,step,torches)
  218.             ckFuel()
  219.             turtle.turnLeft()
  220.             digTunnel(3,torches)
  221.             ckFuel()
  222.             tripleFW()          
  223.             turtle.turnLeft()
  224.     end
  225.     if tonumber(columns) >= 3 then  
  226.         for c = 3, columns do
  227.             digGridTunnel(rows,c,step,torches)
  228.             if c%2 == 1 then
  229.                 ckFuel()
  230.                 turtle.turnRight()
  231.                 digTunnel(3,torches)
  232.                 tripleFW()
  233.                 turtle.turnRight()
  234.             elseif c%2 == 0 then
  235.                 ckFuel()
  236.                 turtle.turnLeft()
  237.                 digTunnel(3,torches)
  238.                 tripleFW()
  239.                 turtle.turnLeft()
  240.             end
  241.         end
  242.     end
  243. end
  244.  
  245.                    
  246.  
  247. print("Piddu's Automine Turtle")
  248.  
  249. local l
  250. local w
  251. local p = ""
  252. local t = ""
  253. local rows = 0
  254. local columns = 0
  255. local step = 3
  256.  
  257. print("Chose a Mine Pattern:")
  258. print("- single tunnel pattern, press 1")
  259. print("- grid pattern, press 2")
  260.  
  261.  
  262. p = read()
  263.  
  264. if p == "1" then
  265.                 l = tunnelLength()
  266.                 w = tunnelWidth()
  267.                 print("Torch placement? y n:")
  268.                 t = read()
  269.                 digTunnel(l,w,t)
  270.                 print("Job Done")
  271. elseif p == "2" then
  272.                 rows = gridRows()
  273.                 columns = gridColumns()
  274.                 print("Torch placement? y n:")
  275.                 t = read()
  276.                 digGrid(rows,columns,step,t)
  277.                 print("Job Done")
  278. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement