MatthewGB

Reactor Builder

Mar 1st, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. size = 49
  2.  
  3. caseslot = 1
  4. controlslot = 9
  5. fuelslot = 15
  6. curslot = "case"
  7.  
  8. blocksneeded = size * size * size + (size-2)*(size-2)*(size-2)
  9.  
  10. print(blocksneeded.." reactor case blocks are required to complete a size "..size.." reactor. Please ensure there is enough!")
  11.  
  12. starttime = os.clock()
  13.  
  14. size = size - 1 --This is just needed.
  15.  
  16. function place2(side)
  17.     gotstuff = false
  18.     while gotstuff == false do
  19.         if curslot == "case" then
  20.             turtle.select(caseslot)
  21.         elseif curslot == "control" then
  22.             turtle.select(controlslot)
  23.         else
  24.             print("NO SUCH ITEM: "..curslot)
  25.         end
  26.         if turtle.getItemCount(turtle.getSelectedSlot()) == 0 then
  27.             if curslot == "case" then
  28.                 caseslot = caseslot + 1
  29.             elseif curslot == "control" then
  30.                 controlslot = controlslot + 1
  31.             end
  32.         else
  33.             gotstuff = true
  34.         end
  35.         if caseslot == 5 then
  36.             caseslot = 1
  37.         end
  38.         if controlslot == 10 then
  39.             controlslot = 5
  40.         end
  41.     end
  42.     if side == "f" then
  43.         turtle.place()
  44.     elseif side == "u" then
  45.         turtle.placeUp()
  46.     else
  47.         turtle.placeDown()
  48.     end
  49. end
  50. function forward()
  51.     if turtle.getFuelLevel() == 0 then
  52.         curslot2 = turtle.getSelectedSlot()
  53.         turtle.select(15)
  54.         turtle.refuel()
  55.         turtle.select(curslot2)
  56.     end
  57.     while not turtle.forward() do
  58.         turtle.dig()
  59.     end
  60. end
  61. function placeUp(height)
  62.     iii = 0
  63.     while iii<height do
  64.         place2()
  65.         turtle.up()
  66.         iii = iii + 1
  67.     end
  68. end
  69. print("Doing floor 1")
  70. i = 0
  71. ii = 0
  72. while ii < size do
  73.     turtle.turnRight()
  74.     i = 0
  75.     while i < size do
  76.         print("Building floor with "..turtle.getFuelLevel().."/"..turtle.getFuelLimit().." fuel left")
  77.         place2()
  78.         forward()
  79.         i = i + 1
  80.     end
  81.     place2()
  82.     i = 0
  83.     turtle.turnRight()
  84.     turtle.turnRight()
  85.     while i < size do
  86.         forward()
  87.         i = i + 1
  88.     end
  89.     turtle.turnRight()
  90.     forward()
  91.     ii = ii + 1
  92. end
  93. turtle.back()
  94. turtle.turnRight()
  95. print("Doing wall 1")
  96. iv = 0
  97. while iv<size do
  98.     placeUp(size)
  99.     turtle.forward()
  100.     v = 0
  101.     while v<size do
  102.         turtle.down()
  103.         v = v + 1
  104.     end
  105.     iv = iv + 1
  106. end
  107. turtle.turnRight()
  108. print("Doing wall 2")
  109. iv = 0
  110. while iv<size do
  111.     placeUp(size)
  112.     turtle.forward()
  113.     v = 0
  114.     while v<size do
  115.         turtle.down()
  116.         v = v + 1
  117.     end
  118.     iv = iv + 1
  119. end
  120. turtle.turnRight()
  121. print("Doing wall 3")
  122. iv = 0
  123. while iv<size do
  124.     placeUp(size)
  125.     turtle.forward()
  126.     v = 0
  127.     while v<size do
  128.         turtle.down()
  129.         v = v + 1
  130.     end
  131.     iv = iv + 1
  132. end
  133. turtle.turnRight()
  134. print("Doing wall 4")
  135. iv = 0
  136. while iv<size do
  137.     placeUp(size)
  138.     turtle.forward()
  139.     v = 0
  140.     while v<size do
  141.         turtle.down()
  142.         v = v + 1
  143.     end
  144.     iv = iv + 1
  145. end
  146. turtle.turnRight()
  147. turtle.up()
  148. print("Doing floor 2")
  149. i = 0
  150. ii = 0
  151. controlrod = true
  152. while ii <= size do
  153.     turtle.turnRight()
  154.     i = 0
  155.     while i < size do
  156.         print("Building floor with "..turtle.getFuelLevel().."/"..turtle.getFuelLimit().." fuel left")
  157.         print("Completed: "..i.." and "..ii.." with cr toggle on: "..controlrod)
  158.         if i ~= 0 and i ~= size-1 and ii ~= 0 and ii ~= size-1 then
  159.             if controlrod then
  160.                 curslot = "control"
  161.                 controlrod = not controlrod
  162.             else
  163.                 curslot = "case"
  164.                 controlrod = not controlrod
  165.             end
  166.         else
  167.             curslot = "case"
  168.         end
  169.         place2()
  170.         forward()
  171.         i = i + 1
  172.     end
  173.     place2()
  174.     i = 0
  175.     turtle.turnRight()
  176.     turtle.turnRight()
  177.     while i < size do
  178.         forward()
  179.         i = i + 1
  180.     end
  181.     turtle.turnRight()
  182.     forward()
  183.     ii = ii + 1
  184. end
  185.  
  186. print("A size "..size.." reactor was completed in "..(os.clock()-starttime).." seconds")
Advertisement
Add Comment
Please, Sign In to add comment