Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. function loadFuel(amount)
  2.   local level = amount
  3.   while (turtle.getFuelLevel() < level) do
  4.     for i = 1,16 do
  5.       turtle.select(i)
  6.       while (turtle.refuel(1)) do
  7.         if (turtle.getFuelLevel() > level) then
  8.           return
  9.         end
  10.       end
  11.     end
  12.     print("More fuel required to continue.")
  13.     print(tostring(turtle.getFuelLevel()) .. " / " ..tostring(level))
  14.     os.sleep(0.5)
  15.    end
  16. end
  17.  
  18. function waitForward()
  19.   loadFuel(1)
  20.   while (not turtle.forward()) do
  21.     print("Obstructed, Halting until clear.")
  22.     os.sleep(0.5)
  23.   end
  24. end
  25.  
  26. function breakForward()
  27.   loadFuel(1)
  28.   while (not turtle.forward()) do
  29.     turtle.dig()
  30.   end
  31. end
  32.  
  33. function turnAround()
  34.   turtle.turnLeft()
  35.   turtle.turnLeft()
  36. end
  37.  
  38. function waitUp()
  39.   loadFuel(1)
  40.   while (not turtle.up()) do
  41.     print("Obstructed, Halting until clear.")
  42.     os.sleep(0.5)
  43.   end
  44. end
  45.  
  46. function breakUp()
  47.   loadFuel(1)
  48.   while (not turtle.up()) do
  49.     turtle.digUp()
  50.   end
  51. end
  52.  
  53. function waitDown()
  54.   loadFuel(1)
  55.   while (not turtle.down()) do
  56.     print("Obstructed, Halting until clear.")
  57.     os.sleep(0.5)
  58.   end
  59. end
  60.  
  61. function breakDown()
  62.   loadFuel(1)
  63.   while (not turtle.down()) do
  64.     turtle.digDown()
  65.   end
  66. end
  67.  
  68. function select()
  69.   for i = 2, 16 do
  70.     if (turtle.getItemCount(i) > 0) then
  71.       turtle.select(i)
  72.       return true    
  73.     end
  74.   end
  75.   return false
  76. end
  77.  
  78. function waitMats()
  79.   while (not select()) do
  80.     print("Waiting for materials.")
  81.     os.sleep(0.5)
  82.   end
  83. end
  84.  
  85. function turn(dir)
  86.   if (dir == 0) then
  87.     turtle.turnLeft()
  88.   else
  89.     turtle.turnRight()
  90.   end
  91. end
  92.  
  93. function line(dist)
  94.   for i = 1,dist do
  95.     waitMats()
  96.     turtle.placeDown()
  97.     if (i < dist) then
  98.       waitForward()
  99.     end  
  100.   end
  101. end
  102.  
  103. function floor(length, width)
  104.   local dir = 0
  105.   for i = 1, width do
  106.     line(length)
  107.     if (i < width) then
  108.       turn(dir)
  109.       breakForward()
  110.       turn(dir)
  111.       dir = (dir + 1) % 2
  112.     end
  113.   end
  114. end
  115.  
  116. function bridge(length,width)
  117.   floor(length,width)
  118.   if (width % 2 == 1) then
  119.     turtle.turnLeft()
  120.     waitForward()
  121.     turtle.turnLeft()
  122.     turtle.up()
  123.     line(length)
  124.     turtle.turnLeft()
  125.     for i = 0, width do
  126.       waitForward()
  127.     end
  128.     turtle.turnLeft()
  129.     line(length)
  130.   else
  131.     turtle.turnRight()
  132.     waitForward()
  133.     turtle.turnRight()
  134.     waitUp()
  135.     line(length)
  136.     turtle.turnRight()
  137.     for i = 0, width do
  138.       waitForward()
  139.     end
  140.     turtle.turnRight()
  141.     line(length)
  142.   end
  143. end
  144.  
  145. function wall(length,height)
  146.   turtle.up()
  147.   for i = 1, height do
  148.     line(length)  
  149.     if (i < height) then
  150.       turtle.turnLeft()
  151.       turtle.turnLeft()
  152.       waitUp()
  153.     end
  154.   end
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement