SHARE
TWEET

ComputerCraft Tutorial: boring_0_3

hevohevo Feb 16th, 2014 974 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ################################
  2. -- boring by mining turtle
  3. -- version 0.3
  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. CLOSE_HOLE_FLAG = true -- whether close a hole
  12. LID_BLOCK_SLOT = 1
  13.  
  14. local args={...}
  15. -- reverse CLOSE_HOLE_FLAG
  16. if #args > 0 then CLOSE_HOLE_FLAG = not CLOSE_HOLE_FLAG end
  17.  
  18. -- ########## functions
  19. local silkP = peripheral.wrap("right")
  20. if silkP and silkP.digSilkTouch then
  21.   print("Boring with SilkTouch!")
  22.   turtle.dig_org = turtle.dig_org or turtle.dig
  23.   turtle.dig= silkP.digSilkTouch
  24.  
  25.   turtle.digDown_org = turtle.digDown_org or turtle.digDown
  26.   turtle.digDown = silkP.digSilkTouchDown
  27. end
  28.  
  29. function myRefuel()
  30.   local function refuelAll()
  31.     for i=1, 16 do
  32.       turtle.select(i)
  33.       turtle.refuel()
  34.     end
  35.     print("Fuel: ",turtle.getFuelLevel(), " (required: ",MIN_FUEL_LEVEL,")")
  36.   end
  37.  
  38.   refuelAll()
  39.   while turtle.getFuelLevel() < MIN_FUEL_LEVEL do
  40.     os.sleep(1)
  41.     -- wait for putting items in inventory
  42.     os.pullEvent("turtle_inventory")
  43.     refuelAll()
  44.   end
  45.  
  46.   turtle.select(1)
  47. end
  48.  
  49. Count = 0
  50. function revolve(depth)
  51.   for i=1, 4 do -- dig four sides
  52.     if turtle.dig() then Count=Count+1 end
  53.     turtle.turnRight()
  54.   end
  55.  
  56.   if turtle.digDown() then Count=Count+1 end
  57.  
  58.   if turtle.getFuelLevel() > depth + 10 then
  59.     return turtle.down() -- return true/false
  60.   else
  61.     return false -- if fuel shortage
  62.   end
  63. end
  64.  
  65. function closeHole()
  66.   turtle.select(LID_BLOCK_SLOT)
  67.  
  68.   turtle.down()
  69.   for i=1,4 do
  70.     turtle.place()
  71.     turtle.turnRight()
  72.   end
  73.   turtle.up()
  74.   turtle.placeDown()
  75. end
  76.  
  77. function backToHome(n)
  78.   for i=1, n do -- back to home position.
  79.     turtle.up()
  80.   end
  81. end
  82.  
  83. -- ########## main
  84. myRefuel()
  85.  
  86. if CLOSE_HOLE_FLAG then
  87.   local err_msg = string.format("Insert 5 Lid-Blocks into slot %d",LID_BLOCK_SLOT)
  88.   assert(turtle.getItemCount(LID_BLOCK_SLOT) >= 5, err_msg)
  89. end
  90.  
  91. local depth = 0
  92. while revolve(depth) do
  93.     print("Depth: ",depth)
  94.   depth = depth +1
  95. end
  96.  
  97. backToHome(depth)
  98. if CLOSE_HOLE_FLAG then closeHole() end
  99. print("Result: ",Count," blocks")
  100. print("Current Fuel: ",turtle.getFuelLevel())
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top