SHARE
TWEET

Untitled

a guest Jan 26th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --This program will excavate in a 10x10 area
  2. --Starts from the bottom left
  3.  
  4. --Init
  5. local wide = 0
  6. local wideCount = 0
  7. local long = 0
  8. local longCount = 0
  9. local deep = 0
  10. local deepCount = 0
  11. local totalBlocks = 0
  12. local coalNeeded = 0
  13. local correct = n
  14. local xPos = 0
  15. local yPos = 0
  16. local zPos = 0
  17. local facing = 0 --right +, left -
  18. local initFace = 0
  19. -- Inventory: This Will Check At Start Code
  20. local chest = 0
  21. local fuelCount = 0
  22. local fuelCount1 = 0
  23. local noFuelNeed = 0 -- if Config is set to not use fuel, set = 1
  24. local error = 0 -- Error Code
  25. local reCheck = 0 -- Recheck Code
  26. -- Others
  27. local totalBlocks = 0
  28. local totalBlockDone = 0 -- How many Block Mined
  29. local LSorWS = 0 -- Go Left or Go Right This is for Wide Code
  30. local ALorAR = 0 -- align left Or align Right
  31. local processRaw = 0
  32. local process = 0
  33. local enderChest = 0 -- TODO
  34. local blockUp = 0 -- Fixing to Chest Probleem and moving probleem
  35. local processRaw = 0
  36. local process = 0
  37.  
  38. -- Checking
  39. local function check()
  40.     if noFuelNeed == 0 then
  41.         if fuelCount == 0 then
  42.             print("Turtle has no fuel")
  43.             print("Put fuel in Second and Thrid slot")
  44.             error = 1
  45.         else
  46.             print("Turtle has Fuel")
  47.         end
  48.         if fuelCount1 == 0 then
  49.             print("Turtle has no extra fuel but will run until empty")
  50.         end
  51.     end
  52.     if chest == 0 then
  53.         print("No chest in Turtle")
  54.         print("Put chest in 1 slot")
  55.         error = 1
  56.     else
  57.         print("Turtle has chest")
  58.     end
  59.     if error == 1 then
  60.         print("Items are missing please try again")
  61.         print("Turtle will recheck in 8 sec")
  62.     end
  63. end
  64.  
  65. -- Recheck if user forget something turtle will check after 6 sec
  66. local function reCheck()
  67.     chest = turtle.getItemCount(1)
  68.     fuelCount = turtle.getItemCount(2)
  69.     fuelCount1 = turtle.getItemCount(3)
  70.     error = 0
  71. end
  72.  
  73. -- Chest Dump
  74. local function chestDump()
  75.     if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  76.         initFace = facing % 4
  77.        
  78.         repeat
  79.             turtle.turnLeft()
  80.             facing = facing - 1
  81.         until facing % 4 == 3
  82.  
  83.         while xPos < 0 do
  84.             turtle.back()
  85.             xPos = xPos + 1
  86.         end
  87.        
  88.         while xPos > 0 do
  89.             turtle.forward()
  90.             xPos = xPos - 1
  91.         end
  92.        
  93.        
  94.         repeat
  95.             turtle.turnLeft()
  96.             facing = facing - 1
  97.         until facing % 4 == 2
  98.        
  99.         while yPos < 0 do
  100.             turtle.back()
  101.             yPos = yPos + 1
  102.         end
  103.        
  104.         while yPos > 0 do
  105.             turtle.forward()
  106.             yPos = yPos - 1
  107.         end
  108.        
  109.        
  110.         while zPos < 0 do
  111.             turtle.up()
  112.             zPos = zPos + 1
  113.         end
  114.  
  115.    
  116.         for slot = 4, 16 do
  117.             turtle.select(slot)
  118.             sleep(0.6)
  119.             turtle.dropUp()
  120.         end
  121.        
  122.         turtle.select(4)
  123.        
  124.         repeat
  125.             turtle.turnLeft()
  126.             facing = facing - 1
  127.         until facing % 4 == 1
  128.        
  129.         while xPos < wideCount do
  130.             turtle.forward()
  131.             xPos = xPos + 1
  132.         end
  133.        
  134.         repeat
  135.             turtle.turnLeft()
  136.             facing = facing - 1
  137.         until facing % 4 == 0
  138.        
  139.         --while yPos < longCount do
  140.         repeat
  141.             turtle.forward()
  142.             yPos = yPos + 1
  143.         until yPos == longCount
  144.         --end
  145.        
  146.         while zPos < deepCount do
  147.             turtle.down()
  148.             zPos = zPos + 1
  149.         end
  150.        
  151.         zPos = zPos * -1
  152.        
  153.         repeat
  154.             turtle.turnLeft()
  155.             facing = facing - 1
  156.         until facing % 4 == initFace
  157.     end
  158. end
  159.  
  160. -- Refuel
  161. local function refuel()
  162.     if noFuelNeed == 0 then
  163.         repeat
  164.             if turtle.getFuelLevel() < 160 then
  165.                 if fuelCount > 0 then
  166.                     turtle.select(2)
  167.                     turtle.refuel(1)
  168.                     fuelCount = fuelCount - 1
  169.                 elseif fuelCount1 > 0 then
  170.                     turtle.select(3)
  171.                     turtle.refuel(1)
  172.                     fuelCount1 = fuelCount1 - 1
  173.                 else
  174.                     print("out of fuel")
  175.                     os.shutdown()
  176.                 end
  177.             end
  178.         until turtle.getFuelLevel() >= 160
  179.     end
  180. end
  181.  
  182. local function mineLong()
  183.     if turtle.detect() then
  184.         turtle.dig()
  185.     end
  186.     if turtle.forward() then
  187.         if facing % 4 == 0 then
  188.             yPos = yPos + 1
  189.         elseif facing % 4 == 1 then
  190.             xPos = xPos + 1
  191.         elseif facing % 4 == 2 then
  192.             yPos = yPos - 1
  193.         elseif facing % 4 == 3 then
  194.             xPos = xPos - 1
  195.         end
  196.        
  197.         longCount = longCount + 1
  198.     else
  199.         repeat
  200.             turtle.dig()
  201.             sleep(0.6)
  202.             if turtle.forward() then
  203.                 if facing % 4 == 0 then
  204.                     yPos = yPos + 1
  205.                 elseif facing % 4 == 1 then
  206.                     xPos = xPos + 1
  207.                 elseif facing % 4 == 2 then
  208.                     yPos = yPos - 1
  209.                 elseif facing % 4 == 3 then
  210.                     xPos = xPos - 1
  211.                 end
  212.                 blockUp = 0
  213.             else
  214.                 blockUp = 1
  215.             end
  216.         until blockUp == 0
  217.         longCount = longCount + 1
  218.         print(totalBlocks - totalBlockDone)
  219.     end
  220.     if turtle.detectUp() then
  221.         turtle.digUp()
  222.     end
  223.     if turtle.detectDown() then
  224.         turtle.digDown()
  225.     end
  226.     totalBlockDone = totalBlockDone + 3
  227. end
  228.  
  229. local function wideMineLeft() -- TODO
  230.     turtle.turnLeft()
  231.     facing = facing - 1
  232.     if turtle.detect() then
  233.         turtle.dig()
  234.         sleep(0.6) -- Minor bug fix if there is gravel
  235.     end
  236.     if turtle.forward() then
  237.         if facing % 4 == 0 then
  238.             yPos = yPos + 1
  239.         elseif facing % 4 == 1 then
  240.             xPos = xPos + 1
  241.         elseif facing % 4 == 2 then
  242.             yPos = yPos - 1
  243.         elseif facing % 4 == 3 then
  244.             xPos = xPos - 1
  245.         end
  246.     else
  247.         repeat
  248.             turtle.dig()
  249.             sleep(0.6)
  250.             if turtle.forward() then
  251.                 if facing % 4 == 0 then
  252.                     yPos = yPos + 1
  253.                 elseif facing % 4 == 1 then
  254.                     xPos = xPos + 1
  255.                 elseif facing % 4 == 2 then
  256.                     yPos = yPos - 1
  257.                 elseif facing % 4 == 3 then
  258.                     xPos = xPos - 1
  259.                 end
  260.                 blockUp = 0
  261.             else
  262.                 blockUp = 1
  263.             end
  264.         until blockUp == 0
  265.     end
  266.     if turtle.detectUp() then
  267.         turtle.digUp()
  268.     end
  269.     if turtle.detectDown() then
  270.         turtle.digDown()
  271.     end
  272.     turtle.turnLeft()
  273.     facing = facing - 1
  274.     LSorWS = 0
  275.     longCount = 0
  276.     wideCount = wideCount + 1
  277.     totalBlockDone = totalBlockDone + 3
  278.     end
  279.  
  280. local function wideMineRight() -- TODO
  281.     turtle.turnRight()
  282.     facing = facing + 1
  283.     if turtle.detect() then
  284.         turtle.dig()
  285.         sleep(0.6)
  286.     end
  287.     if turtle.forward() then
  288.         if facing % 4 == 0 then
  289.             yPos = yPos + 1
  290.         elseif facing % 4 == 1 then
  291.             xPos = xPos + 1
  292.         elseif facing % 4 == 2 then
  293.             yPos = yPos - 1
  294.         elseif facing % 4 == 3 then
  295.             xPos = xPos - 1
  296.         end
  297.     else
  298.         repeat
  299.             turtle.dig()
  300.             sleep(0.6)
  301.             if turtle.forward() then
  302.                 if facing % 4 == 0 then
  303.                     yPos = yPos + 1
  304.                 elseif facing % 4 == 1 then
  305.                     xPos = xPos + 1
  306.                 elseif facing % 4 == 2 then
  307.                     yPos = yPos - 1
  308.                 elseif facing % 4 == 3 then
  309.                     xPos = xPos - 1
  310.                 end
  311.                 blockUp = 0
  312.             else
  313.                 blockUp = 1
  314.             end
  315.         until blockUp == 0
  316.     end
  317.     if turtle.detectUp() then
  318.         turtle.digUp()
  319.     end
  320.     if turtle.detectDown() then
  321.         turtle.digDown()
  322.     end
  323.     turtle.turnRight()
  324.     facing = facing + 1
  325.     LSorWS = 1
  326.     longCount = 0
  327.     wideCount = wideCount + 1
  328.     totalBlockDone = totalBlockDone + 3
  329. end
  330.  
  331. local function deepMine()
  332.     turtle.digDown()
  333.     turtle.down()
  334.         zPos = zPos - 1
  335.     turtle.digDown()
  336.     turtle.down()
  337.         zPos = zPos - 1
  338.     turtle.digDown()
  339.     turtle.down()
  340.         zPos = zPos - 1
  341.     turtle.digDown()
  342.     turtle.turnRight()
  343.     facing = facing + 1
  344.     turtle.turnRight()
  345.     facing = facing + 1
  346.     wideCount = 0
  347.     longCount = 0
  348.     deepCount = deepCount + 3
  349.     totalBlockDone = totalBlockDone + 3
  350. end
  351.  
  352. local function main()
  353.     repeat --Repeat for each level
  354.         mineLong()
  355.         refuel()
  356.         chestDump()
  357.         if longCount == long then
  358.             if wideCount ~= wide then
  359.                 process = totalBlockDone / totalBlocks * 100
  360.                 processRaw = totalBlocks - totalBlockDone
  361.                 print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  362.                 print("TotalBlocks Still Need To Dig Is " .. processRaw)
  363.                 if LSorWS == 0 then
  364.                     wideMineRight()
  365.                 else
  366.                     wideMineLeft()
  367.                 end
  368.             elseif wideCount >= wide then
  369.                     deepMine()
  370.             end
  371.         end
  372.     until deepCount >= deep
  373.     print("turtle is Done")
  374. end
  375.  
  376. local function firstDig()
  377.     turtle.digDown()
  378.     turtle.down()
  379.         zPos = zPos - 1
  380.     turtle.digDown()
  381.     turtle.down()
  382.         zPos = zPos - 1
  383.     turtle.digDown()
  384.     wideCount = 0
  385.     longCount = 0
  386.     deepCount = deepCount + 2
  387.     totalBlockDone = totalBlockDone + 3
  388. end
  389.  
  390. local function start()
  391.     print("Welcome To The Dig Turtle Program")
  392.     print("Slot 1: Chest, Slot 2: Fuel, Slot 3: Fuel")
  393.     print("How long(Length) do you want")
  394.     input = io.read()
  395.     long = tonumber(input)
  396.     long = long - 1
  397.     print("How wide(Width) do you want")
  398.     input2 = io.read()
  399.     wide = tonumber(input2)
  400.     wide = wide - 1
  401.     print("How Deep(Depth) do you Want")
  402.     input3 = io.read()
  403.     deep = tonumber(input3)
  404.     print("Is This Correct?: Length = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  405.     print("Type Y if correct or N if incorrect")
  406.     correct = io.read()
  407.     if correct == n or N then
  408.         os.reboot()
  409.     end
  410.     print("Okay Program Will Do Calculations")
  411.     totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  412.     print("Total amount for block to mine is " .. totalBlocks)
  413.     coalNeeded = totalBlocks / 3 / 80
  414.     print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  415.     if turtle.getFuelLevel() == "unlimited" then
  416.         print("Your turtle config does need fuel")
  417.         noFuelNeed = 1
  418.     elseif turtle.getFuelLevel() < 160 then
  419.         turtle.select(2)
  420.         turtle.refuel(2)
  421.     end
  422.     reCheck()
  423.     check()
  424.     if error == 1 then
  425.         repeat
  426.             sleep(6)
  427.             reCheck()
  428.             check()
  429.         until error == 0
  430.     end
  431. end
  432.  
  433. start()
  434. print("Turtle will now start!")
  435. turtle.select(1)
  436. turtle.placeUp()
  437. firstDig()
  438. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top