Advertisement
johnneijzen

Strip Mining Program (2015)

Oct 14th, 2015
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.82 KB | None | 0 0
  1. --[[
  2. Version
  3.   0.04 10/13/2015
  4. Changelog
  5.   0.01 - Rewriting.
  6.   0.02 - More Rewritting.....
  7.   0.03 - Testing Phase
  8.   0.04 - One minnor bug Fixed
  9. ]]
  10.  
  11. -- Local Variables in My New Program style it now a-z not random
  12. -- Area
  13. local distance = 0
  14. local distanceApart = 0
  15. local distanceApartCount = 0
  16. local backwardsCount = 0
  17. local forwardsCount = 0
  18. -- Misc
  19. local noFuelNeed = 0
  20. local LorR = 0 -- if 0 then left if 1 then right
  21. local howManyTimes = 0
  22. local onlight = 0
  23. -- Inventory
  24. local chests = 0
  25. local itemFuel = 0
  26. local torch = 0
  27.  
  28. -- ItemCheck
  29. local function itemCheck()
  30.     chests = turtle.getItemCount(2)
  31.     itemFuel = turtle.getItemCount(1)
  32.     torch = turtle.getItemCount(3)
  33.     missingItems = 0
  34. end
  35.  
  36. -- Checking
  37. local function check()
  38.     if noFuelNeed == 0 then
  39.         if itemFuel == 0 then
  40.             print("Turtle has no fuel")
  41.             print("Put fuel in second and thrid slot")
  42.             missingItems = 1
  43.         else
  44.             print("Turtle has Fuel")
  45.         end
  46.     end
  47.     if chests == 0 then
  48.         print("No chests in turtle")
  49.         print("Put chests in 1 slot")
  50.         missingItems = 1
  51.     else
  52.         print("Turtle has chest")
  53.     end
  54.     if missingItems == 1 then
  55.         print("Items are missing please try again")
  56.         print("Turtle will recheck in 5 sec")
  57.     end
  58. end
  59.  
  60. -- Refuel
  61. local function refuel()
  62.     if noFuelNeed == 0 then
  63.         repeat
  64.             if turtle.getFuelLevel() < 100 then
  65.                 if itemFuel > 0 then
  66.                     turtle.select(1)
  67.                     turtle.refuel(1)
  68.                     itemFuel = itemFuel - 1
  69.                 else
  70.                     print("out of fuel")
  71.                     os.shutdown()
  72.                 end
  73.             end
  74.         until turtle.getFuelLevel() >= 100
  75.     end
  76. end
  77.  
  78. -- ItemDump
  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.         turtle.digDown()
  82.         turtle.select(2)
  83.         turtle.placeDown()
  84.         chests = chests - 1
  85.         for slot = 5, 16 do
  86.             turtle.select(slot)
  87.             sleep(0.6) -- Small fix for slow pc because i had people problem with this
  88.             turtle.dropDown()
  89.         end
  90.         turtle.select(4)
  91.         if chests == 0 then
  92.             print("Out Of chests")
  93.             os.shutdown()
  94.         end
  95.     end
  96. end
  97.  
  98. local function turnAround()
  99.     turtle.turnLeft()
  100.     turtle.turnLeft()
  101. end
  102.  
  103. local function placeTorch()
  104.     if torch > 0 then
  105.         turnAround()
  106.         turtle.select(3)
  107.         turtle.place()
  108.         turnAround()
  109.         torch = torch - 1
  110.         onlight = 0
  111.     end
  112. end
  113.  
  114. local function dig()
  115.     repeat
  116.         refuel()
  117.         chestDump()
  118.         if turtle.detect() then
  119.             turtle.dig()
  120.         end
  121.         if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  122.             forwardsCount = forwardsCount + 1
  123.             onlight = onlight + 1
  124.         end
  125.         if turtle.detectUp() then
  126.             turtle.digUp()
  127.         end
  128.         if onlight == 8 then
  129.             placeTorch()
  130.         end
  131.     until forwardsCount == distance
  132. end
  133.  
  134. --Back Program
  135. local function back()
  136.     turtle.up()
  137.     turnAround()
  138.     repeat
  139.         if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  140.             backwardsCount = backwardsCount + 1
  141.         end
  142.         if turtle.detect() then -- Sometimes sand and gravel can happen and this will fix it
  143.             if backwardsCount ~= distance then
  144.                 turtle.dig()
  145.             end
  146.         end
  147.     until backwardsCount == distance
  148. end
  149.  
  150. -- Multimines Program
  151. local function nextMine()
  152.     if LorR == 1 then
  153.         turtle.turnLeft()
  154.         turtle.down()
  155.     else
  156.         turtle.turnRight()
  157.         turtle.down()
  158.     end
  159.     repeat
  160.         if turtle.detect() then
  161.             turtle.dig()
  162.         end
  163.         if turtle.forward() then
  164.             distanceApartCount = distanceApartCount + 1
  165.         end
  166.         if turtle.detectUp() then
  167.             turtle.digUp()
  168.         end
  169.     until distanceApartCount == distanceApart
  170.     if LorR == 1 then
  171.         turtle.turnLeft()
  172.     else
  173.         turtle.turnRight()
  174.     end
  175. end
  176.  
  177. -- Reset
  178. local function reset()
  179.     backwardsCount = 0
  180.     forwardsCount = 0
  181.     distanceApartCount = 0
  182.     onlight = 0
  183. end
  184.  
  185. local function main()
  186.     repeat
  187.         dig()
  188.         back()
  189.         nextMine()
  190.         reset()
  191.         howManyTimes = howManyTimes - 1
  192.     until howManyTimes == 0
  193.     print("Turtle is done")
  194. end
  195.  
  196. -- Starting
  197. local function start()
  198.     print("Welcome to Mining Turtle Program")
  199.     print("Slot 1: Fuel, Slot 2: Chests, Optional Slot 3: Torchs")
  200.     print("Note: turtle will still work then there is no more torchs")
  201.     print("How Far Will Turtle Go")
  202.     distance = tonumber(read())
  203.     print("Left or Right")
  204.     print("0 = Left and 1 = Right")
  205.     LorR = tonumber(read())
  206.     print("How Many Times")
  207.     howManyTimes = tonumber(read())
  208.     print("Distance Apart from each Mine")
  209.     distanceApart = tonumber(read())
  210.     distanceApart = distanceApart + 1
  211.     if turtle.getFuelLevel() == "unlimited" then
  212.         print("Your turtle config does need fuel")
  213.         noFuelNeed = 1
  214.     end
  215.     itemCheck()
  216.     check()
  217.     if missingItems == 1 then
  218.         itemCheck()
  219.         check()
  220.     end
  221.     main()
  222. end
  223.  
  224. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement