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