Advertisement
Guest User

mine_v5.lua

a guest
Apr 4th, 2020
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. --digs 2x2 with 3d search
  2.  
  3. --globals
  4. local input = {...}
  5. DISTANCE = input[1]
  6. moves = {}
  7. index = 1
  8. DIR = 1
  9. M_vectors = {3, 4, 1, 2, 6, 5}
  10.  
  11. --main functions
  12.  
  13. function tunnel()
  14.     turtle.dig()
  15.     dig()
  16.     turtle.forward()
  17.     inspect_d(1)
  18.     change_d('left')
  19.     turtle.dig()
  20.     dig()
  21.     turtle.forward()
  22.     inspect_d(1)
  23.     inspect_d(2)
  24.     turtle.digUp()
  25.     digUp()
  26.     turtle.up()
  27.     inspect_d(2)
  28.     inspect_d(3)
  29.     change_d('right')
  30.     change_d('right')
  31.     turtle.dig()
  32.     dig()
  33.     turtle.forward()
  34.     inspect_d(3)
  35.     inspect_d(2)
  36.     turtle.down()
  37.     inspect_d(2)
  38.     change_d('left')
  39. end
  40.  
  41. function dig()
  42.     while turtle.detect() == true do
  43.         turtle.dig()
  44.     end
  45. end
  46.  
  47. function digUp()
  48.     while turtle.detectUp() == true do
  49.         turtle.digUp()
  50.     end
  51. end
  52.  
  53. function check(dir)
  54.     local found = false
  55.     if dir == 1 then
  56.         is_block, data = turtle.inspectDown()
  57.     elseif dir == 2 then
  58.         is_block, data = turtle.inspect()
  59.     elseif dir == 3 then
  60.         is_block, data = turtle.inspectUp()
  61.     end
  62.     if is_block and data.name == 'minecraft:diamond_ore' then
  63.         found = true
  64.     end
  65.     return found
  66. end
  67.  
  68. function change_d(dir)
  69.     if dir == 'left' then
  70.         turtle.turnLeft()
  71.         if DIR == 1 then
  72.             DIR = 4
  73.         else
  74.             DIR = DIR -1
  75.         end
  76.     elseif dir == 'right' then
  77.         turtle.turnRight()
  78.         if DIR == 4 then
  79.             DIR = 1
  80.         else
  81.             DIR = DIR + 1
  82.         end
  83.     end
  84. end
  85.  
  86. function inspect_base(dir)
  87.     local success = check(dir)
  88.     if success and dir == 2 then
  89.         turtle.dig()
  90.         turtle.forward()
  91.         moves[index] = DIR
  92.         index = index + 1
  93.     elseif success and dir == 1 then
  94.         turtle.digDown()
  95.         turtle.down()
  96.         moves[index] = 5
  97.         index = index + 1
  98.     elseif success and dir == 3 then
  99.         turtle.digUp()
  100.         turtle.up()
  101.         moves[index] = 6
  102.         index = index + 1
  103.     end
  104.     return success
  105. end
  106.  
  107. function inspect_loop()
  108.     i = 1
  109.     j = 2
  110.     while moves[1] ~= nil do
  111.         local found = inspect_base(j)
  112.         if not found and j == 2 then
  113.             change_d('right')
  114.             i = i + 1
  115.             if i == 5 then
  116.                 j = 1
  117.             end
  118.         elseif not found and j == 1 then
  119.             j = 3
  120.         elseif not found and j == 3 then
  121.             reverse()
  122.             i = 1
  123.             j = 2
  124.         else
  125.             i = 1
  126.             j = 2
  127.         end
  128.     end
  129. end
  130.  
  131. function turn(goal)
  132.     while DIR ~= goal do
  133.         change_d('right')
  134.     end
  135. end
  136.  
  137. function reverse()
  138.     index = index - 1
  139.     i = moves[index]
  140.     goal = M_vectors[i]
  141.     if goal < 5 then
  142.         turn(goal)
  143.         turtle.forward()
  144.         moves[index] = nil
  145.     else
  146.         if goal == 5 then
  147.             turtle.down()
  148.             moves[index] = nil
  149.         elseif goal == 6 then
  150.             turtle.up()
  151.             moves[index] = nil
  152.         end
  153.     end
  154. end
  155.  
  156. function inspect_d(dir)
  157.     local current_d = DIR
  158.     local found = inspect_base(dir)
  159.     if found then
  160.         inspect_loop()
  161.         turn(current_d)
  162.     end
  163. end
  164.  
  165. --aux functions
  166.  
  167. function refuel()
  168.     if turtle.getFuelLevel() < 80 then
  169.         turtle.select(1)
  170.         turtle.refuel(1)
  171.     end
  172. end
  173.  
  174. function eject()
  175.     for i = 1, 16 do
  176.         turtle.select(i)
  177.         local data = turtle.getItemDetail()
  178.         if data ~= nil and data.name == 'minecraft:cobblestone' then
  179.             turtle.drop()
  180.         end
  181.     end
  182. end
  183.  
  184. --main
  185.  
  186. function main()
  187.     refuel()
  188.     for i = 1, DISTANCE do
  189.         tunnel()
  190.         if (i % 10) == 0 then
  191.             refuel()
  192.             eject()
  193.         end
  194.         print(i)
  195.     end
  196.     turtle.turnRight()
  197.     turtle.turnRight()
  198.     eject()
  199.     for i = 1, DISTANCE do
  200.         turtle.forward()
  201.     end
  202. end
  203.  
  204. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement