asweigart

eggcollect

Jul 31st, 2016
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. -- Egg Collrector program
  2. -- By Al Sweigart
  3. -- Collects eggs in a field.
  4.  
  5. --[[
  6. IMPORTANT NOTE!!!
  7. Planted potatoes in the game world are
  8. named 'minecraft:potatoes' but potatoes
  9. in your inventory are called
  10. 'minecraft:potato'
  11. ]]
  12.  
  13. os.loadAPI('hare')
  14.  
  15. local cliArgs = {...}
  16. local rowsArg = tonumber(cliArgs[1])
  17. local columnsArg = tonumber(cliArgs[2])
  18.  
  19. if columnsArg == nil then
  20. print('Usage: eggcollect rows columns')
  21. return
  22. end
  23.  
  24.  
  25. function storeItems()
  26. if not hare.findBlock('minecraft:chest') then -- face the chest
  27. print('Warning: Could not find chest.')
  28. return
  29. end
  30.  
  31. -- drop off items
  32. local slot
  33. for slot=1,16 do
  34. turtle.select(slot)
  35. turtle.drop()
  36. end
  37.  
  38. -- face field again
  39. turtle.turnLeft()
  40. turtle.turnLeft()
  41. end
  42.  
  43.  
  44. print('Hold Ctrl+T to stop.')
  45. if not hare.findBlock('minecraft:chest') then
  46. print('ERROR: Must start next to a chest!')
  47. end
  48.  
  49. -- face field
  50. turtle.turnLeft()
  51. turtle.turnLeft()
  52.  
  53. while true do
  54. -- check fuel
  55. if turtle.getFuelLevel() < (rowsArg * columnsArg) + rowsArg + columnsArg then
  56. print('ERROR: Not enough fuel.')
  57. return
  58. end
  59.  
  60. -- farm potatoes
  61. print('Sweeping field...')
  62. hare.sweepField(rowsArg, columnsArg, turtle.suckDown, storeItems)
  63.  
  64. print('Sleeping for 5 minutes...')
  65. os.sleep(300)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment