SHARE
TWEET

Untitled

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