Advertisement
Dima99

CC mine v2

Aug 15th, 2020 (edited)
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. --[[
  2. Turtle tunnel miner for computer craft.
  3. Anti gravel mode can effectively counter up to 4 blocks
  4. of gravel on top of the tunnel on default settings
  5. (optimal perfomance/stability balance).
  6.  
  7. *updated: 19.01.23
  8. ]]--
  9.  
  10. --settings
  11. local torch_distance = 10
  12. local torches_slot = 1
  13. local delay = 0.7
  14.  
  15. local function dig_step()
  16.     repeat
  17.         turtle.dig()
  18.     until not turtle.detect()
  19.     turtle.forward()
  20.     turtle.digUp()
  21.     sleep(delay)
  22.     turtle.digDown()
  23. end
  24.  
  25. local function get_args()
  26.     term.clear()
  27.     term.setCursorPos(1,1)
  28.     if #args == 0 or tonumber(args[1]) == nil then
  29.         print("Distance not set")
  30.         print("Usage: " .. shell.getRunningProgram() .. " distance [r] [t] [d]")
  31.         print("r - return to start".."\n".."t - disable torches placing".."\n".."d - disable digging".."s - immediate start")
  32.         return false
  33.     end
  34.     for i = 2, #args do
  35.         if args[i] == "r" or args[i] == "R" then
  36.             return_mode = true
  37.             print("Return mode activated")
  38.         end
  39.         if args[i] == "t" or args[i] == "T" then
  40.             torches = false
  41.             print("Torches placing disabled")
  42.         end
  43.         if args[i] == "d" or args[i] == "D" then
  44.             digging = false
  45.             print("Digging disabled")
  46.         end
  47.         if args[i] == "s" or args[i] == "S" then
  48.             autoStart = true
  49.         end
  50.     end
  51.     return true
  52. end
  53.  
  54. local function check_torches_count()
  55.     local need_torches = math.floor(args[1]/(torch_distance+1))
  56.     print(need_torches.." torch(es) required")
  57.     while (turtle.getItemCount(torches_slot) < need_torches) do
  58.         term.setCursorPos(1,4)
  59.         print("                                            ")
  60.         sleep(0.5)
  61.         term.setCursorPos(1,4)
  62.         print("Not enought torches in "..tostring(torches_slot).." slot")
  63.         sleep(0.5)
  64.     end
  65.     return need_torches
  66. end
  67.  
  68. local function place_torch()
  69.     turtle.select(torches_slot)
  70.     while not turtle.down() do
  71.         turtle.digDown()
  72.     end
  73.     if not turtle.detectDown() then
  74.         if torches_slot > 1 then
  75.             turtle.select(1)
  76.         else
  77.             turtle.select(2)
  78.         end
  79.         turtle.placeDown()
  80.     end
  81.     turtle.up()
  82.     turtle.select(torches_slot)
  83.     turtle.placeDown()
  84. end
  85.  
  86. local function writeProgress(cDist, fDist, tDist)
  87.     local left = math.ceil(cDist/fDist*100)
  88.     term.setCursorPos(1, 1)
  89.     term.clear()
  90.     print("Done "..left.."%")
  91.     if tDist then
  92.         term.write("Next torch in "..tDist.." blocks")
  93.     end
  94. end
  95.  
  96. --main
  97. args = { ... }
  98. return_mode = false
  99. torches = true
  100. digging = true
  101. autoStart = false
  102. if not get_args(args) then return end
  103. local needTorches = 0
  104. if torches then
  105.     light_level = torch_distance
  106.     needTorches = check_torches_count()
  107. end
  108. local neededFuel = needTorches * 2 + args[1]
  109. if return_mode then neededFuel = neededFuel * 2 end
  110. print(" ")
  111. term.write("Fuel: "..turtle.getFuelLevel().." / "..neededFuel)
  112. if turtle.getFuelLevel() < neededFuel then
  113.     print("\n\nNot enought fuel.\nProgram will be aborted")
  114.     return nil
  115. else print(" ...OK")
  116. end
  117. if not autoStart then
  118.     print("\nPress <Enter> to start".."\n".."Or hold <Ctrl + T> to abort")
  119.     read()
  120. end
  121. for i = 1, args[1] do
  122.     if digging then
  123.         dig_step()
  124.     else
  125.         turtle.forward()
  126.     end
  127.     if torches then
  128.         if light_level == 0 then
  129.             place_torch()
  130.             light_level = torch_distance
  131.         else
  132.             light_level = light_level - 1
  133.         end
  134.     end
  135.     writeProgress(i, args[1], light_level)
  136. end
  137. if return_mode == true then
  138.     turtle.up()
  139.     for i = 1, args[1] do
  140.         turtle.back()
  141.     end
  142.     turtle.down()
  143. end
  144. term.clear()
  145. term.setCursorPos(1, 1)
  146. print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement