Advertisement
hevohevo

ComputerCraft Tutorial: boring_0_5

Feb 18th, 2014
1,362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. -- ################################
  2. -- Boring by silktouch/fortune mining turtle
  3. -- version 0.5
  4. -- http://hevohevo.hatenablog.com/
  5. -- This Program requires a SilkTouch/Fortune Mining Turtle by "More Turtles" mod
  6. --  "More Turtles" was created by Nokiyen.
  7. --  http://www.computercraft.info/forums2/index.php?/topic/16465-mc164152-more-turtles-v112/
  8.  
  9. -- ########## config
  10. MIN_FUEL_LEVEL = 64 * 6 + 64 + 10
  11. FUEL_SLOT=16
  12. CLOSE_HOLE_FLAG = true -- whether close a hole
  13. LID_BLOCK_SLOT = 1
  14.  
  15. local args={...}
  16. -- reverse CLOSE_HOLE_FLAG
  17. if #args > 0 then CLOSE_HOLE_FLAG = not CLOSE_HOLE_FLAG end
  18.  
  19. -- ########## functions
  20. local p = peripheral.wrap("right")
  21. if p and p.digSilkTouch then
  22.   print("Boring with SilkTouch!")
  23.   turtle.dig_org = turtle.dig_org or turtle.dig
  24.   turtle.dig= silkP.digSilkTouch
  25.   turtle.digDown_org = turtle.digDown_org or turtle.digDown
  26.   turtle.digDown = silkP.digSilkTouchDown
  27. elseif p and p.digFortune then
  28.   print("Boring with Fortune!")
  29.   turtle.dig_org = turtle.dig_org or turtle.dig
  30.   turtle.dig= p.digFortune
  31.   turtle.digDown_org = turtle.digDown_org or turtle.digDown
  32.   turtle.digDown = p.digFortuneDown
  33. end
  34.  
  35. function waitForEnoughItems(itemName, n, slot)
  36.   turtle.select(slot)
  37.   os.sleep(0.5)
  38.   while turtle.getItemCount(slot) < n do
  39.     if itemName then print(string.format("Insert %s into slot %d",itemName,slot)) end
  40.     os.pullEvent("turtle_inventory")
  41.     os.sleep(1)
  42.   end
  43. end
  44.  
  45. function waitForEnoughFuel(minLevel, slot)
  46.   turtle.select(slot)
  47.   turtle.refuel()
  48.   while  turtle.getFuelLevel() < minLevel do
  49.     print(string.format("Insert fuel-items into slot %d: %d/%d",slot, turtle.getFuelLevel(), minLevel))
  50.     os.pullEvent("turtle_inventory")
  51.     turtle.refuel()
  52.     os.sleep(1)
  53.   end
  54. end
  55.  
  56. Count = 0
  57. function revolve(depth)
  58.   for i=1, 4 do -- dig four sides
  59.     if turtle.dig() then Count=Count+1 end
  60.     turtle.turnRight()
  61.   end
  62.  
  63.   if turtle.digDown() then Count=Count+1 end
  64.  
  65.   if turtle.getFuelLevel() > depth + 10 then
  66.     return turtle.down() -- return true/false
  67.   else
  68.     return false -- if fuel shortage
  69.   end
  70. end
  71.  
  72. function closeHole()
  73.   turtle.select(LID_BLOCK_SLOT)
  74.  
  75.   turtle.down()
  76.   for i=1,4 do
  77.     turtle.place()
  78.     turtle.turnRight()
  79.   end
  80.   turtle.up()
  81.   turtle.placeDown()
  82. end
  83.  
  84. function backToHome(n)
  85.   for i=1, n do -- back to home position.
  86.     turtle.up()
  87.   end
  88. end
  89.  
  90. -- ########## main
  91. waitForEnoughFuel(MIN_FUEL_LEVEL, FUEL_SLOT)
  92. waitForEnoughItems("5 lid-blocks", 5, LID_BLOCK_SLOT)
  93.  
  94. local depth = 0
  95. while revolve(depth) do
  96.     print("Depth: ",depth)
  97.   depth = depth +1
  98. end
  99.  
  100. backToHome(depth)
  101. if CLOSE_HOLE_FLAG then closeHole() end
  102. print("Result: ",Count," blocks")
  103. print("Current Fuel: ",turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement