Advertisement
0x6a616d6573

Untitled

May 24th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. local finished = false
  2. local n = 0
  3. local orientation = 0
  4.  
  5. function d()
  6.     return turtle.detect()
  7. end
  8.  
  9. function dd()
  10.     return turtle.detectDown()
  11. end
  12.  
  13. function l()
  14.     turtle.turnLeft()
  15.     orientation = orientation - 90
  16.     if (orientation == -360) then
  17.         orientation = 0
  18.     elseif (orientation == -270) then
  19.         orientation = 90
  20.     end
  21. end
  22.  
  23. function r()
  24.     turtle.turnRight()
  25.     orientation = orientation + 90
  26.     if (orientation == 360) then
  27.         orientation = 0
  28.     elseif (orientation == 270) then
  29.         orientation = -90
  30.     end
  31. end
  32.  
  33. function f()
  34.     turtle.forward()
  35. end
  36.  
  37. function b()
  38.     turtle.back()
  39. end
  40.  
  41. function selectBuildMaterial()
  42.     local foundBuildMaterial = false
  43.     local buildMaterialIndex = 1
  44.     for i = 1, 16 do
  45.         turtle.select(i)
  46.         if (not turtle.refuel(0)) and (not foundBuildMaterial) and (turtle.getItemCount() > 0) then
  47.             foundBuildMaterial = true
  48.             buildMaterialIndex = i
  49.         end
  50.     end
  51.  
  52.     if not foundBuildMaterial then
  53.         finished = true
  54.     else
  55.         turtle.select(buildMaterialIndex)
  56.     end
  57. end
  58.  
  59. function refuel()
  60.     local foundFuel = false
  61.     for i = 1, 16 do
  62.         turtle.select(i)
  63.         if turtle.refuel(0) and (not foundFuel) then
  64.             turtle.refuel(1)
  65.             foundFuel = true
  66.         end
  67.     end
  68.  
  69.     if not foundFuel then
  70.         finished = true
  71.     end
  72.  
  73.     selectBuildMaterial()
  74. end
  75.  
  76. while not finished do
  77.     if (turtle.getFuelLevel() <= 0) then
  78.         refuel()
  79.     end
  80.  
  81.     if (orientation ~= 0) then
  82.  
  83.         if (orientation < 0) then
  84.             r()
  85.             if d() then
  86.                 l()
  87.             else
  88.                 f()
  89.                 if dd() then
  90.                     b()
  91.                     l()
  92.                 else
  93.                     b()
  94.                 end
  95.             end
  96.         elseif (orientation > 0) then
  97.             l()
  98.             if d() then
  99.                 r()
  100.             else
  101.                 f()
  102.                 if dd() then
  103.                     b()
  104.                     r()
  105.                 else
  106.                     b()
  107.                 end
  108.             end
  109.         end
  110.  
  111.     end
  112.  
  113.     if d() then
  114.         r()
  115.         if d() then
  116.             l()
  117.             l()
  118.             if d() then
  119.                 finished = true
  120.             else
  121.                 f()
  122.                 if dd() then
  123.                     finished = true
  124.                 end
  125.             end
  126.         else
  127.             f()
  128.             if dd() then
  129.                 b()
  130.                 l()
  131.                 l()
  132.                 if d() then
  133.                     finished = true
  134.                 else
  135.                     f()
  136.                     if dd() then
  137.                         finished = true
  138.                     end
  139.                 end
  140.             end
  141.         end
  142.     else
  143.  
  144.         f()
  145.  
  146.         if dd() then
  147.             b()
  148.             r()
  149.             if d() then
  150.                 l()
  151.                 l()
  152.                 if d() then
  153.                     finished = true
  154.                 else
  155.                     f()
  156.                     if dd() then
  157.                         finished = true
  158.                     end
  159.                 end
  160.             else
  161.                 f()
  162.                 if dd() then
  163.                     b()
  164.                     l()
  165.                     l()
  166.                     if d() then
  167.                         finished = true
  168.                     else
  169.                         f()
  170.                         if dd() then
  171.                             finished = true
  172.                         end
  173.                     end
  174.                 end
  175.             end
  176.         end
  177.  
  178.     end
  179.  
  180.  
  181.     if (turtle.getItemCount() <= 0) then
  182.         selectBuildMaterial()
  183.     end
  184.  
  185.     turtle.placeDown()
  186.  
  187.     n = n+1
  188.  
  189.     if n>10000 then
  190.         finished = true
  191.     end
  192.  
  193. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement