Advertisement
marko_rus

Miner [CC]

Oct 7th, 2021 (edited)
1,285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.98 KB | None | 0 0
  1. --09.10.2021, mining software 2.1_CC.
  2.  
  3. --переменные
  4. local mode = 11
  5. local button = 11
  6. local call = ""
  7. local comeback = 2
  8. local t = turtle
  9. -- проверка топлива
  10.  
  11. function checkFuel(dist)
  12. local fuel = t.getFuelLevel()
  13. return fuel-dist
  14. end
  15.  
  16. function readKey(from, to)
  17. local k = -1
  18. while k < from or k > to do --ожидание выбора
  19.     while call ~= "key" do
  20.     call, k = os.pullEvent()
  21.     end
  22. end
  23.  
  24. while call ~= "key_up" do
  25.     call, _ = os.pullEvent()
  26. end
  27.  
  28. return k
  29. end
  30. -- основной цикл
  31. print (" _____________________________________")
  32. print ("| Mining software for CC      v 2.1.0 |")
  33. print ("|    By marko_rus (marko_ru)          |")
  34. print ("|   (C) MCInc  All rights reserved!   |")
  35. print ("|_____________________________________|")
  36.  
  37. print ("Should the robot come back? \n1 - no \n2 - yes")
  38. comeback = readKey(49, 50)-48
  39.  
  40. print ("Select mode: \n1 - tunnel \n2 - ladder \n3 - room (In developement!!!)")
  41.  
  42.     mode = readKey(49, 51)
  43.     ----------------------------------------------------------------------------------
  44.     if mode == 49 then --тоннель
  45.         print("1 - 1x1 \n2 - 1x2 \n3 - 3x3")
  46.        
  47.             button = readKey(49, 51)
  48.            
  49.        
  50.             write("Input distance: ")
  51.             local d = read()
  52.             local x = 0
  53.             d = d+0
  54.            
  55.             if checkFuel(d*comeback) >= 0 and button ~= 51 then
  56.            
  57.         if button == 49 then --1x1
  58.             while x < d do
  59.                 t.dig()
  60.                 t.forward()
  61.                 x = x + 1
  62.             end
  63.         end
  64.        
  65.         if button == 50 then --1x2
  66.             while x < d do
  67.                 t.dig()
  68.                 t.forward()
  69.                 t.digUp()
  70.                 x = x + 1
  71.             end
  72.         end
  73.         else if button ~= 51 then print("Not enough fuel. Need " .. checkFuel(d*comeback) .. " more to go. Please refuel.") end end
  74.        
  75.        
  76.         if button == 51 and checkFuel(d*3*comeback) >= 0 then --3x3
  77.             local bool = true
  78.             while x < d do
  79.                 t.dig()
  80.                 t.forward()
  81.                 t.digDown()
  82.                 t.digUp()
  83.                 if bool then t.turnLeft()
  84.                 else t.turnRight() end
  85.                 t.dig()
  86.                 t.forward()
  87.                 t.digDown()
  88.                 t.digUp()
  89.                 t.dig()
  90.                 t.forward()
  91.                 t.digDown()
  92.                 t.digUp()
  93.                 if bool then t.turnRight()
  94.                 else t.turnLeft() end
  95.                
  96.                 x = x + 1
  97.                 if bool then bool = false
  98.                 else bool = true end
  99.             end
  100.         else if button == 51 then print("Not enough fuel. Need " .. checkFuel(d*3*comeback) .. " more to go. Please refuel.") end end
  101.        
  102.         if comeback == 2 then
  103.         t.turnRight()
  104.         t.turnRight()
  105.         x = 0
  106.            
  107.         while x < d do
  108.             t.dig()
  109.             t.forward()
  110.             x = x + 1
  111.         end
  112.         end
  113.     end
  114.     ----------------------------------------------------------------------------------
  115.     if mode == 50 then --лестница
  116.         print("Input distance: ")
  117.         local d = read()
  118.        
  119.         if checkFuel(d*comeback) >= 0 then
  120.         local x = 0
  121.         d = d+0
  122.        
  123.         while x < d do
  124.             t.dig()
  125.             t.forward()
  126.             t.digUp()
  127.             t.digDown()
  128.             t.down()
  129.             x = x + 1
  130.         end
  131.         x = 0
  132.        
  133.         if comeback == 2 then
  134.         t.turnRight()
  135.         t.turnRight()
  136.        
  137.         while x < d do
  138.             t.up()
  139.             t.forward()
  140.             x = x + 1
  141.         end
  142.         end
  143.        
  144.         else print("Not enough fuel. Need " .. checkFuel(d*2*comeback) .. " more to go. Please refuel.")
  145.     end
  146.     end
  147.     ----------------------------------------------------------------------------------
  148.     if mode == 51 then --комната
  149.         print("Input x: ")
  150.         local x = read() - 1
  151.         print("Input y: ")
  152.         local y = read() + 0
  153.         print("Input z: ")
  154.         local z = read() - 1
  155.        
  156.         local rX =0
  157.         local rY =0
  158.         local rZ =0
  159.         -- передвижение по Z
  160.        
  161.         while true do
  162.         -- передвижение по X
  163.         if rX == 0 then
  164.             while rX < x do
  165.                 t.dig()
  166.                 t.forward()
  167.                 rX = rX + 1
  168.             end
  169.         else
  170.             t.turnLeft()
  171.             t.turnLeft()
  172.                 while rX > 0 do
  173.                     t.dig()
  174.                     t.forward()
  175.                     rX = rX - 1
  176.                 end
  177.             t.turnLeft()
  178.             t.turnLeft()
  179.         end
  180.        
  181.         -- передвижение по Y
  182.         if rY + 1 < y and rZ % 2 == 0 then
  183.             t.digUp()
  184.             t.up()
  185.             rY = rY + 1
  186.         else if rY - 1> 0 and rZ % 2 == 1 and rz ~= 0 then
  187.             t.digDown()
  188.             t.Down()
  189.             rY = rY - 1
  190.         else
  191.         break
  192.         end
  193.         end
  194.         end
  195.     end
  196.     ----------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement