Advertisement
JMANN2400

CircleMakerV2[NoFuel]

Aug 20th, 2017
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1.  
  2.  
  3.  
  4. x = nil
  5.  
  6. y = nil
  7.  
  8. z = 0
  9.  
  10. slot = 1
  11.  
  12. function selectSlot()
  13.     if turtle.getItemCount(slot) == 0 and slot < 16 then
  14.         slot = slot + 1
  15.     elseif turtle.getItemCount(slot) == 0 and slot == 16 then
  16.         slot = 1
  17.     end
  18.     turtle.select(slot)
  19. end
  20.  
  21. function digHole()
  22.     while z < h do
  23.         turtle.digDown()
  24.         turtle.down()
  25.         z = z + 1
  26.     end
  27.     while z > 0 do
  28.         turtle.digUp()
  29.         turtle.up()
  30.         z = z - 1
  31.     end
  32. end
  33.  
  34. function testRange()
  35.     if math.sqrt(math.pow(x, 2) + math.pow(y, 2)) <= r then
  36.         return true
  37.     else
  38.         return false
  39.     end
  40. end
  41.  
  42. function testRangeInverse()
  43.     if math.sqrt(math.pow(x, 2) + math.pow(y, 2)) >= r-1 then
  44.         return true
  45.     else
  46.         return false
  47.     end
  48. end
  49.  
  50. function subSearch()
  51.     while y <= r do
  52.         if testRange() then
  53.             digHole()
  54.         end
  55.         while x < r do
  56.             turtle.dig()
  57.             turtle.forward()
  58.             x = x + 1
  59.             if testRange() then
  60.                 digHole()
  61.             end
  62.         end
  63.         turtle.turnRight()
  64.         turtle.dig()
  65.         turtle.forward()
  66.         y = y + 1
  67.         if testRange() then
  68.             digHole()
  69.         end
  70.         turtle.turnRight()
  71.         while x > -r do
  72.             turtle.dig()
  73.             turtle.forward()
  74.             x = x - 1
  75.             if testRange() then
  76.                 digHole()
  77.             end
  78.         end
  79.         turtle.turnLeft()
  80.         turtle.dig()
  81.         turtle.forward()
  82.         y = y + 1
  83.         if testRange() then
  84.             digHole()
  85.         end
  86.         turtle.turnLeft()
  87.     end
  88. end
  89.  
  90. function addSearch()
  91.     while y <= r do
  92.         if testRange() and testRangeInverse() then
  93.             turtle.digDown()
  94.             selectSlot()
  95.             turtle.placeDown()
  96.         end
  97.         while x < r do
  98.             turtle.dig()
  99.             turtle.forward()
  100.             x = x + 1
  101.             if testRange() then
  102.                 turtle.digDown()
  103.                 selectSlot()
  104.                 turtle.placeDown()
  105.             end
  106.         end
  107.         turtle.turnRight()
  108.         turtle.dig()
  109.         turtle.forward()
  110.         y = y + 1
  111.         if testRange() then
  112.             turtle.digDown()
  113.             selectSlot()
  114.             turtle.placeDown()
  115.         end
  116.         turtle.turnRight()
  117.         while x > -r do
  118.             turtle.dig()
  119.             turtle.forward()
  120.             x = x - 1
  121.             if testRange() then
  122.                 turtle.digDown()
  123.                 selectSlot()
  124.                 turtle.placeDown()
  125.             end
  126.         end
  127.         turtle.turnLeft()
  128.         turtle.dig()
  129.         turtle.forward()
  130.         y = y + 1
  131.         if testRange() then
  132.             turtle.digDown()
  133.             selectSlot()
  134.             turtle.placeDown()
  135.         end
  136.         turtle.turnLeft()
  137.     end
  138. end
  139.  
  140.  
  141.  
  142. print("+-------------------------------------+")
  143. print("| Circle Miner                        |")
  144. print("+-------------------------------------+")
  145.  
  146. print("+-------------------------------------+")
  147.  
  148. print("+-------------------------------------+")
  149. read()
  150. print("+-------------------------------------+")
  151. print("| Radius = ?                          |")
  152. print("+-------------------------------------+")
  153. r = tonumber(read())
  154. print("+-------------------------------------+")
  155. print("| Mode = ?                            |")
  156. print("+-------------------------------------+")
  157. mode = tostring(read())
  158.  
  159. x = -r
  160.  
  161. y = -r
  162.  
  163. if mode == "sub" then
  164.     print("+-------------------------------------+")
  165.     print("| Height = ?                          |")
  166.     print("+-------------------------------------+")
  167.     h = tonumber(read())
  168.     subSearch()
  169. end
  170.  
  171.  
  172.  
  173. if mode == "add" then
  174.     addSearch()
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement