Advertisement
Riewest14

pokemine.lua

Feb 27th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = {...}
  2.  
  3. startHeight = args[1]
  4. flatBedrock = args[2]
  5.  
  6. moveSeq = {}
  7. moveSeq[1] = 0
  8. moveSeq[2] = 3
  9. moveSeq[3] = 1
  10. moveSeq[4] = 4
  11. moveSeq[5] = 2
  12.  
  13. chestSlot  = 16
  14. cobbleSlot = 1
  15.  
  16. digDir = nil
  17.  
  18. minLevel = 5
  19. if flatBedrock then
  20.     minLevel = 2
  21. end
  22.  
  23. ------------------
  24. --MOVEMENT METHODS
  25. ------------------
  26.  
  27. --Just runs turtle.forward()
  28. --until the specified amount toMov
  29. --is met. Digs block if unable to move
  30. function mF(toMov, action)
  31.   if not toMov then
  32.     toMov = 1
  33.   end
  34.   for i = 1, toMov do
  35.     while not (turtle.forward()) do
  36.       turtle.dig()
  37.     end
  38.     if action then action() end
  39.   end
  40. end
  41.  
  42. --Runst turtle.back() toMov times
  43. function mB(toMov, action)
  44.   if not toMov then
  45.     toMov = 1
  46.   end
  47.   for i = 1, toMov do
  48.     while not turtle.back() do
  49.       sleep(.1)
  50.     end
  51.     if action then action() end
  52.   end
  53. end
  54.  
  55. --Runs turtle.up() toMov times
  56. --and digs up if unable to move up.
  57. function mU(toMov, action)
  58.   if not toMov then
  59.     toMov = 1
  60.   end
  61.   for i = 1, toMov do
  62.     while not (turtle.up()) do
  63.       turtle.digUp()
  64.     end
  65.     if action then action() end
  66.   end
  67. end
  68.  
  69. --Runs turtle.down() toMov times
  70. -- and digs down if unable to move down
  71. function mD(toMov, action)
  72.   if not toMov then
  73.     toMov = 1
  74.   end
  75.   for i = 1, toMov do
  76.     while not (turtle.down()) do
  77.       turtle.digDown()
  78.     end
  79.     if action then action() end
  80.   end
  81. end
  82.  
  83. --Turns the turtle 180 degrees
  84. function turnAround()
  85.   turtle.turnLeft()
  86.   turtle.turnLeft()
  87. end
  88.  
  89. ------------------
  90. ------------------
  91. --UTILITY METHODS
  92. ------------------
  93. ------------------
  94. function fuelCheck()
  95.     pokeBlocks = startHeight - minLevel + 1
  96.     pokeMove = pokeBlocks * 52
  97.     tranMove = 16 * 16
  98.     totalMove = tranMove + pokeMove
  99.     print("Current Fuel:", turtle.getFuelLevel())
  100.         print("Estimated Fuel:", totalMove + 100)
  101.     if (totalMove + 100) >= turtle.getFuelLevel() then
  102.         print("Need more fuel for requested chunkmine.")
  103.         return false
  104.     end
  105.     return true
  106. end
  107.  
  108. function dropSide(slotNum, side)
  109.   turtle.select(slotNum)
  110.   side = string.lower(side)
  111.   success = false
  112.   if side == "front" then
  113.     success = turtle.drop()
  114.   elseif side == "top" then
  115.     success = turtle.dropUp()
  116.   elseif side == "bottom" then
  117.     success = turtle.dropDown()
  118.   else
  119.     success = turtle.drop()
  120.   end
  121.   return success
  122. end
  123.  
  124. function emptyInv(slotsToEmpty, side)
  125.   oldSlot = turtle.getSelectedSlot()
  126.   if not side then
  127.     side = "back"
  128.   end
  129.   if not slotsToEmpty then
  130.     count = 16
  131.   else
  132.     count = table.getn(slotsToEmpty)
  133.   end
  134.   for i = 1, count do
  135.     dropSide(slotsToEmpty[i], side)
  136.   end
  137.   turtle.select(oldSlot)
  138. end
  139.  
  140. function doChest()
  141.     turtle.select(chestSlot)
  142.     while not turtle.placeUp() do
  143.         turtle.digUp()
  144.         sleep(.1)
  145.     end
  146.     slotsToEmpty = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
  147.     emptyInv(slotsToEmpty, "top")
  148.     turtle.select(chestSlot)
  149.     turtle.digUp()
  150.     turtle.select(cobbleSlot)
  151. end
  152.  
  153. ------------------
  154. ------------------
  155. --MINING METHODS
  156. ------------------
  157. ------------------
  158.  
  159. function checkOre()
  160.     success, block = turtle.inspect()
  161.     if not success then return false end
  162.     name = string.lower(block.name)
  163.     return (string.match(name, "ore"))
  164. end
  165.  
  166. function scan()
  167.     for i=1, 4 do
  168.         if checkOre() then
  169.             turtle.dig()
  170.         end
  171.         turtle.turnRight()
  172.     end
  173. end
  174.  
  175. function poke()
  176.     turtle.select(cobbleSlot)
  177.     for i=1+minLevel, startHeight do
  178.         digDir(1, scan)
  179.         if (i == minLevel + 2 and digDir == mD) then turtle.placeUp() end
  180.     end
  181.     if digDir == mD then
  182.         digDir = mU
  183.     else
  184.         turtle.placeDown()
  185.         digDir = mD
  186.     end
  187.     doChest()
  188. end
  189.  
  190. function doRow(startMove)
  191.     mF(startMove)
  192.     moveAmount = 15 - startMove
  193.     poke()
  194.     while moveAmount >= 5 do
  195.         mF(5)
  196.         moveAmount = moveAmount - 5
  197.         poke()
  198.     end
  199.     mF(moveAmount)
  200. end
  201.  
  202. function doChunk()
  203.     moveIndex = 1
  204.     for i=1, 16 do
  205.         evenRow = (i % 2 == 0)
  206.         startMove = moveSeq[moveIndex]
  207.         if evenRow and startMove ~= 0 then startMove = 5 - startMove end
  208.         doRow(startMove)
  209.         if evenRow and i ~= 16 then
  210.             turtle.turnLeft()
  211.             mF(1)
  212.             turtle.turnLeft()
  213.         elseif i ~= 16 then
  214.             turtle.turnRight()
  215.             mF(1)
  216.             turtle.turnRight()
  217.         end
  218.         moveIndex = moveIndex + 1
  219.         if moveIndex > 5 then moveIndex = 1 end
  220.     end
  221. end
  222.  
  223. function start()
  224.     digDir = mD
  225.     if fuelCheck() then
  226.         doChunk()
  227.     end
  228.     turnAround()
  229. end
  230.  
  231. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement