SHARE
TWEET

ComputerCraft Tutorial: fortune_block_breaker_0_2

hevohevo Feb 25th, 2014 888 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ######################################
  2. -- Fortune Block Breaker
  3. -- version 0.2
  4. -- http://hevohevo.hatenablog.com/
  5. -- This Program requires a Fortune Mining Turtle by "More Turtles" mod
  6. --  http://www.computercraft.info/forums2/index.php?/topic/16465-mc164152-more-turtles-v112/
  7.  
  8. -- Side view
  9. -- T: fortune mining turtle, B: chest for blocks, I: chest for items
  10. --   B
  11. --   T
  12. --   I
  13.  
  14. -- Config
  15. BLOCK_SLOT = 1
  16. FUEL_SLOT = 16
  17. SUCK_FUNC = turtle.suckUp
  18. DROP_FUNC = turtle.dropDown
  19.  
  20.  
  21. local p = peripheral.wrap("right")
  22. assert((p and p.digFortune), "required Fortune Mining Turtle")
  23.  
  24. -- Functions
  25. function suckBlock() -- return true/false
  26.   turtle.select(BLOCK_SLOT)
  27.   if turtle.getItemCount(BLOCK_SLOT) > 0 then
  28.     return true
  29.   else
  30.     return SUCK_FUNC()
  31.   end
  32. end
  33.  
  34. function waitForEnoughFuel(minLevel, slot)
  35.   local qty = 0
  36.   local refuel = function()
  37.     turtle.select(slot)
  38.     turtle.refuel()
  39.     qty = turtle.getFuelLevel()
  40.     print("fuel: ",qty)
  41.     return qty
  42.   end
  43.  
  44.   while refuel() < minLevel do
  45.     print(string.format("Insert fuel-items into slot %d: %d/%d", slot, qty, minLevel))
  46.     os.sleep(1)
  47.     os.pullEvent("turtle_inventory")
  48.   end
  49. end
  50.  
  51. function placeDig(count)
  52.   waitForEnoughFuel(count, FUEL_SLOT)
  53.   for i=1,count do
  54.     turtle.select(BLOCK_SLOT)
  55.     turtle.place()
  56.     p.digFortune()
  57.   end
  58. end
  59.  
  60. function dropSeq()
  61.   for i=1,16 do
  62.     turtle.select(i)
  63.     if not DROP_FUNC() then break end
  64.   end
  65. end
  66.  
  67. -- Main
  68. print("Start: fortune BB")
  69. while suckBlock() do
  70.   placeDig(turtle.getItemCount(BLOCK_SLOT))
  71.   dropSeq()
  72. end
  73. print("Finished: fuel ",turtle.getFuelLevel())
RAW Paste Data
Top