Advertisement
Guest User

NetherFocus Miner

a guest
Feb 27th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1.  -- Mining Program with Nether Focus --
  2. -- Chest with Fuel above Turtle
  3. -- Dump Chest behind Turtle
  4.  
  5. local numRODefault = 32
  6. local numRRDefault = 1
  7.  
  8. -- Get Inputs --
  9. local inputs = {...}
  10. if tonumber(inputs[1]) > 0 then numRunsOut = inputs[1] else numRunsOut = numRODefault end
  11. if tonumber(inputs[2]) > 0 then numRunsRight = inputs[2] else numRunsRight = numRRDefault end
  12.  
  13. -- ini User Varibles --
  14. local rSLowerLimit = 17
  15. local dropAmount = 15
  16.  
  17. -- Turtle Slot Assignments --
  18. local fuelSlot = 1
  19. local rackSlot = 2
  20. local set = 2
  21. local inventoryCheck = 15
  22.  
  23. -- ini Program Varibles --
  24. local tH = 0 -- Total Height,
  25. local sL = 1 -- Sleep Length in slp()
  26. local isHeadingOut = true
  27. local rAdj = 0 -- Total Right Adjust
  28. local oAdj = 0 -- Total Out Adjust
  29. local junk = "junk" -- Used in refuel pause
  30. local nR = 0 -- systems' track of runs Out
  31. local nRR = 0 -- systems' track of runs Right
  32. local refuelAmount = 1
  33. local fuelCheck = 10000
  34.  
  35. --BASE FUNCTIONS--
  36. function slp() os.sleep(sL) end -- sleeps
  37. function tRound() turtle.turnLeft() turtle.turnLeft() end -- obvious
  38. function mF() if turtle.detect() then turtle.dig() end while not turtle.forward() do slp() turtle.dig() end end -- if movement fails, dig in that direction, wait a sec, then try again. repeat until success.
  39. function mB() while not turtle.back() do slp() tRound() turtle.dig() tRound() end end
  40. function mU() if turtle.detectUp() then turtle.digUp() end while not turtle.up() do slp() turtle.digUp() end end
  41. function mD() if turtle.detectDown() then turtle.digDown() end while not turtle.down() do slp() turtle.digDown() end end
  42. function tR() turtle.turnRight() end --shorthand
  43. function tL() turtle.turnLeft() end
  44.  
  45. function rA()
  46.  tR()
  47.  for i = 1,rAdj do mF() end
  48.  tL()
  49. end
  50.  
  51. function oA()
  52.  for i = 1,oAdj do mF() end
  53. end
  54.  
  55. function dF()
  56.  turtle.select(rackSlot)
  57.  if turtle.detect() then
  58.   if not turtle.compare() then
  59.    turtle.dig() end end
  60.  turtle.select(set)
  61. end
  62.  
  63. function cF()
  64.     dF() tR()
  65.     dF() tL()
  66. end
  67.  
  68. function rtS()
  69.  for i = 1,tH do
  70.   mU() end
  71. end
  72.  
  73. function rtM()
  74.  for i = 1,tH do
  75.   mD() end
  76. end
  77.  
  78. function preDump()
  79.     if isHeadingOut then
  80.         tRound()
  81.     end
  82.     oA()
  83.     rA()
  84. end
  85.  
  86. function dump()
  87.  for i = 3,16 do
  88.   turtle.select(i)
  89.   turtle.drop() end
  90.  turtle.select(rackSlot)
  91.  while turtle.getItemCount() > rSLowerLimit do
  92.   turtle.drop(dropAmount) end
  93.  tRound()
  94.  turtle.select(set)
  95. end
  96.  
  97. function postDump()
  98.  rA()
  99.  oA()
  100.  if not isHeadingOut then tRound() end
  101. end
  102.  
  103. function rFuel()
  104.  turtle.select(fuelSlot)
  105.  while turtle.getFuelLevel() <= fuelCheck do
  106.   shell.run("refuel","1")
  107.   turtle.suckUp(1)
  108.  end
  109.  turtle.select(set)
  110. end
  111.  
  112. function cI()
  113.  if turtle.getItemCount(inventoryCheck) >= 1 then
  114.   rtS()
  115.   preDump()
  116.   dump()
  117.   rFuel()
  118.   postDump()
  119.   rtM() end
  120. end
  121.  
  122. function digDn()
  123.     if dD() then
  124.         tH += 1
  125.     else
  126.         cFail()
  127.     end
  128. end
  129.  
  130. function dD()
  131.  local k = 0
  132.  turtle.digDown()
  133.  for k = 1,5 do
  134.     if turtle.down() then
  135.         return true
  136.     else
  137.         turtle.digDown()
  138.         sleep(.5)
  139.     end
  140.  end
  141.  if k >= 4 then return false
  142.     else print ("Error in bedrock detection. Failed to return true, Failed to try enough to return false. /n Stopping by endless while loop (Ctrl+t for 1 sec)") while true do sleep(30) end end
  143. end
  144.  
  145. function cFail()
  146.   rtS()
  147.   for i = 1,2 do
  148.    mF()
  149.    if isHeadingOut then oAdj += 1
  150.    else oAdj -= 1
  151.   end
  152.   write(tH.."|")
  153.   tH = 0
  154.   nR = nR + 1
  155.  end
  156. end
  157.  
  158. function runForward()
  159.     postDump()
  160.     for i=1,2 do
  161.         while nR <= (numRunsOut-1) do
  162.             cI()
  163.             digDn()
  164.             cF()
  165.         end
  166.         if isHeadingOut then
  167.             mF()
  168.             oAdj += 1
  169.             tR()
  170.             mF() mF()
  171.             rAdj = rAdj + 2
  172.             tR()
  173.             isHeadingOut = false
  174.             nR = 0
  175.         end
  176.     end
  177.  preDump()
  178.  dump()
  179.  nRR = nRR + 1
  180. end
  181.  
  182. --XX--PROGRAM--START--XX--
  183.  
  184. --Refuel for complete run (once); May need tweaking; done in Program Varibles --
  185.  
  186. rFuel()
  187.  
  188. -- MAIN LOOP --
  189.  
  190. while nRR <= numRunsRight do
  191.  runForward()
  192.  oAdj = 0
  193.  nR = 0
  194.  rAdj = nRR * 3
  195.  isHeadingOut = true
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement