Advertisement
Griffen8280

Turtle Planting

Aug 5th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.86 KB | None | 0 0
  1. --Ensure that the turtle is in the middle block of the wall 2 high from the ground in the back of the farm
  2. --The turtle also needs to be facing toward the farm so make sure to orient it correctly after placing it
  3. --This can be accomplished with turtle.turnLeft(2) or similar after placing it down from the lua prompt.
  4.  
  5. --Functions
  6.  
  7. local function refuel()  --This refuels the turtle or instructs the player through the computer when he needs more coal
  8.     while turtle.getFuelLevel() < 50 do
  9.         term.write( "I need "..( 236 - turtle.getFuelLevel() ).." more fuel" )
  10.         term.write( "Checking for fuel..." )
  11.         rednet.send(0, "fuel")
  12.         for i = 1, 16 do
  13.           turtle.select( i )
  14.           turtle.refuel()
  15.         end
  16.         term.write( "Checked for fuel...")
  17.     end
  18.     term.write( "I have got enough fuel...")
  19.     turtle.select(1)
  20.     rednet.send(0, "full")
  21. end
  22.  
  23. local function place()  --This is the loop that does all the planting
  24.     for x=1, 7 do --repeats code 7 times
  25.         turtle.placeDown() -- can only go 1 block at a time thus the for loop
  26.         turtle.forward()
  27.         turtle.placeDown() -- for end of row planting.  will only work if possible otherwise it errors and keeps moving.
  28.         if turtle.getItemCount() < 1 then --Checks to see if the slot is empty and switches to the next
  29.             turtle.select(2)
  30.             if turtle.getItemCount() < 1 then  --Checks to see if the slot is empty and switches to the next
  31.                 turtle.select(3)
  32.                 if turtle.getItemCount() < 1 then --Checks to see if the slot is empty and switches to the next
  33.                     turtle.select(4)
  34.                 end
  35.             end
  36.         end
  37.     end
  38. end
  39.  
  40. local function reset()  --Essentially this just turns the turtle around
  41.     turtle.turnLeft()
  42.     turtle.turnLeft()
  43. end
  44.  
  45. local function left()  --Function to clean up the code in the main work functions
  46.     turtle.turnLeft()
  47.     turtle.forward()
  48.     turtle.turnLeft()
  49. end
  50.  
  51. local function right()  --Function to clean up the code in the main work functions
  52.     turtle.turnRight()
  53.     turtle.forward()
  54.     turtle.turnRight()
  55. end
  56.  
  57. local function empty()  --Function to empty the inventory of the turtle
  58.     turtle.select(1)
  59.     turtle.drop()
  60.     turtle.select(2)
  61.     turtle.drop()
  62.     turtle.select(3)
  63.     turtle.drop()
  64.     turtle.select(4)
  65.     turtle.drop()
  66. end
  67.  
  68. local function get()  --Function to fill the inventory of the turtle
  69.     turtle.suck()
  70.     turtle.select(2)
  71.     turtle.suck()
  72.     turtle.select(3)
  73.     turtle.suck()
  74.     turtle.select(4)
  75.     turtle.suck()
  76.     turtle.select(1)
  77. end
  78.  
  79. local function leftplanting()  --Loop for the entire planting process
  80.     for a=1, 3 do  --This cycles through the planting levels
  81.         for i=1, 4 do  --This cycles through the planting pads
  82.             if (i % 2 == 0) then
  83.                 place()
  84.                 right()
  85.             else
  86.                 place()
  87.                 left()
  88.             end
  89.         end
  90.     turtle.down()
  91.     refuel()
  92.     end
  93. end
  94.  
  95. local function rightplanting()  --Loop for the entire planting process
  96.     for a=1, 3 do  --This cycles through the planting levels
  97.         for i=1, 4 do  --This cycles through the planting pads
  98.             if (i % 2 == 0) then
  99.                 place()
  100.                 left()
  101.             else
  102.                 place()
  103.                 right()
  104.             end
  105.         end
  106.     turtle.down()
  107.     refuel()
  108.     end
  109. end
  110.  
  111. local function carrots()
  112.     refuel()
  113.     turtle.turnLeft()  --Place this chest on the right of the turtle as your facing it
  114.     get()
  115.     turtle.turnRight()
  116.     turtle.forward()
  117.     turtle.turnRight()
  118.     turtle.forward()
  119.     turtle.forward()
  120.     sleep(0.1)
  121.     turtle.down()
  122.     turtle.down()
  123.     leftplanting()
  124.     reset()
  125.     turtle.up()
  126.     turtle.up()
  127.     turtle.forward()
  128.     turtle.forward()
  129.     turtle.turnLeft()
  130.     for i=1, 12 do
  131.         turtle.forward()
  132.     end
  133.     refuel()
  134.     turtle.turnRight()
  135.     turtle.forward()
  136.     turtle.forward()
  137.     sleep(0.1)
  138.     turtle.down()
  139.     turtle.down()
  140.     rightplanting()
  141.     reset()
  142.     turtle.up()
  143.     turtle.up()
  144.     turtle.forward()
  145.     turtle.forward()
  146.     turtle.turnRight()
  147.     for i=1, 14 do
  148.         turtle.forward()
  149.     end
  150.     reset()
  151.     turtle.turnLeft()
  152.     empty()
  153.     turtle.turnRight()
  154.     rednet.send(0, "done")  --Be sure to set this number to the id of the control computer
  155.     os.reboot()
  156. end
  157.  
  158. local function potatoes()
  159.     refuel()
  160.     turtle.turnRight()  --Place this chest on the left of the turtle as your facing it
  161.     get()
  162.     turtle.turnLeft()
  163.     turtle.forward()
  164.     turtle.turnRight()
  165.     turtle.forward()
  166.     turtle.forward()
  167.     sleep(0.1)
  168.     turtle.down()
  169.     turtle.down()
  170.     leftplanting()
  171.     reset()
  172.     turtle.up()
  173.     turtle.up()
  174.     turtle.forward()
  175.     turtle.forward()
  176.     turtle.turnLeft()
  177.     for i=1, 12 do
  178.         turtle.forward()
  179.     end
  180.     refuel()
  181.     turtle.turnRight()
  182.     turtle.forward()
  183.     turtle.forward()
  184.     sleep(0.1)
  185.     turtle.down()
  186.     turtle.down()
  187.     rightplanting()
  188.     reset()
  189.     turtle.up()
  190.     turtle.up()
  191.     turtle.forward()
  192.     turtle.forward()
  193.     turtle.turnRight()
  194.     for i=1, 14 do
  195.         turtle.forward()
  196.     end
  197.     reset()
  198.     turtle.turnRight()
  199.     empty()
  200.     turtle.turnLeft()
  201.     rednet.send(0, "done")  --Be sure to set this number to the id of the control computer
  202.     os.reboot()
  203.  
  204. end
  205.  
  206. local function wheat()
  207.     refuel()
  208.     reset()  --Place this chest behind the turtle as your facing it
  209.     get()
  210.     reset()
  211.     turtle.forward()
  212.     turtle.turnRight()
  213.     turtle.forward()
  214.     turtle.forward()
  215.     sleep(0.1)
  216.     turtle.down()
  217.     turtle.down()
  218.     leftplanting()
  219.     reset()
  220.     turtle.up()
  221.     turtle.up()
  222.     turtle.forward()
  223.     turtle.forward()
  224.     turtle.turnLeft()
  225.     for i=1, 12 do
  226.         turtle.forward()
  227.     end
  228.     refuel()
  229.     turtle.turnRight()
  230.     turtle.forward()
  231.     turtle.forward()
  232.     sleep(0.1)
  233.     turtle.down()
  234.     turtle.down()
  235.     rightplanting()
  236.     reset()
  237.     turtle.up()
  238.     turtle.up()
  239.     turtle.forward()
  240.     turtle.forward()
  241.     turtle.turnRight()
  242.     for i=1, 14 do
  243.         turtle.forward()
  244.     end
  245.     empty()
  246.     reset()
  247.     rednet.send(0, "done")  --Be sure to set this number to the id of the control computer
  248.     os.reboot()
  249.  
  250. end
  251.  
  252. --Main Program
  253.  
  254. rednet.open("right")
  255. while true do
  256.     id, msg = rednet.receive(0)  --Be sure to set this number to the id of the control computer
  257.     if msg == "carrots" then
  258.         carrots()
  259.         else if msg == "potatoes" then
  260.             potatoes()
  261.             else if msg == "wheat" then
  262.                 wheat()
  263.             end
  264.         end
  265.     end
  266. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement