Advertisement
dadragon84

do_veggiesplant

Feb 26th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.78 KB | None | 0 0
  1. -- do_veggiesplant
  2. -----------------------------------------------------------------------
  3. --[[
  4. ("This program is currently intended for use with melon and pumpkin farms")
  5. ("The turtle must be placed with 1 empty block between the first possible farm item and the turtle")
  6. ("There must be a chest to the right of where the turtle is placed before starting the program to ensure correct dropoff")
  7. ("This program assumes a 4 wide system for Melons and Pumpkins, the length is variable:")
  8. ("D = Dirt(or other): W = Water: S = Seed: C = Chest: T = Turtle: M = Melon or Pumpkin Crop")
  9. ("      W   DDDDDDDDDDDD      ")
  10. ("      I   DSSSSSSSSSSDC     ")
  11. ("      D   DMMMMMMMMMM T     ")
  12. ("      T   DMMMMMMMMMM       ")
  13. ("      H   DSSSSSSSSSSD      ")
  14. ("          DWWWWWWWWWWD      ")
  15. ("              LENGTH        ")
  16. --]]
  17. term.clear()
  18. term.setCursorPos(1, 1)
  19. minerID = os.getComputerID()
  20. turtleName = nil
  21. consoleID = 0
  22. version = "1.0"
  23. function getConsoleID()
  24.   local fname = "ConsoleID"
  25.   if fs.exists(fname) then
  26.     file = fs.open(fname, "r")
  27.     consoleID = tonumber(file.readAll())
  28.     file.close()
  29.     print("Monitor Console ID: "..consoleID)
  30.   else
  31.     updateStatus("Waiting for Console ID...",true)
  32.     term.write("Monitor Console ID: ")
  33.     consoleID = io.read()
  34.     file = fs.open(fname, "w")
  35.     file.write(consoleID)
  36.     file.close()
  37.     consoleID = tonumber(consoleID)
  38.   end
  39. end
  40. function updateStatus(msg, silent)
  41.   if not rednet.isOpen("right") then rednet.open("right") end
  42.   if rednet.isOpen("right") then
  43.     if turtleName == nil then return end
  44.     networkmsg = "MM:"..turtleName..": "..msg
  45.     if consoleID == 0 then
  46.       rednet.broadcast(networkmsg)
  47.     else
  48.       rednet.send(consoleID,networkmsg)
  49.     end
  50.   end
  51.   if not silent then print(msg) end
  52. end
  53. function getTurtleName()
  54.   local fname = "TurtleName"
  55.   if fs.exists(fname) then
  56.     file = fs.open(fname, "r")
  57.     turtleName = file.readAll()
  58.     file.close()
  59.   else
  60.     term.write("Turtle Name: ")
  61.     turtleName = io.read()
  62.     file = fs.open(fname, "w")
  63.     file.write(turtleName)
  64.     file.close()
  65.   end
  66. end
  67. -- Main Program
  68. updateStatus("Starting")
  69. term.clear()
  70. term.setCursorPos(1,1)
  71. getTurtleName()
  72. getConsoleID()
  73. function update()
  74. end
  75. function fuelItUp()
  76.   updateStatus("...Working")
  77. --Finds out if the turtle needs to refuel and if it has fuel to run
  78.   needsFuel = turtle.getFuelLevel()
  79.   minimumFuelLevel = 10
  80.   hasFuel = turtle.getItemCount(16)
  81.   useFuel = turtle.refuel()
  82.   if needsFuel == "unlimited" then
  83.    
  84.   else
  85.     if tonumber(needsFuel) < tonumber(minimumFuelLevel) then
  86.       if hasFuel > 0 then
  87.         turtle.select(16)
  88.         turtle.refuel(1)
  89.         turtle.select(1)
  90.       else
  91.         updateStatus("Please insert fuel into slot 16")
  92.         repeat os.sleep(1)
  93.         until tonumber(turtle.getItemCount(16)) > 0
  94.         fuelItUp()
  95.       end
  96.     end
  97.   end
  98. end
  99. function questions()
  100.   print("How many blocks deep?")
  101.   length = io.read()
  102.   prime()
  103. end
  104. function prime()
  105.   fuelItUp()
  106.   hasSeeds = turtle.getItemCount(15)
  107.   if tonumber(hasSeeds) > 0 then
  108.     primePosition()
  109.   else
  110.     updateStatus("Please put Seeds into slot 15")
  111.     os.sleep(5)
  112.     prime()
  113.   end  
  114. end
  115. function primePosition()
  116.   i = 0
  117.   startBlock = 0
  118.   totalPlanted = 0
  119.   turtle.up()
  120.   turtle.forward()
  121.   turtle.forward()
  122.   turtle.forward()
  123.   plantingDown()
  124. end
  125. function plantingDown()
  126.   turtle.select(1)
  127.   while i ~= tonumber(length) do
  128.     fuelItUp()
  129.    
  130.     plantBot = turtle.detectDown()
  131.     if plantBot == false then
  132.       turtle.digDown()
  133.       turtle.select(15)
  134.       turtle.placeDown()
  135.       totalPlanted = totalPlanted + 1
  136.     end
  137.     if turtle.getItemCount(14) > 0 then
  138.         turtle.select(14)
  139.         turtle.placeDown()
  140.     end
  141.     turtle.forward()
  142.     i = i + 1
  143.   end
  144.   turn()
  145. end
  146. function turn()
  147.   turtle.turnLeft()
  148.   turtle.forward()
  149.   turtle.forward()
  150.   turtle.forward()
  151.   turtle.turnLeft()
  152.   plantingBack()
  153. end
  154. function plantingBack()
  155.   while i ~=  startBlock do
  156.     fuelItUp()
  157.     plantBot = turtle.detectDown()
  158.     if plantBot == false then
  159.       turtle.digDown()
  160.       turtle.select(15)
  161.       turtle.placeDown()
  162.       totalPlanted = totalPlanted + 1
  163.     end
  164.     if turtle.getItemCount(14) > 0 then
  165.         turtle.select(14)
  166.         turtle.placeDown()
  167.       end
  168.     turtle.forward()
  169.     i = i - 1
  170.   end
  171.   finish()
  172. end
  173. function finish()
  174. updateStatus("Finished")
  175.   turtle.forward()
  176.   turtle.forward()
  177.   turtle.turnLeft()
  178.   turtle.forward()
  179.   turtle.forward()
  180.   turtle.forward()
  181.   turtle.down()
  182.   turtle.turnLeft()
  183.   turtle.select(15)
  184.   turtle.drop()
  185.   turtle.select(14)
  186.   turtle.drop()
  187.   print("Total Plants Planted:")
  188.   print(totalPlanted)
  189.   updateStatus("Total Plants Planted:  " ..totalPlanted)
  190. end
  191.  
  192. questions()
  193. print("Press Enter to Continue")
  194. io.read()
  195. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement