Advertisement
meza2meza

MezMiner

Jan 27th, 2022 (edited)
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.51 KB | None | 0 0
  1. ---LUA MINECRAFT
  2.  
  3.  
  4.  
  5. function digF()
  6.     -- if not refuel() then
  7.     --  print( "Not enough Fuel" )
  8.     --  returnSupplies()
  9.     -- end
  10.    
  11.     while not turtle.forward() do
  12.         if turtle.detect() then
  13.             if turtle.dig() then
  14.                 -- if not collect() then
  15.                 --  print("full must return")
  16.                 -- end
  17.             else
  18.                 return false
  19.             end
  20.         elseif turtle.attack() then
  21.             -- if not collect() then
  22.             --  print("full must return")
  23.             -- end
  24.         else
  25.             sleep( 0.5 )
  26.         end
  27.     end
  28. end
  29.  
  30. function digD()
  31.     -- if not refuel() then
  32.     --  print( "Not enough Fuel" )
  33.     --  returnSupplies()
  34.     -- end
  35.    
  36.     while not turtle.down() do
  37.         if turtle.detectDown() then
  38.             if turtle.digDown() then
  39.                 -- if not collect() then
  40.                 --  print("full must return")
  41.                 -- end
  42.             else
  43.                 return false
  44.             end
  45.         elseif turtle.attack() then
  46.             -- if not collect() then
  47.             --  print("full must return")
  48.             -- end
  49.         else
  50.             sleep( 0.5 )
  51.         end
  52.     end
  53. end
  54. --Dig Forward
  55. -- sleep?
  56.  
  57. function dropAll()
  58.     -- be sure to be facing chest
  59.     -- check if chest infront
  60.     local success, data = turtle.inspect()
  61.       if success then
  62.       print("Block name: ", data.name)
  63.       print("Block metadata: ", data.metadata)
  64.     end
  65.     if string.sub(data.name, -5) == "chest" then
  66.       for n=1,16 do
  67.           if turtle.getItemCount(n) > 0 then
  68.               turtle.select(n)
  69.               turtle.drop()
  70.           end
  71.       end
  72.     else
  73.     print("no Chest")
  74.     end
  75. end
  76.  
  77. function layeredQuarry()
  78.  print("Starting Layered Quarry")
  79.  --get x level
  80.  print("Input x level:")
  81.  local i = read("*")
  82.  print('You chose, ', i, '!\n')
  83.  -- workout how big first square is at this layer
  84.  -- Get Width and Lenfth (W)
  85.  w = i + 1
  86.  w_orig = i
  87.  d = i
  88.  
  89.  -- define start point check if chest?
  90.  --Check Fuel
  91.  -- Refule if needed
  92.  turtle.refuel()
  93.  -- Ask to go left or right
  94.  print("Swing Left (l) or Right (r) ?:")
  95.  local lr = read("*")
  96.  print('You chose, ', lr, '!\n')
  97.  firstRun = true
  98.  
  99.  
  100.  repeat
  101.     --First layer
  102.     repeat
  103.             print("Moving ",w," spaces.\n")
  104.             for n=1,w do
  105.                 digF()
  106.             end
  107.             if lr == "l" then
  108.                 turtle.turnLeft()
  109.             elseif lr == "r" then
  110.                 turtle.turnRight()
  111.             else
  112.                 print("error 4")
  113.             end
  114.             for n=1,w-1 do
  115.                 digF()
  116.             end
  117.             if lr == "l" then
  118.                 turtle.turnLeft()
  119.             elseif lr == "r" then
  120.                 turtle.turnRight()
  121.             else
  122.                 print("error 4")
  123.             end
  124.             for n=1,w-1 do
  125.                 digF()
  126.             end
  127.             if lr == "l" then
  128.                 turtle.turnLeft()
  129.             elseif lr == "r" then
  130.                 turtle.turnRight()
  131.             else
  132.                 print("error 4")
  133.             end
  134.             for n=1,w-2 do
  135.                 digF()
  136.             end
  137.             if lr == "l" then
  138.                 turtle.turnLeft()
  139.             elseif lr == "r" then
  140.                 turtle.turnRight()
  141.             else
  142.                 print("error 4")
  143.             end
  144.            
  145.             print("Finished section ",w," Moves.\n")
  146.            
  147.             if w == 1 then
  148.             w = 0
  149.             else
  150.             w = w - 2
  151.             end
  152.                
  153.     until w == 0
  154.  
  155.     print("1st Layer completed")
  156.     --Back to base
  157.     if (w_orig % 2 == 0) then
  158.         -- if I is even, half right, hlf down
  159.         turtle.turnRight()
  160.         for n=1, (w_orig * 0.5) do
  161.             digF()
  162.         end
  163.         turtle.turnRight()
  164.         for n=1, (w_orig * 0.5) do
  165.             digF()
  166.         end
  167.         turtle.turnRight()
  168.         turtle.turnRight()
  169.    
  170.     else
  171.     -- iff odd, one accross right, then half right, then half down
  172.     turtle.turnRight()
  173.     digF()
  174.     -- Need to adjust up / down for return --------------------------------------------------------------------
  175.         for n=1, (w_orig * 0.5) do
  176.             digF()
  177.         end
  178.         turtle.turnRight()
  179.         for n=1, (w_orig * 0.5) do
  180.             digF()
  181.         end
  182.         digF()
  183.         --
  184.         dropAll()
  185.         --
  186.         turtle.turnRight()
  187.         turtle.turnRight()
  188.     end
  189.     --move and dig down
  190.     print("checkp 1")
  191.     -- digF()
  192.     if lr == "l" then
  193.         turtle.turnLeft()
  194.     elseif lr == "r" then
  195.         turtle.turnRight()
  196.     else
  197.         print("error 4")
  198.     end
  199.     digF()
  200.     if lr == "l" then
  201.         turtle.turnRight()
  202.     elseif lr == "r" then
  203.         turtle.turnLeft()
  204.     else
  205.         print("error 4")
  206.     end
  207.     digD()
  208.     digF()
  209.     d = d - 1
  210.     --d = 3 -- remove
  211.     w = w_orig - 1
  212.     w_orig = w_orig - 1
  213.    
  214.  until d == 5
  215.  print("completed")
  216. end
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237. print("MezMiner Starting......")
  238.  
  239. print("Fuel: ")
  240. print(turtle.getFuelLevel())
  241. print("")
  242. print("")
  243. x, y, z = 0,0,0
  244. print("")
  245. print("Select option: ")
  246. print("1. Layered Quarry")
  247. print("2. Straight Down")
  248. print("3. Stairway Down")
  249. local i = read("*n")
  250. print('You chose, ', i, '!\n')
  251.  
  252. if i == "1" then
  253.     layeredQuarry()
  254. elseif i == "2" then
  255.     --[ Executes when the boolean expression 2 is true --]
  256.     print("Lets Strigh Downnnn")
  257. elseif i == "3" then
  258.     print("Lets Stairwa")
  259.     --[ Executes when the boolean expression 3 is true --]
  260.  else
  261.     print("No Option?")
  262.     --[ executes when the none of the above condition is true --]
  263.  end
  264.  
  265.  
  266.  
  267. --Get task (Mine, Strip, down, )
  268. --Check If correct type of turtle?
  269. --Check Fuel?
  270.  
  271.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement