Advertisement
johnneijzen

Excavation Program(2015)

Oct 14th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.60 KB | None | 0 0
  1. --[[
  2. Version
  3.     0.06 10/12/2015
  4. Changelog
  5.     0.01 - Starting Of Rewriting 20/8/2015
  6.     0.02 - More Rewriting......
  7.     0.03 - Testing phase....... 10/12/2015 8:00 PM
  8.     0.04 - Minor Enchaments and bug fixing 10/12/2015 10:00 PM
  9.     0.05 - Fully Working it pass Testing Phase if there are bugs please report on github 10/12/2015 11:50 PM
  10.     0.06 - Quick Auto reformater So make everything tap not space 10/13/2015
  11. ]]
  12.  
  13. -- Local Variables in My New Program style it now a-z not random
  14. -- Area
  15. local deep = 0
  16. local deepCount = 0
  17. local long = 0
  18. local longCount = 0
  19. local wide = 0
  20. local wideCount = 0
  21. -- Misc
  22. local corrent = n
  23. local coalNeeded = 0
  24. local progress = 0
  25. local progressPercent = 0
  26. local redstoneStart = 0 -- 0 is normal start and 1 is starting with redstone.
  27. local redstoneOn = 0 -- 1 if redstone is detected and 0 if not
  28. local totalBlocks = 0
  29. local totalBlocksDone = 0
  30. -- Inventory
  31. local chest = 0
  32. local enderChest = 0 -- TODO
  33. local fuelCount = 0
  34. local fuelCount1 = 0
  35. local noFuelNeed = 0 -- This is 0 if fuel is needed and 1 is not needed
  36. local missingItems = 0
  37. -- Dig
  38. local blocked = 0 -- Fixing to Chest Probleem and moving probleem
  39. local LorR = 0 -- Left or Right This is for Wide Code
  40. local doneDig = 0
  41.  
  42. -- Main Functions in order when is it used.
  43.  
  44. -- ItemCheck
  45. local function itemCheck()
  46.     chest = turtle.getItemCount(3)
  47.     fuelCount = turtle.getItemCount(1)
  48.     fuelCount1 = turtle.getItemCount(2)
  49.     missingItems = 0
  50. end
  51.  
  52. -- Checking
  53. local function check()
  54.     if noFuelNeed == 0 then
  55.         if fuelCount == 0 then
  56.             print("Turtle has no fuel")
  57.             print("Put fuel in First and Second slot")
  58.             missingItems = 1
  59.         else
  60.             print("Turtle has Fuel")
  61.         end
  62.         if fuelCount1 == 0 then
  63.             print("Turtle has no extra fuel but if is short job it okey")
  64.         end
  65.     end
  66.     if chest == 0 then
  67.         print("No chest in Turtle")
  68.         print("Put chest in Thrid slot")
  69.         missingItems = 1
  70.     else
  71.         print("Turtle has chest")
  72.     end
  73.     if missingItems == 1 then
  74.         print("Items are missing please try again")
  75.         print("Turtle will recheck in 5 sec")
  76.     end
  77. end
  78.  
  79. -- ItemDump
  80. local function chestDump()
  81.     if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  82.         repeat -- Better Fix To Gravel Problem. Compacted and Faster and less like to break.
  83.             sleep(0.6) -- I let turtle wait for 0.6 second for gravel to fall
  84.             if turtle.detectUp() then -- if there is gravel remove it before placing chest
  85.                 turtle.digUp()
  86.                 sleep(0.6)
  87.                 blocked = 1
  88.             else
  89.                 blocked = 0
  90.             end
  91.         until blocked == 0
  92.         turtle.select(3)
  93.         turtle.placeUp()
  94.         chest = chest - 1
  95.         for slot = 4, 16 do
  96.             turtle.select(slot)
  97.             sleep(0.6) -- Small fix for slow pc because i had people problem with this
  98.             turtle.dropUp()
  99.         end
  100.         turtle.select(4)
  101.         if chest == 0 then
  102.             print("Out Of Chest")
  103.             os.shutdown()
  104.         end
  105.     end
  106. end
  107.  
  108. -- Refuel
  109. local function refuel()
  110.     if noFuelNeed == 0 then
  111.         repeat
  112.             if turtle.getFuelLevel() < 120 then
  113.                 if fuelCount > 0 then
  114.                     turtle.select(1)
  115.                     turtle.refuel(1)
  116.                     fuelCount = fuelCount - 1
  117.                 elseif fuelCount1 > 0 then
  118.                     turtle.select(2)
  119.                     turtle.refuel(1)
  120.                     fuelCount1 = fuelCount1 - 1
  121.                 else
  122.                     print("out of fuel")
  123.                     os.shutdown()
  124.                 end
  125.             end
  126.         until turtle.getFuelLevel() >= 120
  127.     end
  128. end
  129.  
  130. -- Mining Lenght
  131. local function mineLong()
  132.     if turtle.detect() then
  133.         turtle.dig()
  134.     end
  135.     if turtle.forward() then
  136.         -- Notting
  137.     else
  138.         repeat
  139.             if turtle.detect() then -- First check if there is block front if there is dig if not next step.
  140.                 turtle.dig()
  141.                 sleep(0.6)
  142.             end
  143.             if turtle.forward() then -- try to move if turtle can move blocked == 0 if cant move then blocked 1
  144.                 blocked = 0
  145.             else
  146.                 blocked = 1
  147.             end
  148.         until blocked == 0
  149.     end
  150.     if turtle.detectUp() then
  151.         turtle.digUp()
  152.     end
  153.     if turtle.detectDown() then
  154.         turtle.digDown()
  155.     end
  156.     longCount = longCount + 1
  157.     totalBlocksDone = totalBlocksDone + 3
  158. end
  159.  
  160. -- Mining Width
  161. local function mineWide()
  162.     if LorR == 0 then
  163.         turtle.turnRight()
  164.     else
  165.         turtle.turnLeft()
  166.     end
  167.     if turtle.detect() then
  168.         turtle.dig()
  169.     end
  170.     if turtle.forward() then
  171.         --Notting
  172.     else
  173.         repeat
  174.             if turtle.detect() then
  175.                 turtle.dig()
  176.                 sleep(0.6)
  177.             end
  178.             if turtle.forward() then
  179.                 blocked = 0
  180.             else
  181.                 blocked = 1
  182.             end
  183.         until blocked == 0
  184.     end
  185.     if turtle.detectUp() then
  186.         turtle.digUp()
  187.     end
  188.     if turtle.detectDown() then
  189.         turtle.digDown()
  190.     end
  191.     if LorR == 0 then
  192.         turtle.turnRight()
  193.         LorR = 1
  194.     else
  195.         turtle.turnLeft()
  196.         LorR = 0
  197.     end
  198.     longCount = 0
  199.     wideCount = wideCount + 1
  200.     totalBlocksDone = totalBlocksDone + 3
  201. end
  202.  
  203. -- Mine Deep
  204. local function mineDeep()
  205.     turtle.digDown()
  206.     turtle.down()
  207.     turtle.digDown()
  208.     turtle.down()
  209.     turtle.digDown()
  210.     turtle.down()
  211.     turtle.digDown()
  212.     turtle.turnRight()
  213.     turtle.turnRight()
  214.     wideCount = 0
  215.     longCount = 0
  216.     deepCount = deepCount + 3
  217.     totalBlocksDone = totalBlocksDone + 3
  218. end
  219.  
  220. local function firstDig()
  221.     turtle.digDown()
  222.     turtle.down()
  223.     turtle.digDown()
  224.     turtle.down()
  225.     turtle.digDown()
  226.     wideCount = 0
  227.     longCount = 0
  228.     deepCount = deepCount + 3
  229.     totalBlocksDone = totalBlocksDone + 3
  230. end
  231.  
  232. local function main()
  233.     repeat
  234.         mineLong()
  235.         refuel()
  236.         chestDump()
  237.         if longCount == long then
  238.             process = totalBlocksDone / totalBlocks * 100
  239.             processRaw = totalBlocks - totalBlocksDone
  240.             print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  241.             print("TotalBlocks Still Need To Dig Is " .. processRaw)
  242.             if wideCount == wide then
  243.                 if deepCount < deep then
  244.                     mineDeep()
  245.                 end
  246.             else
  247.                 mineWide()
  248.             end
  249.         end
  250.         if longCount == long and wideCount == wide and deepCount >= deep then
  251.             doneDig = 1
  252.         end
  253.     until doneDig == 1
  254.     print("turtle is Done")
  255. end
  256.  
  257. local function start()
  258.     print("Welcome To Excavation Turtle Program")
  259.     print("Slot 1: Fuel, Slot 2: Fuel, Slot 3: Chest")
  260.     print("Note: If now put item in then it say Error just wait it fix it self")
  261.     print("Whats is Lenght you want")
  262.     long = tonumber(read())
  263.     long = long - 1
  264.     print("Whats is Width you want")
  265.     wide = tonumber(read())
  266.     wide = wide - 1
  267.     print("Whats is Depth You Want")
  268.     deep = tonumber(read())
  269.     print("Is This Corrent Lenght " .. "Lenght = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  270.     print("Type y Or Y if it is correct and if not then n or N")
  271.     corrent = read()
  272.     if corrent == n or N then
  273.         os.reboot()
  274.     end
  275.     print("Okey Program Will Do Calculations")
  276.     totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  277.     print("Total amount for block to mine is " .. totalBlocks)
  278.     coalNeeded = totalBlocks / 3 / 80
  279.     print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  280.     if turtle.getFuelLevel() == "unlimited" then
  281.         print("Your turtle config does need fuel")
  282.         noFuelNeed = 1
  283.     end
  284.     print("Do You Want Redstone as Starting Input")
  285.     print("Note: It Only Detect Back of Turtle")
  286.     print("if not then type 0 if yes then type 1")
  287.     starting = tonumber(read())
  288.     itemCheck()
  289.     check()
  290.     if missingItems == 1 then
  291.         repeat
  292.             sleep(5)
  293.             itemCheck()
  294.             check()
  295.         until missingItems == 0
  296.     end
  297.     if noFuelNeed == 0 then
  298.         if turtle.getFuelLevel() < 120 then
  299.             turtle.select(1)
  300.             turtle.refuel(2)
  301.         end
  302.     end
  303.     if starting == 0 then
  304.         print("Turtle will now start!")
  305.         firstDig()
  306.         main()
  307.     elseif starting == 1 then
  308.         repeat
  309.             os.pullEvent("redstone") -- Wait For Redstone Input without it break with words Too long without yielding.
  310.             if redstone.getInput("back") then
  311.                 On = 1
  312.             end
  313.         until On == 1
  314.         print("Turtle will now start!")
  315.         firstDig()
  316.         main()
  317.     end
  318. end
  319.  
  320. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement