Advertisement
hevohevo

ComputerCraft Tutorial: boring_0_2

Feb 14th, 2014
5,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. -- ################################
  2. -- Boring by mining turtle
  3. -- version 0.2
  4. -- http://hevohevo.hatenablog.com/
  5.  
  6. -- ########## config
  7. MIN_FUEL_LEVEL = 400
  8. CLOSE_HOLE_FLAG = true -- boolean. whether close a hole
  9. LID_BLOCK_SLOT = 1
  10.  
  11. local args={...}
  12. -- reverse CLOSE_HOLE flag
  13. if #args > 0 then
  14.   CLOSE_HOLE_FLAG = not CLOSE_HOLE_FLAG
  15. end
  16.  
  17. -- ########## functions
  18. function myRefuel()
  19.   local function refuelAll()
  20.     for i=1, 16 do
  21.       turtle.select(i)
  22.       turtle.refuel()
  23.     end
  24.     print("Fuel: ",turtle.getFuelLevel(), " (required: ",MIN_FUEL_LEVEL,")")
  25.   end
  26.  
  27.   refuelAll()
  28.   while turtle.getFuelLevel() < MIN_FUEL_LEVEL do
  29.     os.sleep(1)
  30.     -- wait for putting items in inventory
  31.     os.pullEvent("turtle_inventory")
  32.     refuelAll()
  33.   end
  34.  
  35.   turtle.select(1)
  36. end
  37.  
  38. function revolve(depth)
  39.   for i=1, 4 do -- dig four sides
  40.     turtle.dig()
  41.     turtle.turnRight()
  42.   end
  43.  
  44.   turtle.digDown() -- dig down side
  45.  
  46.   if turtle.getFuelLevel() > depth then
  47.     return turtle.down() -- return true/false
  48.   else
  49.     return false -- if fuel shortage
  50.   end
  51. end
  52.  
  53. function closeHole()
  54.   turtle.select(LID_BLOCK_SLOT)
  55.   turtle.down()
  56.  
  57.   for i=1,4 do
  58.     turtle.place()
  59.     turtle.turnRight()
  60.   end
  61.  
  62.   turtle.up()
  63.   turtle.placeDown()
  64. end
  65.  
  66. function backToHome(n)
  67.   for i=1, n do -- back to home position.
  68.     turtle.up()
  69.   end
  70. end
  71.  
  72. -- ########## main
  73. myRefuel()
  74.  
  75. local depth = 0
  76. while revolve(depth) do
  77.   depth = depth +1
  78. end
  79.  
  80. backToHome(depth)
  81. if CLOSE_HOLE_FLAG then closeHole() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement