Advertisement
HandieAndy

Planter

Feb 3rd, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. local args = {...}
  2. local length
  3. local width
  4. if (args[1] ~= nil) then
  5.   length = tonumber(args[1])
  6. end
  7. if (args[2] ~= nil) then
  8.   width = tonumber(args[2])
  9. end
  10.  
  11. function atGround()
  12.   local success,data = turtle.inspectDown()
  13.   if (data ~= nil and (data.name == "minecraft:grass" or data.name == "minecraft:dirt")) then
  14.     return true
  15.   else
  16.     return false
  17.   end
  18. end
  19.  
  20. function placeWheat()
  21.   while (not atGround()) do
  22.     if (not turtle.down()) then
  23.       if (not turtle.digDown()) then
  24.         print("Unable to go down. Please ensure there is dirt under the turtle. Then press enter.")
  25.         read()
  26.       end
  27.     end
  28.   end
  29.   while (not turt.select("minecraft:wheat_seeds")) do
  30.     print("Add more seeds and press enter.")
  31.     read()
  32.   end
  33.   turtle.up()
  34.   turtle.digDown()
  35.   turtle.placeDown()
  36. end
  37.  
  38. function moveForward()
  39.   while (turtle.detect()) do
  40.     while (not turtle.up()) do
  41.       print("Vertical obstruction. Remove and press enter.")
  42.       read()
  43.     end
  44.   end
  45.   while (not turtle.forward()) do
  46.     print("Obstruction. Trying again.")
  47.   end
  48. end
  49.  
  50. function row()
  51.   for i=1,length do
  52.     placeWheat()
  53.     moveForward()
  54.   end
  55. end
  56.  
  57. function main()
  58.   for i=1,width do
  59.     row()
  60.     if (i % 2 == 0) then
  61.       turtle.turnLeft()
  62.       moveForward()
  63.       turtle.turnLeft()
  64.     else
  65.       turtle.turnRight()
  66.       moveForward()
  67.       turtle.turnRight()
  68.     end
  69.     moveForward()
  70.   end
  71. end
  72.  
  73. if (not fs.exists("turt")) then
  74.     print("Installing Turt API.")
  75.     shell.run("pastebin get 7jXkEZX6 turt")
  76. end
  77.  
  78. os.loadAPI("turt")
  79. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement