Advertisement
UnicorNora

ComputerCraft mining script 1.6.4

Sep 6th, 2023 (edited)
1,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.45 KB | None | 0 0
  1. --[[
  2. Version
  3.   0.07 1/2/2015 1:41 PM
  4. Changelog
  5.   0.01 - Starting Of Rewriting
  6.   0.02 - More Writing
  7.   0.03 - Adding Fuel Code
  8.   0.04 - Small but many program error fixed
  9.   0.05 - Fully Test
  10.   0.06 - Fixing Minor Bug when add 3 to deep because firstdig had no 3 add to deepcount
  11.   0.07 - Fixing High Error
  12. --]]
  13.  
  14. -- Local Variables
  15. -- Starting
  16. local wide = 0
  17. local wideCount = 0
  18. local long = 0
  19. local longCount = 0
  20. local deep = 0
  21. local deepCount = 0
  22. local totalBlocks = 0
  23. local coalNeeded = 0
  24. local corrent = n
  25. -- Inventory This Will Check At Start Code
  26. local chest = 0
  27. local fuelCount = 0
  28. local fuelCount1 = 0
  29. local noFuelNeed = 0 -- if Config has fuel no need on
  30. local error = 0 -- Error Code
  31. local reCheck = 0 -- Recheck Code
  32. -- Others
  33. local totalBlocks = 0
  34. local totalBlockDone = 0 -- How many Block Mined
  35. local LSorWS = 0 -- Go Left or Go Right This is for Wide Code
  36. local ALorAR = 0 -- align left Or align Right
  37. local processRaw = 0
  38. local process = 0
  39. local enderChest = 0 -- TODO
  40. local blockUp = 0 -- Fixing to Chest Probleem and moving probleem
  41. local processRaw = 0
  42. local process = 0
  43.  
  44. -- Checking
  45. local function check()
  46.     if noFuelNeed == 0 then
  47.         if fuelCount == 0 then
  48.             print("Turtle has no fuel")
  49.             print("Put fuel in Second and Thrid slot")
  50.             error = 1
  51.         else
  52.             print("Turtle has Fuel")
  53.         end
  54.         if fuelCount1 == 0 then
  55.             print("Turtle has no extra fuel but if is short job it okey")
  56.         end
  57.     end
  58.     if chest == 0 then
  59.         print("No chest in Turtle")
  60.         print("Put chest in 1 slot")
  61.         error = 1
  62.     else
  63.         print("Turtle has chest")
  64.     end
  65.     if error == 1 then
  66.         print("Items are missing please try again")
  67.         print("Turtle will recheck in 8 sec")
  68.     end
  69. end
  70.  
  71. -- Recheck if user forget something turtle will check after 6 sec
  72. local function reCheck()
  73.     chest = turtle.getItemCount(1)
  74.     fuelCount = turtle.getItemCount(2)
  75.     fuelCount1 = turtle.getItemCount(3)
  76.     error = 0
  77. end
  78.  
  79. local function chestDump()
  80.     if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  81.     repeat -- The Fix to Gravel Chest Bug. It check if gravel above then it dig till it gone
  82.         turtle.digUp()
  83.         sleep(0.6)
  84.         if turtle.detectUp() then
  85.             turtle.digUp()
  86.             blockUp = 1
  87.         else
  88.             blockUp = 0
  89.         end
  90.     until blockUp == 0
  91.     turtle.select(1)
  92.     turtle.placeUp()
  93.     chest = chest - 1
  94.     for slot = 4, 16 do
  95.         turtle.select(slot)
  96.         sleep(0.6) -- Small fix for slow pc because i had people problem with this
  97.         turtle.dropUp()
  98.     end
  99.     turtle.select(1)
  100.     turtle.digUp()
  101.     turtle.select(4)
  102.     if Chest == 0 then
  103.         print("Out Of Chest")
  104.         os.shutdown()
  105.     end
  106.     end
  107. end
  108.  
  109. -- Refuel
  110. local function refuel()
  111.     if noFuelNeed == 0 then
  112.         repeat
  113.             if turtle.getFuelLevel() < 160 then
  114.                 if fuelCount > 0 then
  115.                     turtle.select(2)
  116.                     turtle.refuel(1)
  117.                     fuelCount = fuelCount - 1
  118.                 elseif fuelCount1 > 0 then
  119.                     turtle.select(3)
  120.                     turtle.refuel(1)
  121.                     fuelCount1 = fuelCount1 - 1
  122.                 else
  123.                     print("out of fuel")
  124.                     os.shutdown()
  125.                 end
  126.             end
  127.         until turtle.getFuelLevel() >= 160
  128.     end
  129. end
  130.  
  131. local function mineLong()
  132.     if turtle.detect() then
  133.         turtle.dig()
  134.     end
  135.     if turtle.forward() then
  136.         longCount = longCount + 1
  137.     else
  138.         repeat
  139.             turtle.dig()
  140.             sleep(0.6)
  141.             if turtle.forward() then
  142.                 blockUp = 0
  143.             else
  144.                 blockUp = 1
  145.             end
  146.         until blockUp == 0
  147.         longCount = longCount + 1
  148.         print(totalBlocks - totalBlockDone)
  149.     end
  150.     if turtle.detectUp() then
  151.         turtle.digUp()
  152.     end
  153.     if turtle.detectDown() then
  154.         turtle.digDown()
  155.     end
  156.     totalBlockDone = totalBlockDone + 3
  157. end
  158.  
  159. local function wideMineLeft() -- TODO
  160.     turtle.turnLeft()
  161.     if turtle.detect() then
  162.         turtle.dig()
  163.         sleep(0.6) -- Minor bug fix if there is gravel
  164.     end
  165.     if turtle.forward() then
  166.         --notting
  167.     else
  168.         repeat
  169.             turtle.dig()
  170.             sleep(0.6)
  171.             if turtle.forward() then
  172.                 blockUp = 0
  173.             else
  174.                 blockUp = 1
  175.             end
  176.         until blockUp == 0
  177.     end
  178.     if turtle.detectUp() then
  179.         turtle.digUp()
  180.     end
  181.     if turtle.detectDown() then
  182.         turtle.digDown()
  183.     end
  184.     turtle.turnLeft()
  185.     LSorWS = 0
  186.     longCount = 0
  187.     wideCount = wideCount + 1
  188.     totalBlockDone = totalBlockDone + 3
  189.     end
  190.  
  191. local function wideMineRight() -- TODO
  192.     turtle.turnRight()
  193.     if turtle.detect() then
  194.         turtle.dig()
  195.         sleep(0.6)
  196.     end
  197.     if turtle.forward() then
  198.         --Notting
  199.     else
  200.         repeat
  201.             turtle.dig()
  202.             sleep(0.6)
  203.             if turtle.forward() then
  204.                 blockUp = 0
  205.             else
  206.                 blockUp = 1
  207.             end
  208.         until blockUp == 0
  209.     end
  210.     if turtle.detectUp() then
  211.         turtle.digUp()
  212.     end
  213.     if turtle.detectDown() then
  214.         turtle.digDown()
  215.     end
  216.     turtle.turnRight()
  217.     LSorWS = 1
  218.     longCount = 0
  219.     wideCount = wideCount + 1
  220.     totalBlockDone = totalBlockDone + 3
  221. end
  222.  
  223. local function deepMine()
  224.     turtle.digDown()
  225.     turtle.down()
  226.     turtle.digDown()
  227.     turtle.down()
  228.     turtle.digDown()
  229.     turtle.down()
  230.     turtle.digDown()
  231.     turtle.turnRight()
  232.     turtle.turnRight()
  233.     wideCount = 0
  234.     longCount = 0
  235.     deepCount = deepCount + 3
  236.     totalBlockDone = totalBlockDone + 3
  237. end
  238.  
  239. local function main()
  240.     repeat --Repeat for each level
  241.         mineLong()
  242.         refuel()
  243.         chestDump()
  244.         if longCount == long then
  245.             if wideCount ~= wide then
  246.                 process = totalBlockDone / totalBlocks * 100
  247.                 processRaw = totalBlocks - totalBlockDone
  248.                 print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  249.                 print("TotalBlocks Still Need To Dig Is " .. processRaw)
  250.                 if LSorWS == 0 then
  251.                     wideMineRight()
  252.                 else
  253.                     wideMineLeft()
  254.                 end
  255.             elseif wideCount >= wide then
  256.                     deepMine()
  257.             end
  258.         end
  259.     until deepCount >= deep
  260.     print("turtle is Done")
  261. end
  262.  
  263. local function firstDig()
  264.     turtle.digDown()
  265.     turtle.down()
  266.     turtle.digDown()
  267.     turtle.down()
  268.     turtle.digDown()
  269.     wideCount = 0
  270.     longCount = 0
  271.     totalBlockDone = totalBlockDone + 3
  272. end
  273.  
  274. local function start()
  275.     print("Welcome To Excavation Turtle Program")
  276.     print("Slot 1: Chest, Slot 2: Fuel, Slot 3: Fuel")
  277.     print("Note: If now put item in then it say error just wait it fix it self")
  278.     print("How long(Lenght) you want")
  279.     input = io.read()
  280.     long = tonumber(input)
  281.     long = long - 1
  282.     print("How wide(Width) you want")
  283.     input2 = io.read()
  284.     wide = tonumber(input2)
  285.     wide = wide - 1
  286.     print("How Deep(Depth) You Want")
  287.     input3 = io.read()
  288.     deep = tonumber(input3)
  289.     print("Is This Corrent Lenght " .. "Lenght = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  290.     print("Type y Or Y if it is correct and if not then n or N")
  291.     corrent = io.read()
  292.     if corrent == n or N then
  293.         os.reboot()
  294.     end
  295.     print("Okey Program Will Do Calculations")
  296.     totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  297.     print("Total amount for block to mine is " .. totalBlocks)
  298.     coalNeeded = totalBlocks / 3 / 80
  299.     print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  300.     if turtle.getFuelLevel() == "unlimited" then
  301.         print("Your turtle config does need fuel")
  302.         noFuelNeed = 1
  303.     elseif turtle.getFuelLevel() < 160 then
  304.         turtle.select(2)
  305.         turtle.refuel(2)
  306.     end
  307.     reCheck()
  308.     check()
  309.     if error == 1 then
  310.         repeat
  311.             sleep(6)
  312.             reCheck()
  313.             check()
  314.         until error == 0
  315.     end
  316.     print("Turtle will now start!")
  317.     firstDig()
  318.     main()
  319. end
  320.  
  321. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement