Advertisement
asweigart

eggcollect

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