BruceWplays

Farm old V8

Sep 13th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. version = "5"
  2. term.clear()
  3. term.setCursorPos(1, 1)
  4. --print(version)
  5. done = 0
  6.  
  7. --for l=1,10 do
  8. --if fs.exists("farmapi/gt") == false then do
  9.     --print("downloading goto api")
  10.     --shell.run("mkdir","farmapi")
  11.     --shell.run("cd","farmapi")
  12.     --shell.run("pastebin","get","a3GBewNp","gt")
  13.     --shell.run("cd","..")
  14.         --if fs.exists("farmapi/gt") == true then
  15.             --print("download complete")
  16.                 --elseif fs.exists("farmapi/gt") == false then
  17.                     --print("download failed")
  18.                 --end
  19. --end
  20.  
  21.  
  22. shell.run("AndysPrograms/api/update", "gt", "a3GBewNp", "AndysPrograms/api", "none", "none")
  23. --else do
  24.            
  25.   term.clear()
  26.   term.setCursorPos(1, 1)                          
  27.  
  28.  os.loadAPI("AndysPrograms/api/gt")  
  29.  
  30.  
  31.  
  32.  
  33.  if fs.exists("AndysPrograms/Farm/settings") then
  34.     settings.load("AndysPrograms/Farm/settings")
  35. end
  36. local maxW, maxH = term.getSize()
  37.  
  38.  
  39.  
  40. function exit()
  41.     term.clear()
  42.     term.setCursorPos(1, 1)
  43.     print("Starting")
  44.     openset = 0
  45. end
  46. function chngset()
  47.     chngsel = 1
  48. end
  49.  
  50. function savesets()
  51.     settings.save("AndysPrograms/Farm/settings")
  52. end
  53. gpstab = {}
  54. local stgpsx, stgpsy, stgpsz = gps.locate(5)
  55. table.insert(gpstab, stgpsx)
  56. table.insert(gpstab, stgpsy)
  57. table.insert(gpstab, stgpsz)
  58. table.insert(gpstab, "n")
  59. if fs.exists("AndysPrograms/Farm/settings") == false then
  60.     if fs.exists("AndysPrograms/Farm") == false then
  61.       fs.makeDir("AndysPrograms/Farm")
  62.     end
  63.  
  64.  
  65.  
  66.  
  67.     srtbk = {"minecraft:pumpkin", "minecraft:reeds"}
  68.     settings.set("Farm Lenth", 1)
  69.     settings.set("Farm Width", 1)
  70.     settings.set("Mode", 2)
  71.     settings.set("Start Location", gpstab)
  72.     settings.set("Chest Location", gpstab)
  73.     settings.set("Sort Block Names", srtbk)
  74.     settings.set("Sort Blocks", 1)
  75.     settings.set("Chest Direction", 0)
  76.     savesets()
  77.  
  78.    
  79.    
  80.   end
  81. function resetmenu()
  82. deftab = {}
  83. setmenu = {}
  84. setmenu = {
  85.     {text = "Finish editing:", options = "Finish", handler = exit},
  86.     {text = "Farm Lenth", setname = "Farm Lenth", options = settings.get("Farm Lenth"), type = "num", handler = chngset},
  87.     {text = "Farm Width", setname = "Farm Width", options = settings.get("Farm Width"), type = "num", handler = chngset},
  88.     {text = "Mode, 1 = Nrml, 2 = Pump/Mel/SgrCne", setname = "Mode", options = settings.get("Mode"), type = "num", handler = chngset},
  89.     {text = "Start Location", setname = "Start Location", options = settings.get("Start Location"), type = deftab, handler = chngset},
  90.     {text = "Chest Location", setname = "Chest Location", options = settings.get("Chest Location"), type = deftab, handler = chngset},
  91.     {text = "Chest Direction 0=fwd 2=up 1=dn", setname = "Chest Direction", options = settings.get("Chest Direction"), type = "num", handler = chngset},
  92.     {text = "Sort Blocks", setname = "Sort Blocks", options = settings.get("Sort Blocks"), type = "num", handler = chngset},
  93.     {text = "Sort Block Names", setname = "Sort Block Names", options = settings.get("Sort Block Names"), type = deftab, handler = chngset}
  94. }
  95.  
  96. end
  97. resetmenu()
  98.  
  99. function addsettings(num, value)
  100.     settings.set(setmenu[num].setname, value)
  101.     savesets()
  102. end
  103.  
  104. openset = 1
  105.  
  106. farmargs = {...}
  107. if farmargs[1] == "noset" then
  108.     openset = 0
  109. end
  110.  
  111. while openset == 1 do
  112.  
  113.  
  114.  
  115.  
  116. if openset == 1 then
  117.     chngsel = 0
  118.     term.clear()
  119.     setsoffset = 1
  120.     selitem = 1
  121.     --if (maxH) < (#setmenu * 2) then
  122.     --    selitem = maxH / 2
  123.    -- elseif (maxH) > (#setmenu) then
  124.        --selitem = 1
  125.     --end
  126. function printmenu(menu)
  127.     for sets=1,#setmenu do
  128.        
  129.         setsmul = (sets * 2) - 1
  130.         if (setsmul + setsoffset) <= maxH then
  131.             term.setCursorPos(1, setsmul + setsoffset)
  132.             print(setmenu[sets].text)
  133.             if #setmenu[sets].text / maxW > 1 then
  134.                 --setsoffset = setsoffset + #setmenu[sets].text / maxW
  135.                 --setsoffset = setsoffset - 0.9
  136.             end
  137.             term.setCursorPos(1, (setsmul + 1) + setsoffset)
  138.             if setmenu[sets].options ~= nil then
  139.                 term.clearLine()
  140.                 prntset = setmenu[sets].options
  141.                 if (type(prntset) == "table") then
  142.                     prntset = table.concat(setmenu[sets].options, ", ")
  143.                 end
  144.                 if selitem == sets then
  145.                     if chngsel == 1 then
  146.                         input = read()
  147.                         if input then
  148.                             inptesset = setmenu[sets].type
  149.                             if type(inptesset) == "table" then
  150.                                 settingsinputtable = {}
  151.                                 input2 = string.gsub(input, ", ", ",")
  152.                                 --print(input)
  153.                                 for i in string.gmatch(input2, '([^,]+)') do
  154.                                     table.insert(settingsinputtable, i)
  155.                                 end
  156.                                 --print(input)
  157.                                 addsettings(selitem, settingsinputtable)
  158.                             end
  159.                             if type(inptesset) ~= "table" then
  160.                                 addsettings(selitem, input)
  161.                             end
  162.                             resetmenu()
  163.                             --print(chngsel)
  164.                             chngsel = 0
  165.                         end
  166.  
  167.                     else
  168.                         print(">  "..prntset)
  169.                     end
  170.                 else
  171.                     print("   "..prntset)
  172.                 end
  173.             end
  174.         end
  175.     end
  176. end
  177.     function onsel(menu, selected)
  178.         menu[selected].handler()
  179.     end
  180.  
  181.     function onkeypress(key, menu, selected)
  182.         if key == keys.enter or key == keys.space then
  183.             if chngsel == 0 then
  184.                 onsel(menu, selected)
  185.             end
  186.            -- if chngsel == 1 and (key == keys.enter or key == keys.space) then
  187.              --   chngsel = 0
  188.            -- end
  189.         elseif key == keys.up or key == keys.w then
  190.             if selitem > 1 then
  191.                 setsoffset = setsoffset + 2.1
  192.                 setsoffset = math.floor(setsoffset)
  193.                 selitem = selitem - 1
  194.             end
  195.         elseif key == keys.down or key == keys.s then
  196.             if selitem < (#menu) then
  197.                 setsoffset = setsoffset - 1.9
  198.                 setsoffset = math.floor(setsoffset)
  199.                 selitem = selitem + 1
  200.             end
  201.         elseif key == keys.q then
  202.             exit()
  203.         end
  204.     end
  205.  
  206. while openset == 1 do
  207.     term.setCursorPos(1, 1)
  208.     term.clear()
  209.     printmenu(setmenu)
  210.     event, key = os.pullEvent("key")
  211.     onkeypress(key, setmenu, selitem)
  212. end
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222. end
  223.  
  224.  
  225.  
  226. end
  227. while true do
  228. if done ~= 4 then do
  229.  
  230.  
  231.  
  232.                        
  233. ---------------------                        
  234. ---------------------                        
  235. ---------------------
  236. --CHANGE HERE START--
  237. ---------------------
  238. ---------------------                        
  239. ---------------------                        
  240.    
  241.  
  242.  
  243.  
  244.  
  245.                        
  246. --"1" is Normal, "2" is Pumpkin/Melon/Probably Sugar Cane                    
  247. Mode = tonumber(settings.get(setmenu[4].setname))
  248.  
  249. if Mode > 2 or Mode < 1 then
  250.     Mode = 2
  251. end
  252.  
  253.  
  254. Farm_Lenth = tonumber(settings.get(setmenu[2].setname))
  255. Farm_Width = tonumber(settings.get(setmenu[3].setname))
  256.  
  257.  
  258.  
  259.                      
  260. -- sort for specific crop                        
  261.  
  262. --whether or not to sort, 1 is yes, 0 is no                        
  263. sortblock = tonumber(settings.get(setmenu[8].setname))
  264. if sortblock > 1 or sortblock < 0 then
  265.     sortblock = 1
  266. end
  267.  
  268. --name of the crop                        
  269. crop_name = settings.get(setmenu[9].setname)                                        
  270.                        
  271. --max age of crop should probably be left at 7
  272. crop_max_age = 7                      
  273.                        
  274.                        
  275.                        
  276.                        
  277. --setup location
  278.     setuploc = settings.get(setmenu[5].setname)
  279.            
  280.                        
  281.                    
  282. --chest location                      
  283.     chestloc = settings.get(setmenu[6].setname)
  284.    
  285.  
  286.  
  287. --chest 2 = "up", 1 = "down", or 0 = "forward"                        
  288. chestdirection = tonumber(settings.get(setmenu[7].setname))
  289.      
  290. if chestdirection > 2 or chestdirection < 0 then
  291.     chestdirection = 2
  292. end
  293.     --misc
  294.                        
  295.                       --ignore if a crop has no age value should be set at 1 for Pumpkin/Melon and 0 for Normal
  296.                         Override_ignore_nil_age = 0
  297.                         ignore_nil_age = 1  
  298.                        
  299.                         override_stages = 0
  300.                         turnleftchest = 0
  301.                         totalstages = 1
  302.                        
  303.                        
  304. -------------------                        
  305. -------------------
  306. --CHANGE HERE END--
  307. -------------------        
  308. -------------------
  309.                        
  310.                        
  311.        
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341. --unused!!!! Recenter Values
  342. turn_right_recenter_times = 0
  343. forward_recenter_times = 0  
  344.  
  345. if Override_ignore_nil_age == 0 then
  346.    if Mode == 2 then                          
  347.          ignore_nil_age = 1
  348.    elseif Mode == 1 then                            
  349.          ignore_nil_age = 0                        
  350.    end                          
  351. end                    
  352.                        
  353. st_width = Farm_Width
  354. lenth = Farm_Lenth                      
  355. if override_stages == 1 then
  356. totalsteps = totalstages
  357.      if Mode == 2 then
  358.        grabstage = 5
  359.        elseif Mode == 1 then
  360.        grabstage = 2                        
  361.      end                              
  362. elseif Mode == 2 then
  363.    if override_stages == 0 then                        
  364.          grabstage = 5                  
  365.        totalstages = 1                    
  366.  totalsteps = 1  
  367.      end                                                      
  368.  elseif  Mode == 1 then
  369.    if override_stages == 0 then                        
  370.        grabstage = 2                    
  371.        totalstages = 2                    
  372.  totalsteps = 2  
  373.      end                          
  374.   end    
  375.  
  376. term.clear()
  377. term.setCursorPos(1, 1)
  378. print("Recentering")              
  379. totalsteps = totalstages                                              
  380. endsteps = totalsteps + 1                    
  381. sub_lenth = lenth - 1                      
  382. function chest()                        
  383.     term.clear()
  384.            term.setCursorPos(1, 1)                                
  385.           print("going to chest")                        
  386.           gt.goto(chestloc)            
  387.        if Mode == 2 then
  388.         chest = 1
  389.          elseif  Mode == 1 then                        
  390.        chest = 2
  391.                                        end
  392.            term.clear()
  393.            term.setCursorPos(1, 1)                          
  394.        print("putting in chest")
  395.        
  396.          
  397.        while chest <= 16 do
  398.        turtle.select(chest)
  399.      if chestdirection == 0 then  
  400.          turtle.drop()                              
  401.                                      
  402.            elseif chestdirection == 1 then
  403.                        
  404.        turtle.dropDown()
  405.        elseif chestdirection == 2 then                          
  406.          turtle.dropUp()
  407.                end                        
  408.                                        
  409.                                        
  410.        chest = chest + 1
  411.      end
  412.          if turnleftchest == 1 then
  413.              turtle.turnLeft()
  414.                                    end
  415.         term.clear()
  416.            term.setCursorPos(1, 1)                                
  417.           print("Resetting")                        
  418.       sleep(1)
  419.       os.reboot()                        
  420.     end                    
  421.     --chest()                          
  422.                                
  423.                                
  424. function turn()
  425.  
  426.  
  427. if width >= 2 then                                  
  428.  
  429.   if right == 1 then
  430.  
  431.     turtle.turnRight()
  432.     turtle.forward()
  433.     turtle.turnRight()
  434.  
  435.     dist = sub_lenth
  436.     width = width - 1
  437.     right = 0
  438.   else
  439.  
  440.     turtle.turnLeft()
  441.     turtle.forward()
  442.     turtle.turnLeft()
  443.     dist = sub_lenth
  444.     width = width - 1
  445.     right = 1
  446. end
  447. elseif width < 2 then
  448.   dist = sub_lenth
  449.   width = width - 1
  450.   if width <= 0 then
  451.     turtle.turnLeft()
  452.     turtle.turnLeft()
  453.   end
  454. end
  455. end
  456.  
  457.                        
  458. function recenter()                            
  459. working_turn_right_recenter_times = turn_right_recenter_times
  460.                            
  461. working_forward_recenter_times = forward_recenter_times              
  462. gt.goto(setuploc)
  463. if turn_right_recenter_times ~= 0 then
  464.     while working_turn_right_recenter_times ~= 0 do
  465.         turtle.turnRight()
  466.         working_turn_right_recenter_times = working_turn_right_recenter_times - 1      
  467.     end                                
  468. end                          
  469.                                    
  470. right = 1
  471. turtle.select(1)
  472. dist = lenth - 1
  473.   if forward_recenter_times ~= 0 then  
  474.      while working_forward_recenter_times ~= 0 do                          
  475.       turtle.forward()  
  476.       working_forward_recenter_times = working_forward_recenter_times - 1                              
  477.      end                        
  478.   end                              
  479.                                
  480. end
  481.                        
  482.  
  483.                        
  484.                        
  485. function stage1()    
  486.                            
  487.                          
  488.                                        term.setCursorPos(1, 1)
  489.                    term.clearLine()                        
  490.                  print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest and Plant")    
  491. for i=1,#crop_name do                          
  492.        success, data = turtle.inspectDown()  
  493.          if success then        
  494.                              
  495.                                
  496.                                 if data.state.age ~= nil then
  497.                                    
  498.                                    
  499.                                             term.setCursorPos(1, 2)
  500.                                                 term.clearLine()
  501.                                                percentagefloat = (data.state.age - 0) / (7 - 0) * 100
  502.                                                 percentage = math.floor(percentagefloat+0.5)
  503.                                                
  504.                                                 print("Crop Age: " .. percentage .. "%")
  505.                                     end
  506. --         if ignore_nil_age == 1 then
  507.  --    if data.state.age == nil then
  508.    --         data.state.age = crop_max_age                        
  509.    --  end
  510.  --end                              
  511.                              
  512.  if (data.name == crop_name[i]) or (sortblock == 0) then  
  513.        if data.state.age == crop_max_age or ignore_nil_age == 1 then
  514.            --print("Age Check 2: " .. data.state.age)                                          
  515.         turtle.digDown()
  516.                  turtle.suckDown()                                  
  517.                  --term.setCursorPos(1, 3)
  518.                   --term.clearLine()                                  
  519.                  --print("dig")  
  520.                                        
  521.                                      
  522.               end
  523.                 end
  524.                                            
  525.                   if Mode == 1 then                          
  526.                   turtle.placeDown()                            
  527.                     end                
  528.        end
  529.     end        
  530. end        
  531.  
  532.                        
  533.                        
  534. function stage2()  
  535.                            
  536.                            
  537.                            
  538.                             term.setCursorPos(1, 1)
  539.                                   term.clearLine()
  540.                            
  541.                                             print ("Stage: " .. done .. "/" .. totalsteps .. " Cleanup")                                    
  542.         turtle.suckDown()
  543.        
  544.                                     --print("grab")                      
  545.                        
  546.                        
  547.                        
  548. end                        
  549.                        
  550.                        
  551.  
  552. if width == 0 or width == nil  then
  553.     done = done + 1
  554.     --print ("add")                      
  555.     --print ("Steps: " .. done)
  556.     if done == endsteps then
  557.         chest()
  558.         done = 0
  559.     end
  560.  
  561. width = st_width
  562.                             --print("width: " .. width)
  563.                             recenter()
  564.  elseif width ~= 0 then
  565.                                
  566.                            
  567.                            
  568. if dist ~= 0 then                          
  569.            
  570.                          
  571. if done == 1 then
  572. term.clear()
  573.    while width ~= 0 do                                
  574.     while dist ~= 0 do                          
  575. stage1()                                
  576. turtle.forward()                        
  577. stage1()
  578. --print(dist)
  579.        dist = dist - 1
  580.                                                    
  581.              
  582.          end                                
  583.         turn()
  584.        end                            
  585.  
  586. elseif done == grabstage then
  587.      term.clear()                                
  588.    while width ~= 0 do                                  
  589.     while dist ~= 0 do
  590. stage2()                        
  591. turtle.forward()
  592. stage2()
  593.                                                
  594.        dist = dist - 1
  595.        end                                  
  596.         turn()
  597.                            
  598.     end
  599.                                        
  600. --unused planting phase not needed because it can be done after digging
  601. elseif done == 9 then
  602.    
  603.    while width ~= 0 do                                
  604.     while dist ~= 0 do
  605.         turtle.placeDown()
  606.         turtle.forward()
  607.        print("plant")
  608.             print ("Steps: " .. done)                                  
  609.    dist = dist - 1
  610.        end
  611.        turn()                                      
  612.     end
  613.       --end- unused planting phase end                        
  614.  
  615.  end
  616.  
  617.                                     end
  618.  
  619.  
  620.                                
  621.  
  622.  
  623.  
  624.  
  625. end
  626. end
  627. end
  628. end
Add Comment
Please, Sign In to add comment