Advertisement
wolfd

Sponger

Jul 31st, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. -- SPONGER
  2. -- NEEDS TO BE FACING POSITIVE X
  3. sponge_slot = 1
  4. fuel_slot = 2
  5.  
  6. sponge_distance = 6
  7.  
  8. move_counter = 79 -- trigger immediately
  9.  
  10. init_x = 0
  11. init_y = 0
  12. init_z = 0
  13.  
  14. x = init_x
  15. y = init_y
  16. z = init_z
  17.  
  18. print("Enter # of blocks\n")
  19. print("forward\n")
  20. sponge_x = tonumber(io.read())
  21. print("Enter # of blocks\n")
  22. print("vertical\n")
  23. print(" (probably negative)\n")
  24. sponge_y = tonumber(io.read())
  25. print("Enter # of blocks\n")
  26. print("to the right\n")
  27. sponge_z = tonumber(io.read())
  28.  
  29. function sponge_it()
  30.     turtle.dig() -- remove potential block
  31.     turtle.place()
  32.     turtle.dig()
  33. end
  34.  
  35. function turtle_down()
  36.     if turtle.detectDown() then
  37.         return true
  38.     else
  39.         y = y - 1
  40.         refuel_every_eighty()
  41.         turtle.down()
  42.         return false
  43.     end
  44. end
  45.  
  46.  
  47. function refuel_every_eighty()
  48.     move_counter = move_counter + 1
  49.     if move_counter >= 80 then
  50.         move_counter = 0
  51.         if turtle.getItemCount(fuel_slot) <= 1 then -- leave one always
  52.             fuel_slot = fuel_slot + 1
  53.             if fuel_slot >= 17 then
  54.                 exit()
  55.             end
  56.            
  57.         end
  58.         turtle.select(fuel_slot)
  59.         turtle.refuel(1)
  60.         turtle.select(sponge_slot)
  61.     end
  62. end
  63.  
  64. function sponge_y_way()
  65.     local cant_go_down = false
  66.     for i_sponge_y = 1, math.floor(math.abs(sponge_y / sponge_distance)) do
  67.         for move_y = 1, sponge_distance do
  68.             if sponge_y < 0 then
  69.                 cant_go_down = turtle_down()
  70.                 if cant_go_down then break end-- if can't go down any further, go back up (for clearing ocean floors)
  71.             else
  72.                 y = y + 1
  73.                 refuel_every_eighty()
  74.                 turtle.up()
  75.             end
  76.         end
  77.         sponge_it()
  78.         if cant_go_down then break end-- if can't go down any further, go back up (for clearing ocean floors)
  79.     end
  80.  
  81.     for move_y = 1, math.abs(init_y - y) do
  82.         if sponge_y < 0 then
  83.             y = y + 1
  84.             refuel_every_eighty()
  85.             turtle.up()
  86.         else
  87.             y = y - 1
  88.             refuel_every_eighty()
  89.             turtle.down()
  90.         end
  91.     end
  92. end
  93.  
  94. function sponge_x_way()
  95.     if sponge_x < 0 then
  96.         turtle.turnLeft()
  97.         turtle.turnLeft()
  98.     end
  99.  
  100.     for i_sponge_x = 1, math.floor(math.abs(sponge_x / sponge_distance)) do
  101.         sponge_it()
  102.         sponge_y_way()
  103.         for move = 1, sponge_distance do
  104.             refuel_every_eighty()
  105.             turtle.forward()
  106.             if sponge_x < 0 then
  107.                 x = x - 1
  108.             else
  109.                 x = x + 1
  110.             end
  111.         end
  112.     end
  113.  
  114.     sponge_it()
  115.     sponge_y_way()
  116.  
  117.     turtle.turnLeft()
  118.     turtle.turnLeft()
  119.  
  120.     for i = 1, math.abs(init_x - x) do
  121.         refuel_every_eighty()
  122.         turtle.forward()
  123.         if sponge_x < 0 then
  124.             x = x + 1
  125.         else
  126.             x = x - 1
  127.         end
  128.     end
  129.  
  130.     turtle.turnLeft()
  131.     turtle.turnLeft()
  132. end
  133.  
  134.  
  135.  
  136.  
  137. function sponge_x_z_way()
  138.     for move_z_i = 1, math.floor(math.abs(sponge_z / sponge_distance)) do
  139.         sponge_x_way()
  140.         if sponge_z < 0 then
  141.             turtle.turnLeft()
  142.         else
  143.             turtle.turnRight()
  144.         end
  145.  
  146.         for move_z = 1, sponge_distance do
  147.             refuel_every_eighty()
  148.             turtle.forward()
  149.  
  150.             if sponge_z < 0 then
  151.                 z = z - 1
  152.             else
  153.                 z = z + 1
  154.             end
  155.         end
  156.  
  157.         if sponge_z < 0 then
  158.             turtle.turnRight()
  159.         else
  160.             turtle.turnLeft()
  161.         end
  162.         if move_z_i == math.floor(math.abs(sponge_z / sponge_distance)) then
  163.             sponge_x_way()
  164.         end
  165.     end
  166.  
  167.     if sponge_z < 0 then
  168.         turtle.turnLeft()
  169.     else
  170.         turtle.turnRight()
  171.     end
  172.  
  173.     for i = 1, math.abs(init_y - y) do
  174.         refuel_every_eighty()
  175.         turtle.forward()
  176.         if sponge_z < 0 then
  177.             z = z + 1
  178.         else
  179.             z = z - 1
  180.         end
  181.     end
  182.  
  183.     if sponge_z < 0 then
  184.         turtle.turnRight()
  185.     else
  186.         turtle.turnLeft()
  187.     end
  188. end
  189.  
  190. sponge_x_z_way()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement