SHARE
TWEET

ComputerCraft Tutorial: auto_craft0_2

hevohevo Dec 4th, 2013 827 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ###########################
  2. -- auto_craft
  3. -- version 0.2.1
  4. -- http://hevohevo.hatena.com/
  5. -- ###########################
  6.  
  7. -- ###########################
  8. -- Turtle position (Side view)
  9. -- T: crafty turtle, M: chest for materials, P: chest for products
  10.  
  11. -- M
  12. -- T
  13. -- P
  14.  
  15. -- ###########################
  16. -- config
  17. MATERIAL_SLOT = 1
  18. PRODUCT_SLOT = 4
  19.  
  20. -- ###########################
  21. -- functions
  22.  
  23. function dropItems(begin_slot, end_slot)
  24.   print('drop items: slots ',begin_slot,'-',end_slot)
  25.   for i=begin_slot, end_slot do
  26.     turtle.select(i)
  27.     turtle.dropDown()
  28.   end
  29.   turtle.select(1)
  30. end
  31.  
  32. function getMaterials()
  33.   turtle.select(MATERIAL_SLOT)
  34.   if turtle.getItemCount(MATERIAL_SLOT) ==0 and turtle.suckUp() then
  35.     print(' Success: suckUp')
  36.     return true
  37.   else
  38.     print(' Failed: suckUp')
  39.     return false
  40.   end
  41. end
  42.  
  43. function craft1x1()
  44.   -- repeat 1x1-craft while material > 0
  45.   while  turtle.getItemCount(MATERIAL_SLOT) >0 do
  46.     if turtle.craft(0) == false then break end
  47.     turtle.select(PRODUCT_SLOT)
  48.     turtle.craft()
  49.     turtle.dropDown()
  50.   end
  51. end
  52.  
  53. -- ###########################
  54. -- main
  55. dropItems(1,16)
  56. while getMaterials() do
  57.   craft1x1()
  58.   dropItems(1,4)
  59. end
  60. dropItems(1,16)
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top