Advertisement
0x6a616d6573

Untitled

May 27th, 2019
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. local finished = false
  2. local n = 0
  3. local orientation = 0
  4. local lineLength = 21
  5. local waitForMoreBuildMaterial = true
  6.  
  7. function d()
  8.     return turtle.detect()
  9. end
  10.  
  11. function dd()
  12.     return turtle.detectDown()
  13. end
  14.  
  15. function l()
  16.     turtle.turnLeft()
  17.     orientation = orientation - 90
  18.     if (orientation == -360) then
  19.         orientation = 0
  20.     elseif (orientation == -270) then
  21.         orientation = 90
  22.     end
  23. end
  24.  
  25. function r()
  26.     turtle.turnRight()
  27.     orientation = orientation + 90
  28.     if (orientation == 360) then
  29.         orientation = 0
  30.     elseif (orientation == 270) then
  31.         orientation = -90
  32.     end
  33. end
  34.  
  35. function f()
  36.     turtle.forward()
  37. end
  38.  
  39. function b()
  40.     turtle.back()
  41. end
  42.  
  43. function u()
  44.     turtle.up()
  45. end
  46.  
  47. function selectBuildMaterial()
  48.     local foundBuildMaterial = false
  49.     local buildMaterialIndex = 1
  50.     for i = 1, 16 do
  51.         turtle.select(i)
  52.         if (not turtle.refuel(0)) and (not foundBuildMaterial) and (turtle.getItemCount() > 0) then
  53.             foundBuildMaterial = true
  54.             buildMaterialIndex = i
  55.         end
  56.     end
  57.  
  58.     if not foundBuildMaterial then
  59.         if waitForMoreBuildMaterial then
  60.             sleep(10)
  61.             selectBuildMaterial()
  62.         else
  63.             inished = true
  64.         end
  65.     else
  66.         turtle.select(buildMaterialIndex)
  67.     end
  68. end
  69.  
  70. function refuel()
  71.     local foundFuel = false
  72.     for i = 1, 16 do
  73.         turtle.select(i)
  74.         if turtle.refuel(0) and (not foundFuel) then
  75.             turtle.refuel(1)
  76.             foundFuel = true
  77.         end
  78.     end
  79.  
  80.     if not foundFuel then
  81.         finished = true
  82.     end
  83.  
  84.     selectBuildMaterial()
  85. end
  86.  
  87. while not finished do
  88.     if (turtle.getFuelLevel() <= 0) then
  89.         refuel()
  90.     end
  91.  
  92.     if (turtle.getItemCount() <= 0) then
  93.         selectBuildMaterial()
  94.     end
  95.  
  96.     turtle.placeDown()
  97.  
  98.     n = n+1
  99.  
  100.     if (n == lineLength) then
  101.         r()
  102.         r()
  103.         u()
  104.         n = 0
  105.     else
  106.         f()
  107.     end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement