Advertisement
Guest User

stripmine

a guest
Oct 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | None | 0 0
  1. modem = peripheral.wrap("right")
  2.  
  3. function cycle(length)
  4.     turtle.turnLeft()
  5.     digBranch(length)
  6.     turtle.turnRight()
  7.     turtle.turnRight()
  8.     digBranch(length)
  9.     turtle.turnLeft()
  10.     seekOre()
  11.     storeItems()
  12.     forward()
  13.     forward()
  14.     forward()
  15. end
  16.  
  17. function digBranch(length)
  18.     for i = 1, length do
  19.         digOnce()
  20.     end
  21.     for i = 1, length do
  22.         back()
  23.     end
  24. end
  25.  
  26. function digOnce()
  27.     forward()
  28.     seekOre()
  29. end
  30.  
  31. function seekOre()
  32.     local r = 0
  33.     turtle.select(1)
  34.     tryStoreItems()
  35.     if turtle.detectUp() then
  36.         if not compareUp() then
  37.             up()
  38.             seekOre()
  39.             down()
  40.         end
  41.     end
  42.     if turtle.detectDown() then
  43.         if not compareDown() then
  44.             down()
  45.             seekOre()
  46.             up()
  47.         end
  48.     end
  49.     for i = 1, 4 do
  50.         turtle.turnRight()
  51.         if turtle.detect() and not compare() then
  52.             forward()
  53.             seekOre()
  54.             back()
  55.         end
  56.     end
  57. end
  58.  
  59. function compareUp()
  60.     matches = false
  61.     turtle.select(1)
  62.     matches = matches or turtle.compareUp()
  63.     turtle.select(2)
  64.     matches = matches or turtle.compareUp()
  65.     turtle.select(3)
  66.     matches = matches or turtle.compareUp()
  67.     return matches
  68. end
  69.  
  70. function compareDown()
  71.     matches = false
  72.     turtle.select(1)
  73.     matches = matches or turtle.compareDown()
  74.     turtle.select(2)
  75.     matches = matches or turtle.compareDown()
  76.     turtle.select(3)
  77.     matches = matches or turtle.compareDown()
  78.     return matches
  79. end
  80.  
  81. function compare()
  82.     matches = false
  83.     turtle.select(1)
  84.     matches = matches or turtle.compare()
  85.     turtle.select(2)
  86.     matches = matches or turtle.compare()
  87.     turtle.select(3)
  88.     matches = matches or turtle.compare()
  89.     return matches
  90. end
  91.  
  92. function tryStoreItems()
  93.     store = false
  94.     for i = 4, 15 do
  95.         if turtle.getItemSpace(i) < 4 then
  96.             store = true
  97.         end
  98.     end
  99.     if store then
  100.         storeItems()
  101.     end
  102. end
  103.  
  104. function storeItems()
  105.     turtle.digUp()
  106.     turtle.select(16)
  107.     turtle.placeUp()
  108.     for i = 4, 15 do
  109.         turtle.select(i)
  110.         turtle.dropUp(turtle.getItemCount())
  111.     end
  112.     turtle.select(16)
  113.     turtle.digUp()
  114. end
  115.  
  116. function dig()
  117.     while true do
  118.         turtle.dig()
  119.         os.sleep(0.2)
  120.         if not turtle.detect() then
  121.             break
  122.         end
  123.     end
  124. end
  125.  
  126. function digUp()
  127.     while true do
  128.         turtle.digUp()
  129.         os.sleep(0.2)
  130.         if not turtle.detectUp() then
  131.             break
  132.         end
  133.     end
  134. end
  135.  
  136. function forward()
  137.     while true do
  138.         if turtle.forward() then
  139.             return
  140.         else
  141.             print"obstructed in: forward"
  142.             dig()
  143.             turtle.attack()
  144.             turtle.attack()
  145.             turtle.attack()
  146.         end
  147.     end
  148. end
  149.  
  150. function back()
  151.     while true do
  152.         if turtle.back() then
  153.             return
  154.         else
  155.             print"obstructed in: back"
  156.             turtle.turnRight()
  157.             turtle.turnRight()
  158.             dig()
  159.             kill()
  160.             turtle.turnRight()
  161.             turtle.turnRight()
  162.         end
  163.     end
  164. end
  165.  
  166. function kill()
  167.     loop = true
  168.     while loop do
  169.         loop = turtle.attack()
  170.         if loop then
  171.             os.sleep(1)
  172.         end
  173.     end
  174. end
  175.  
  176. function killUp()
  177.     loop = true
  178.     while loop do
  179.         loop = turtle.attackUp()
  180.         if loop then
  181.             os.sleep(1)
  182.         end
  183.     end
  184. end
  185.  
  186. function killDown()
  187.     loop = true
  188.     while loop do
  189.         loop = turtle.attackDown()
  190.         if loop then
  191.             os.sleep(1)
  192.         end
  193.     end
  194. end
  195.  
  196. function up()
  197.     while true do
  198.         if turtle.up() then
  199.             return
  200.         else
  201.             print"obstructed in: up"
  202.             digUp()
  203.             killUp()
  204.         end
  205.     end
  206. end
  207.  
  208. function down()
  209.     while true do
  210.         if turtle.down() then
  211.             return
  212.         else
  213.             print"obstructed in: down"
  214.             turtle.digDown()
  215.             killDown()
  216.         end
  217.     end
  218. end
  219.  
  220. function grid(depth, side, length, layers)
  221.     layers = layers or 1
  222.     for l = 1, layers do
  223.         for s = 1, side do
  224.             for i = 1, depth do
  225.                 cycle(length)
  226.             end
  227.             print"waiting..."
  228.             print"ok."
  229.             for i = 1, depth do
  230.                 back()
  231.                 back()
  232.                 back()
  233.             end
  234.             print"waiting..."
  235.             print"ok."
  236.             if s < side then
  237.                 turtle.turnRight()
  238.                 for i = 1, length * 2 + 1 do
  239.                     forward()
  240.                 end
  241.                 turtle.turnLeft()
  242.             end
  243.         end
  244.         turtle.turnLeft()
  245.         for s = 2, side do
  246.             for i = 1, length * 2 + 1 do
  247.                 forward()
  248.             end
  249.         end
  250.         turtle.turnRight()
  251.         if l < layers then
  252.             up()
  253.             up()
  254.         end
  255.     end
  256.     for i = 2, layers do
  257.         down()
  258.         down()
  259.     end
  260. end
  261.  
  262. grid(2, 1, 4, 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement