Advertisement
hevohevo

ComputerCraft Tutorial: boring_0_4

Feb 17th, 2014
2,953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. -- ################################
  2. -- Boring by silktouch mining turtle
  3. -- version 0.4
  4. -- http://hevohevo.hatenablog.com/
  5. -- This Program requires a SilkTouch 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 silkP = peripheral.wrap("right")
  21. if silkP and silkP.digSilkTouch then
  22.   print("Boring with SilkTouch!")
  23.   turtle.dig_org = turtle.dig_org or turtle.dig
  24.   turtle.dig= silkP.digSilkTouch
  25.  
  26.   turtle.digDown_org = turtle.digDown_org or turtle.digDown
  27.   turtle.digDown = silkP.digSilkTouchDown
  28. end
  29.  
  30. function waitForEnoughItems(itemName, n, slot)
  31.   turtle.select(slot)
  32.   os.sleep(0.5)
  33.   while turtle.getItemCount(slot) < n do
  34.     if itemName then print(string.format("Insert %s into slot %d",itemName,slot)) end
  35.     os.pullEvent("turtle_inventory")
  36.     os.sleep(1)
  37.   end
  38. end
  39.  
  40. function waitForEnoughFuel(minLevel, slot)
  41.   turtle.select(slot)
  42.   turtle.refuel()
  43.   while  turtle.getFuelLevel() < minLevel do
  44.     print(string.format("Insert fuel-items into slot %d: %d/%d",slot, turtle.getFuelLevel(), minLevel))
  45.     os.pullEvent("turtle_inventory")
  46.     turtle.refuel()
  47.     os.sleep(1)
  48.   end
  49. end
  50.  
  51. Count = 0
  52. function revolve(depth)
  53.   for i=1, 4 do -- dig four sides
  54.     if turtle.dig() then Count=Count+1 end
  55.     turtle.turnRight()
  56.   end
  57.  
  58.   if turtle.digDown() then Count=Count+1 end
  59.  
  60.   if turtle.getFuelLevel() > depth + 10 then
  61.     return turtle.down() -- return true/false
  62.   else
  63.     return false -- if fuel shortage
  64.   end
  65. end
  66.  
  67. function closeHole()
  68.   turtle.select(LID_BLOCK_SLOT)
  69.  
  70.   turtle.down()
  71.   for i=1,4 do
  72.     turtle.place()
  73.     turtle.turnRight()
  74.   end
  75.   turtle.up()
  76.   turtle.placeDown()
  77. end
  78.  
  79. function backToHome(n)
  80.   for i=1, n do -- back to home position.
  81.     turtle.up()
  82.   end
  83. end
  84.  
  85. -- ########## main
  86. waitForEnoughFuel(MIN_FUEL_LEVEL, FUEL_SLOT)
  87. waitForEnoughItems("5 lid-blocks", 5, LID_BLOCK_SLOT)
  88.  
  89. local depth = 0
  90. while revolve(depth) do
  91.     print("Depth: ",depth)
  92.   depth = depth +1
  93. end
  94.  
  95. backToHome(depth)
  96. if CLOSE_HOLE_FLAG then closeHole() end
  97. print("Result: ",Count," blocks")
  98. print("Current Fuel: ",turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement