arbarr3

farm

Apr 17th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. local args = { ... }
  2.  
  3. numArgs = table.getn(args)
  4.  
  5. crop = {["minecraft:potatoes"]="minecraft:potato", ["minecraft:carrots"]="minecraft:carrot", ["minecraft:wheat"]="minecraft:wheat_seeds"}
  6.  
  7. function fuel ()
  8. if turtle.getFuelLevel() == 0 then
  9. turtle.select(1)
  10. turtle.refuel(1)
  11. end
  12. end
  13.  
  14. function scan ()
  15. worked, data = turtle.inspectDown()
  16. if data["metadata"] == 7 then
  17. return data["name"]
  18. else
  19. return false
  20. end
  21. end
  22.  
  23. function farm (planted)
  24. toPlant = crop[planted]
  25. found = false
  26. slot = 1
  27. while not found and slot < 16 do
  28. check = turtle.getItemDetail(slot)
  29. if check ~= nil then
  30. if check["name"] == toPlant then
  31. turtle.select(slot)
  32. found = true
  33. end
  34. end
  35. slot = slot + 1
  36. end
  37. turtle.digDown()
  38. if turtle.getItemCount() > 0 then
  39. turtle.placeDown()
  40. end
  41. end
  42.  
  43. function move (x, y)
  44. y = y or x
  45.  
  46. for i = 1, x do
  47. for j = 1, y do
  48. planted = scan()
  49. if planted ~= false then
  50. farm(planted)
  51. end
  52. fuel()
  53. turtle.forward()
  54. end
  55. if scan() then
  56. farm()
  57. end
  58. if (i % 2 == 0) then
  59. turtle.turnLeft()
  60. fuel()
  61. turtle.forward()
  62. turtle.turnLeft()
  63. else
  64. turtle.turnRight()
  65. fuel()
  66. turtle.forward()
  67. turtle.turnRight()
  68. end
  69. end
  70. end
  71. --================Main===============--
  72.  
  73. if numArgs == 1.0 then
  74. move(tonumber(args[1]))
  75. elseif numArgs == 2.0 then
  76. move(tonumber(args[1]), tonumber(args[2]))
  77. else
  78. error("Place at bootom left corner, and use below:")
  79. error("Usage: farm [int xDim & yDim] [int yDim]")
  80. end
Advertisement
Add Comment
Please, Sign In to add comment