Advertisement
M0n5t3r

MineBot

Jul 3rd, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. -- Variables
  2.  
  3. local torchslot = 14
  4. local fuelslot = 16
  5. local woodslot = 13
  6. local chestslot =15
  7. local torch = 0
  8. local chest = 0
  9. local targs = { ... }
  10. steps = tonumber(targs[1])
  11. steps = steps or 1
  12. local fuelneeded = 0
  13. local torchesneeded = 0
  14. local chestneeded = 0
  15. local torchesgot = turtle.getItemCount(torchslot)
  16. local chestgot = turtle.getItemCount(torchslot)
  17. local fuellevel = 0
  18.  
  19. -- Functions
  20.  
  21. function digBlock()
  22.         repeat
  23.                 turtle.dig()
  24.                 sleep(0.5)
  25.         until not turtle.detect() == true
  26. end
  27.  
  28. fuellevel = turtle.getFuelLevel()
  29. torchesgot = turtle.getItemCount(torchslot)
  30. chestgot = turtle.getItemCount(torchslot)
  31.  
  32. -- Math
  33.  
  34. fuelneeded = steps*5
  35. fuelneeded = fuelneeded+steps
  36. if steps > 40 then
  37.         torchesneeded = steps/10
  38.         chestneeded = steps/30
  39. else
  40.         torchesneeded = 0
  41.         chestneeded = 0
  42. end
  43.  
  44. -- Welcome messages
  45. print(" ****************************")
  46. print(" *  MineBot By BlackApple   *")
  47. print(" ****************************")
  48. print(" *-=  Distance to mine:   ", steps)
  49. print(" *-=  Fuel needed:        ", fuelneeded)
  50. print(" *-=  Fuel level:         ", fuellevel)
  51. print(" *-=  Torches needed:      ", torchesneeded)
  52. print(" *-=  Torch level:        ", torchesgot)
  53. print(" *-=  Chest needed:     ", chestneeded)
  54. print(" *-=  Torches Level:        ", chestgot)
  55. print(" ****************************")
  56. -- Resource Acquiring
  57.  
  58. if fuellevel < fuelneeded then
  59.         print("  !! insert fuel in slot ", fuelslot)
  60.         repeat
  61.                 sleep(0.5)
  62.                 turtle.select(fuelslot)
  63.                 turtle.refuel()
  64.                 fuellevel = turtle.getFuelLevel()
  65.         until fuellevel > fuelneeded
  66. end
  67.  
  68. if chestgot < chestneeded then
  69.         print("  !! insert chests in slot ", chestslot)
  70.         repeat
  71.                 sleep(0.5)
  72.                 turtle.select(chestslot)
  73.                 chestgot= turtle.getItemCount(chestslot)
  74.         until chestgot >= chestneeded
  75. end
  76.  
  77. if torchesgot < torchesneeded then
  78.         print("  !! insert torches in slot ", torchslot)
  79.         repeat
  80.                 sleep(0.5)
  81.                 turtle.select(torchslot)
  82.                 torchesgot = turtle.getItemCount(torchslot)
  83.         until torchesgot >= torchesneeded
  84. end
  85.  
  86. print("Resources acquired. Beginning mining...")
  87. stopdigging = 0
  88.  
  89.  
  90. -- Begin Digging
  91.  
  92.  
  93. for i = 1, steps do
  94.         digBlock()
  95.         turtle.forward()
  96.         turtle.select(1)
  97.         turtle.placeDown()
  98.         repeat
  99.                 turtle.digUp()
  100.                 sleep(0.3)
  101.         until turtle.up() == true
  102.         repeat
  103.                 turtle.digUp()
  104.                 sleep(0.3)
  105.         until turtle.up() == true
  106.         turtle.turnLeft()
  107.         turtle.dig()
  108.         turtle.turnRight()
  109.         turtle.turnRight()
  110.         turtle.dig()
  111.         turtle.down()
  112.         turtle.dig()
  113.         turtle.turnLeft()
  114.         turtle.turnLeft()
  115.         turtle.dig()
  116.         turtle.down()
  117.         digBlock()
  118.         turtle.turnRight()
  119.         turtle.turnRight()
  120.         digBlock()
  121.         turtle.turnLeft()
  122.         torch = torch + 1
  123.         if torch == 10 then
  124.                 turtle.turnLeft()
  125.                 turtle.turnLeft()
  126.                 turtle.select(torchslot)
  127.                 turtle.place()
  128.                 turtle.turnLeft()
  129.                 turtle.turnLeft()
  130.                 turtle.forward()
  131.                 turtle.select(woodslot)
  132.                 torch = 1
  133.         end
  134.         chest = chest + 1
  135.         if chest == 30 then
  136.                 turtle.turnLeft()
  137.                 turtle.select(chestslot)
  138.                 turtle.place()
  139.                 for q=1,12 do turtle.select(q) turtle.drop() end
  140.                 turtle.turnRight()
  141.                 turtle.select(woodslot)
  142.                 chest = 1
  143.  
  144.         end
  145. end
  146. turtle.turnLeft()
  147. turtle.turnLeft()
  148. turtle.up()
  149. for i = 1, steps do
  150.         turtle.forward()
  151. end
  152. turtle.down()
  153. turtle.turnLeft()
  154. turtle.turnLeft()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement