Advertisement
hevohevo

ComputerCraft Tutorial: cultivate0_4

Nov 5th, 2013
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. -- ########################
  2. -- cultivate <n>
  3. -- version 0.4
  4. -- http://hevohevo.hatenablog.com/
  5. -- ########################
  6.  
  7. -- #############
  8. -- config
  9. ARGS = {...}
  10. MAX = ARGS[1]
  11. SEED_SLOT = 1
  12. MEAL_SLOT = 2
  13.  
  14. -- ##################
  15. -- define functions
  16. function plantSeed()
  17.   turtle.select(SEED_SLOT)
  18.   if turtle.place() then
  19.     return true
  20.   else
  21.     print('failed: plantSeed')
  22.     return false
  23.   end
  24. end
  25.  
  26. function dropItems(begin_slot, end_slot)
  27.   print('drop items: slots ',begin_slot,'-',end_slot)
  28.   for i=begin_slot, end_slot do
  29.     turtle.select(i)
  30.     turtle.dropDown()
  31.   end
  32.   turtle.select(1)
  33. end
  34.  
  35. function useOneMeal()
  36.   if (turtle.getItemCount(MEAL_SLOT) ==0) and (turtle.suckUp()==false) then
  37.     print('failed: suckUp, and meal = 0')
  38.     return false
  39.   else
  40.     turtle.select(MEAL_SLOT)
  41.     turtle.place()
  42.     return true
  43.   end
  44. end
  45.  
  46. function useMeals()
  47.   local flag = true
  48.   for i=1,3 do
  49.     if useOneMeal() == false then
  50.       flag = false
  51.       break
  52.     end
  53.   end
  54.   return flag
  55. end
  56.  
  57. function harvest()
  58.   turtle.select(SEED_SLOT)
  59.   turtle.dig()
  60. end
  61.  
  62. -- ##################
  63. -- Main
  64. turtle.dig()
  65. for i=1,MAX do
  66.   print(i,'/',MAX)
  67.  
  68.   if plantSeed() == false then break end
  69.   if useMeals() == false then break end
  70.  
  71.   harvest()
  72.  
  73.   if i%50==0 then dropItems(3,16) end
  74.  
  75. end
  76. dropItems(3,16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement