Advertisement
mapokapo

Turtle Miner 2

Mar 24th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.23 KB | None | 0 0
  1. function stripDig()
  2.   for i = 1, 3 do
  3.     turtle.dig()
  4.     if not turtle.forward() then
  5.       while true do
  6.         turtle.dig()
  7.         if turtle.forward() then break end
  8.       end
  9.     end
  10.     turtle.digDown()
  11.   end
  12.   stripIterate(true)
  13. end
  14.  
  15. function stripIterate(bool)
  16.   if bool then
  17.     turtle.turnLeft()
  18.   end
  19.   for i = 1, 5 do
  20.     turtle.dig()
  21.     if i < 5 then
  22.       if not turtle.forward() then
  23.         while true do
  24.           turtle.dig()
  25.           if turtle.forward() then break end
  26.         end
  27.       end
  28.     else
  29.       turtle.turnRight()
  30.       turtle.turnRight()
  31.       for j = 1, i-1 do
  32.         if not turtle.forward() then
  33.           while true do
  34.             turtle.dig()
  35.             if turtle.forward() then break end
  36.           end
  37.         end
  38.       end
  39.       if bool then
  40.         stripIterate(false)
  41.       else
  42.         turtle.turnRight()
  43.       end
  44.     end
  45.   end
  46. end
  47.  
  48. function strip()
  49.   print("How many iterations to dig the tunnel for?")
  50.   -- 1 iteration is 3 blocks long including the block where the turtle is placed
  51.   -- each iteration has a branch on both sides at the 3rd block at head height
  52.   -- Note: The turtle must be placed on the ground, and will not dig a branch on the starting block
  53.   -- Note: Turtle must have torches in selected slot
  54.   local length = tonumber(read())
  55.   turtle.digUp()
  56.   turtle.up()
  57.   for i = 0, length-1 do
  58.     if i % 3 == 0 or i == length then
  59.       turtle.placeDown()
  60.     end
  61.     stripDig()
  62.   end
  63.   turtle.turnRight()
  64.   turtle.turnRight()
  65.   for i = 0, (length*3)-2 do
  66.     turtle.forward()
  67.   end
  68.   turtle.down()
  69.   turtle.digDown()
  70.   turtle.down()
  71.   print("Finished strip mining")
  72. end
  73.  
  74. function stairs()
  75.   print("Enter current Y coordinate value: ")
  76.   top = tonumber(read())
  77.   print("Enter desired Y value above bedrock (0): ")
  78.   bottom = tonumber(read())
  79.   if bottom > top or top > 255 or bottom < 0 then
  80.     term.clear()
  81.     term.setCursorPos(1, 1)
  82.     print("Warning: Incorrect input. Please try again")
  83.     stairs()
  84.   else
  85.     function moveForward()
  86.       if not turtle.forward() then
  87.         while true do
  88.           turtle.dig()
  89.           if turtle.forward() then break end
  90.         end
  91.       end
  92.     end
  93.     term.clear()
  94.     term.setCursorPos(1, 1)
  95.     length = top - bottom
  96.     length = math.ceil(length/2) * 2
  97.     print("Digging from y="..top.." to y="..top-length)
  98.     turtle.digDown()
  99.     turtle.down()
  100.     for i = 1, length/2 do
  101.       if not turtle.detectDown() then
  102.         turtle.select(2)
  103.         turtle.placeDown();
  104.       end
  105.       moveForward()
  106.       turtle.digDown()
  107.       moveForward()
  108.       turtle.dig()
  109.       turtle.digDown()
  110.       turtle.digUp()
  111.       turtle.down()
  112.       turtle.dig()
  113.       turtle.digDown()
  114.       turtle.down()
  115.       turtle.turnRight()
  116.       turtle.turnRight()
  117.       if not turtle.detect() then
  118.         turtle.select(2)
  119.         turtle.place();
  120.       end
  121.       turtle.turnRight()
  122.       turtle.turnRight()
  123.       print(math.floor((100 / (length / (i * 2))) * 100 + 0.5) / 100 .. "%")
  124.       if i-1 % 3 == 0 then
  125.         turtle.select(1)
  126.         if not turtle.placeUp() then
  127.           while true do
  128.             turtle.digUp()
  129.             if turtle.placeUp() then break end
  130.           end
  131.         end
  132.       end
  133.     end
  134.   end
  135.   turtle.dig()
  136.   print("Finished digging stairs")
  137. end
  138.  
  139. programs = {"stairs", "strip", "exit"}
  140.  
  141. function getProg()
  142.   print("Programs: ")
  143.   for k, v in pairs(programs) do
  144.     print(k.." - "..v)
  145.   end
  146.   prog = read()
  147.   if prog == programs[1] and stairs ~= nil then
  148.     term.clear()
  149.     term.setCursorPos(1, 1)
  150.     stairs()
  151.   elseif prog == programs[2] and strip ~= nil then
  152.     term.clear()
  153.     term.setCursorPos(1, 1)
  154.     strip()
  155.   elseif prog == programs[#programs] then
  156.     print("Goodbye")
  157.     term.clear()
  158.     term.setCursorPos(1, 1)
  159.   else
  160.     term.clear()
  161.     term.setCursorPos(1, 1)
  162.     print("Invalid program!")
  163.     getProg()
  164.   end
  165. end
  166.  
  167. function start()
  168.   term.clear()
  169.     term.setCursorPos(1, 1)
  170.   print("Enter password")
  171.   pass = read()
  172.     term.clear()
  173.     term.setCursorPos(1, 1)
  174.   if pass == "leo123" then
  175.     print("Welcome. Type the name of a program to begin.")
  176.     getProg()
  177.   else
  178.     print("Incorrect password!")
  179.     start()
  180.   end
  181. end
  182.  
  183. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement