Advertisement
0x6a616d6573

Untitled

May 24th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 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.     f()
  82.  
  83.     if dd() then
  84.         b()
  85.         r()
  86.         f()
  87.     end
  88.  
  89.  
  90.     if (turtle.getItemCount() <= 0) then
  91.         selectBuildMaterial()
  92.     end
  93.  
  94.     turtle.placeDown()
  95.  
  96.     n = n+1
  97.  
  98.     if n>10000 then
  99.         finished = true
  100.     end
  101.  
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement