Advertisement
hevohevo

ComputerCraft Tutorial: cultivate0_3

Nov 3rd, 2013
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. -- ########################
  2. -- cultivate <n>
  3. -- version 0.3
  4. -- ########################
  5.  
  6. -- #############
  7. -- config
  8. ARGS = {...}
  9. MAX = ARGS[1]
  10. SEED_SLOT = 1
  11. MEAL_SLOT = 2
  12.  
  13. -- ##################
  14. -- define functions
  15. function plantSeed()
  16.   turtle.select(SEED_SLOT)
  17.   if turtle.place() then
  18.     return true
  19.   else
  20.     print('failed: plantSeed')
  21.     return false
  22.   end
  23. end
  24.  
  25. function getMeals()
  26.   turtle.select(MEAL_SLOT)
  27.   if turtle.suckUp() then
  28.     -- succeed in sucking meals
  29.     if turtle.getItemCount(MEAL_SLOT) < 4 then
  30.       -- but, meals < 4
  31.       print('failed: getMeals, meal < 4 ')
  32.       return false
  33.     else
  34.       -- ok, meals > 3
  35.       print('getMeals')
  36.       return true
  37.     end
  38.   else
  39.     -- failed to sucking meals
  40.     print('failed: suckUp')
  41.     return false
  42.   end
  43. end
  44.  
  45.  
  46. function dropItems(begin_slot, end_slot)
  47.   print('drop items: slots ',begin_slot,'-',end_slot)
  48.   for i=begin_slot, end_slot do
  49.     turtle.select(i)
  50.     turtle.dropDown()
  51.   end
  52.   turtle.select(1)
  53. end
  54.  
  55. function useMeals()
  56.   if turtle.getItemCount(MEAL_SLOT) < 4 then
  57.     if getMeals()==false then
  58.       return false
  59.     end
  60.   end
  61.  
  62.   turtle.select(MEAL_SLOT)
  63.   turtle.place()
  64.   turtle.place()
  65.   turtle.place()
  66.   return true
  67. end
  68.  
  69. -- useMeals() and useMeals2() are the same functions.
  70. function useMeals2()
  71.   if (turtle.getItemCount(MEAL_SLOT) < 4) and (getMeals()==false) then
  72.     return false
  73.   else
  74.     turtle.select(MEAL_SLOT)
  75.     turtle.place()
  76.     turtle.place()
  77.     turtle.place()
  78.     return true
  79.   end
  80. end
  81.  
  82. function harvest()
  83.   turtle.select(SEED_SLOT)
  84.   turtle.dig()
  85. end
  86.  
  87. -- ##################
  88. -- Main
  89. turtle.dig()
  90. for i=1,MAX do
  91.   print(i,'/',MAX)
  92.  
  93.   if plantSeed() == false then break end
  94.   if useMeals() == false then break end
  95.  
  96.   harvest()
  97.  
  98.   if i%50==0 then dropItems(3,16) end
  99.  
  100. end
  101.  
  102. dropItems(3,16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement