View difference between Paste ID: vNkFNq3B and ZW6q8wWs
SHOW: | | - or go back to the newest paste.
1-
function startfarm(funfarmargs)
1+
version = "5"
2-
    while _G.andy_farm_program_running == 1 do
2+
term.clear()
3-
        local setmenu = _G.setmenu
3+
term.setCursorPos(1, 1)
4-
        --print(table.concat(setmenu,", "))
4+
--print(version)
5-
        --print(tostring(setmenu))
5+
done = 0
6-
        version = "5"
6+
7-
        --term.clear()
7+
--for l=1,10 do
8-
        --term.setCursorPos(1, 1)
8+
--if fs.exists("farmapi/gt") == false then do
9-
        --print(version)
9+
    --print("downloading goto api")
10
    --shell.run("mkdir","farmapi")
11-
        local farm_prog_progress = "init"
11+
    --shell.run("cd","farmapi")
12-
        farm_prog_progress = 0
12+
    --shell.run("pastebin","get","a3GBewNp","gt")
13-
        farm_prog_progress = farm_prog_progress + 1
13+
    --shell.run("cd","..")
14-
        farmapiloadedguilib = 0
14+
        --if fs.exists("farmapi/gt") == true then
15-
        --term.clear()
15+
            --print("download complete") 
16-
        --term.setCursorPos(1, 1)                           
16+
                --elseif fs.exists("farmapi/gt") == false then
17
                    --print("download failed")
18-
        os.loadAPI("AndysPrograms/api/gt")  
18+
                --end
19-
        while farmapiloadedguilib ~= 1 do
19+
--end
20-
            if os.loadAPI("AndysPrograms/api/gui/gui") then
20+
21-
                --print("loaded gui farmapi lib")
21+
22-
                farmapiloadedguilib = 1
22+
shell.run("AndysPrograms/api/update", "gt", "a3GBewNp", "AndysPrograms/api", "none", "none")
23-
            else
23+
--else do
24-
                print(" NOTloaded gui lib")
24+
25
  term.clear()
26
  term.setCursorPos(1, 1)                           
27
 
28-
        local setmenu = gui.get_setmenu()
28+
 os.loadAPI("AndysPrograms/api/gt")  
29-
        --andy_farm_program_running = 0
29+
30
31-
        if fs.exists("AndysPrograms/Farm/settings") then
31+
32-
            settings.load("AndysPrograms/Farm/settings")
32+
33
 if fs.exists("AndysPrograms/Farm/settings") then
34-
        local maxW, maxH = term.getSize()
34+
    settings.load("AndysPrograms/Farm/settings")
35
end
36-
        farmexit = 0
36+
local maxW, maxH = term.getSize()
37-
        while farmexit ~= 1 do
37+
38
39-
        local setmenu = _G.setmenu
39+
40
function exit()
41
    term.clear()
42
    term.setCursorPos(1, 1)
43
    print("Starting")
44-
        -- setmenu = {
44+
    openset = 0
45-
        --     {options = "Finish editing", handler = mainmenu_farm},
45+
end
46-
        --     {text = "Farm Lenth", setname = "Farm Lenth", options = settings.get("Farm Lenth"), type = "num", handler = chngset},
46+
function chngset()
47-
        --     {text = "Farm Width", setname = "Farm Width", options = settings.get("Farm Width"), type = "num", handler = chngset},
47+
    chngsel = 1
48-
        --     {text = "Mode, 1 = Nrml, 2 = Pump/Mel/SgrCne", setname = "Mode", options = settings.get("Mode"), type = "num", handler = chngset},
48+
end
49-
        --     {text = "Start Location", setname = "Start Location", options = settings.get("Start Location"), type = deftab, handler = chngset},
49+
50-
        --     {text = "Chest Location", setname = "Chest Location", options = settings.get("Chest Location"), type = deftab, handler = chngset},
50+
function savesets()
51-
        --     {text = "Chest Direction 0=fwd 2=up 1=dn", setname = "Chest Direction", options = settings.get("Chest Direction"), type = "num", handler = chngset},
51+
    settings.save("AndysPrograms/Farm/settings")
52-
        --     {text = "Sort Blocks", setname = "Sort Blocks", options = settings.get("Sort Blocks"), type = "num", handler = chngset},
52+
end
53-
        --     {text = "Sort Block Names", setname = "Sort Block Names", options = settings.get("Sort Block Names"), type = deftab, handler = chngset}
53+
gpstab = {}
54-
        -- }
54+
local stgpsx, stgpsy, stgpsz = gps.locate(5)
55-
        ---------------------
55+
table.insert(gpstab, stgpsx)
56-
        ---------------------
56+
table.insert(gpstab, stgpsy)
57-
        ---------------------
57+
table.insert(gpstab, stgpsz)
58-
        --CHANGE HERE START--
58+
table.insert(gpstab, "n")
59-
        ---------------------
59+
if fs.exists("AndysPrograms/Farm/settings") == false then
60-
        ---------------------
60+
    if fs.exists("AndysPrograms/Farm") == false then
61-
        ---------------------
61+
      fs.makeDir("AndysPrograms/Farm")
62
    end
63
64
65
66
67
    srtbk = {"minecraft:pumpkin", "minecraft:reeds"}
68
    settings.set("Farm Lenth", 1)
69-
        --"1" is Normal, "2" is Pumpkin/Melon/Probably Sugar Cane
69+
    settings.set("Farm Width", 1)
70-
        farm_prog_progress = farm_prog_progress + 1
70+
    settings.set("Mode", 2)
71-
        Mode = tonumber(settings.get(setmenu[4].setname))
71+
    settings.set("Start Location", gpstab)
72
    settings.set("Chest Location", gpstab)
73-
        if Mode > 2 or Mode < 1 then
73+
    settings.set("Sort Block Names", srtbk)
74-
            Mode = 2
74+
    settings.set("Sort Blocks", 1)
75
    settings.set("Chest Direction", 0)
76
    savesets()
77
  
78-
        Farm_Lenth = tonumber(settings.get(setmenu[2].setname))
78+
    
79-
        Farm_Width = tonumber(settings.get(setmenu[3].setname))
79+
    
80
  end
81
function resetmenu()
82
deftab = {}
83
setmenu = {}
84-
        -- sort for specific crop
84+
setmenu = {
85
    {text = "Finish editing:", options = "Finish", handler = exit},
86-
        --whether or not to sort, 1 is yes, 0 is no
86+
    {text = "Farm Lenth", setname = "Farm Lenth", options = settings.get("Farm Lenth"), type = "num", handler = chngset},
87-
        sortblock = tonumber(settings.get(setmenu[8].setname))
87+
    {text = "Farm Width", setname = "Farm Width", options = settings.get("Farm Width"), type = "num", handler = chngset},
88-
        if sortblock > 1 or sortblock < 0 then
88+
    {text = "Mode, 1 = Nrml, 2 = Pump/Mel/SgrCne", setname = "Mode", options = settings.get("Mode"), type = "num", handler = chngset},
89-
            sortblock = 1
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-
        --name of the crop
92+
    {text = "Sort Blocks", setname = "Sort Blocks", options = settings.get("Sort Blocks"), type = "num", handler = chngset},
93-
        crop_name = settings.get(setmenu[9].setname)
93+
    {text = "Sort Block Names", setname = "Sort Block Names", options = settings.get("Sort Block Names"), type = deftab, handler = chngset}
94
}
95-
        --max age of crop should probably be left at 7
95+
96-
        crop_max_age = 7
96+
end
97
resetmenu()
98
99
function addsettings(num, value)
100-
        --setup location
100+
    settings.set(setmenu[num].setname, value)
101-
            setuploc = settings.get(setmenu[5].setname)
101+
    savesets()
102
end
103
104
openset = 1
105-
        --chest location
105+
106-
            chestloc = settings.get(setmenu[6].setname)
106+
farmargs = {...}
107
if farmargs[1] == "noset" then
108-
        farmsleeptime = 0
108+
    openset = 0
109
end
110-
        --chest 2 = "up", 1 = "down", or 0 = "forward"
110+
111-
        chestdirection = tonumber(settings.get(setmenu[7].setname))
111+
while openset == 1 do
112
113-
        if chestdirection > 2 or chestdirection < 0 then
113+
114-
            chestdirection = 2
114+
115
116-
            --misc
116+
if openset == 1 then
117
    chngsel = 0
118-
                            --ignore if a crop has no age value should be set at 1 for Pumpkin/Melon and 0 for Normal
118+
    term.clear()
119-
                                Override_ignore_nil_age = 0
119+
    setsoffset = 1
120-
                                ignore_nil_age = 1
120+
    selitem = 1
121
    --if (maxH) < (#setmenu * 2) then
122-
                                override_stages = 0
122+
    --    selitem = maxH / 2
123-
                                turnleftchest = 0
123+
   -- elseif (maxH) > (#setmenu) then
124-
                                totalstages = 1
124+
       --selitem = 1
125-
        -------------------
125+
    --end
126-
        -------------------
126+
function printmenu(menu)
127-
        --CHANGE HERE END--
127+
    for sets=1,#setmenu do
128-
        -------------------
128+
129-
        -------------------
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-
        farm_prog_progress = farm_prog_progress + 1
146+
                        input = read()
147
                        if input then
148
                            inptesset = setmenu[sets].type
149
                            if type(inptesset) == "table" then
150-
        function scrlnum(a,b,st,cl)
150+
                                settingsinputtable = {}
151-
        if a == b then
151+
                                input2 = string.gsub(input, ", ", ",")
152-
            return a, 1
152+
                                --print(input)
153-
        else
153+
                                for i in string.gmatch(input2, '([^,]+)') do
154-
            local clend = cl + st
154+
                                    table.insert(settingsinputtable, i)
155-
            local cldiv = cl - clend
155+
                                end
156-
            local clenddiv = clend - cl
156+
                                --print(input)
157-
            scrlnumper = (os.clock() - cl) / clenddiv
157+
                                addsettings(selitem, settingsinputtable)
158-
            --local scrlnumperold = scrlnumper
158+
159-
            scrlnumper = scrlnumper ^ 2
159+
                            if type(inptesset) ~= "table" then
160-
            --scrlnumper = ((scrlnumper - 1) ^ 2) - 1
160+
                                addsettings(selitem, input)
161-
            --if scrlnumper < scrlnumperold then
161+
162-
            --    scrlnumper = scrlnumperold
162+
                            resetmenu()
163-
            --end
163+
                            --print(chngsel)
164-
            --if scrlnumper < 0 then
164+
                            chngsel = 0
165-
            --    scrlnumper = -scrlnumper
165+
166-
            --end
166+
167-
            --if scrlnumper > 1.02 and scrlnumper < 0.98 then
167+
                    else
168-
            --    scrlnumper = 1
168+
                        print(">  "..prntset)
169-
            --end
169+
170
                else
171-
            return math.floor(((scrlnumper * (b - a)) + a) + 0.1), scrlnumper
171+
                    print("   "..prntset)
172-
            --return ((scrlnumper * (b - a)) + a) + 0.1, scrlnumper
172+
173
            end
174
        end
175
    end
176
end
177
    function onsel(menu, selected)
178
        menu[selected].handler()
179
    end
180-
        --unused!!!! Recenter Values
180+
181-
        turn_right_recenter_times = 0
181+
    function onkeypress(key, menu, selected)
182-
        forward_recenter_times = 0
182+
        if key == keys.enter or key == keys.space then
183
            if chngsel == 0 then
184-
        if Override_ignore_nil_age == 0 then
184+
                onsel(menu, selected)
185-
        if Mode == 2 then
185+
186-
                ignore_nil_age = 1
186+
           -- if chngsel == 1 and (key == keys.enter or key == keys.space) then
187-
        elseif Mode == 1 then
187+
             --   chngsel = 0
188-
                ignore_nil_age = 0
188+
           -- end
189
        elseif key == keys.up or key == keys.w then
190
            if selitem > 1 then
191
                setsoffset = setsoffset + 2.1
192-
        st_width = Farm_Width
192+
                setsoffset = math.floor(setsoffset)
193-
        lenth = Farm_Lenth
193+
                selitem = selitem - 1
194-
        if override_stages == 1 then
194+
195-
            totalsteps = totalstages
195+
        elseif key == keys.down or key == keys.s then
196-
            if Mode == 2 then
196+
            if selitem < (#menu) then
197-
                grabstage = 5
197+
                setsoffset = setsoffset - 1.9
198-
            elseif Mode == 1 then
198+
                setsoffset = math.floor(setsoffset)
199-
                grabstage = 2
199+
                selitem = selitem + 1
200
            end
201-
        elseif Mode == 2 then
201+
        elseif key == keys.q then
202-
        if override_stages == 0 then
202+
            exit()
203-
                grabstage = 5
203+
204-
                totalstages = 1
204+
205-
                totalsteps = 1
205+
206
while openset == 1 do
207-
        elseif  Mode == 1 then
207+
    term.setCursorPos(1, 1) 
208-
            if override_stages == 0 then
208+
    term.clear()
209-
                grabstage = 2
209+
    printmenu(setmenu)
210-
                totalstages = 2
210+
    event, key = os.pullEvent("key")
211-
                totalsteps = 2
211+
    onkeypress(key, setmenu, selitem)
212
end
213
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+
end
223-
            --term.setCursorPos(1, 1)
223+
224-
            --print("Going to Chest")
224+
225-
            gt.goto(chestloc)
225+
226-
            if Mode == 2 then
226+
end
227-
                chest = 1
227+
while true do
228-
            elseif  Mode == 1 then
228+
if done ~= 4 then do
229-
                chest = 2
229+
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+
--CHANGE HERE START--
237-
                turtle.select(chest)
237+
---------------------
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
--"1" is Normal, "2" is Pumpkin/Melon/Probably Sugar Cane                    
247-
            if turnleftchest == 1 then
247+
Mode = tonumber(settings.get(setmenu[4].setname))
248-
                turtle.turnLeft()
248+
 
249
if Mode > 2 or Mode < 1 then
250-
            --term.clear()
250+
    Mode = 2
251-
            --term.setCursorPos(1, 1)
251+
end
252-
            --print("Resetting")
252+
253-
            -- sleep(farmsleeptime)
253+
254-
            farmexit = 1
254+
Farm_Lenth = tonumber(settings.get(setmenu[2].setname))
255
Farm_Width = tonumber(settings.get(setmenu[3].setname))
256
 
257
 
258-
        function turn()
258+
 
259-
            if width >= 2 then
259+
                      
260-
                if right == 1 then
260+
-- sort for specific crop                        
261-
                    turtle.turnRight()
261+
 
262-
                    turtle.forward()
262+
--whether or not to sort, 1 is yes, 0 is no                        
263-
                    turtle.turnRight()
263+
sortblock = tonumber(settings.get(setmenu[8].setname))
264-
                    dist = sub_lenth
264+
if sortblock > 1 or sortblock < 0 then
265-
                    width = width - 1
265+
    sortblock = 1
266-
                    right = 0
266+
end
267
268-
                    turtle.turnLeft()
268+
--name of the crop                        
269-
                    turtle.forward()
269+
crop_name = settings.get(setmenu[9].setname)                                         
270-
                    turtle.turnLeft()
270+
271-
                    dist = sub_lenth
271+
--max age of crop should probably be left at 7
272-
                    width = width - 1
272+
crop_max_age = 7                       
273-
                    right = 1
273+
274
                        
275-
            elseif width < 2 then
275+
276-
                dist = sub_lenth
276+
277-
                width = width - 1
277+
--setup location
278-
                if width <= 0 then
278+
    setuploc = settings.get(setmenu[5].setname)
279-
                    turtle.turnLeft()
279+
280-
                    turtle.turnLeft()
280+
281
                    
282
--chest location                      
283
    chestloc = settings.get(setmenu[6].setname) 
284
   
285
 
286-
        function recenter()                             
286+
  
287-
            working_turn_right_recenter_times = turn_right_recenter_times
287+
--chest 2 = "up", 1 = "down", or 0 = "forward"                        
288
chestdirection = tonumber(settings.get(setmenu[7].setname))
289-
            working_forward_recenter_times = forward_recenter_times
289+
     
290-
            gt.goto(setuploc)
290+
if chestdirection > 2 or chestdirection < 0 then
291-
                if turn_right_recenter_times ~= 0 then
291+
    chestdirection = 2
292-
                    while working_turn_right_recenter_times ~= 0 do
292+
end
293-
                        turtle.turnRight()
293+
    --misc
294-
                        working_turn_right_recenter_times = working_turn_right_recenter_times - 1
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-
            right = 1
298+
299-
            turtle.select(1)
299+
                        override_stages = 0
300-
            dist = lenth - 1
300+
                        turnleftchest = 0
301-
            if forward_recenter_times ~= 0 then
301+
                        totalstages = 1
302-
                while working_forward_recenter_times ~= 0 do
302+
303-
                    turtle.forward()
303+
304-
                    working_forward_recenter_times = working_forward_recenter_times - 1
304+
-------------------                        
305
-------------------
306
--CHANGE HERE END--
307
-------------------        
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+
--unused!!!! Recenter Values
342-
                        while dlprns1 < 1 do
342+
turn_right_recenter_times = 0
343-
                            scagtmst = os.clock()
343+
forward_recenter_times = 0   
344-
                            scnmpnt, dlprns1 = scrlnum(percentageold,percentage,tnstm,scnmtmst)
344+
345-
                            if dlprns1 == nil then
345+
if Override_ignore_nil_age == 0 then
346-
                                dlprns1 = 0
346+
   if Mode == 2 then                          
347
         ignore_nil_age = 1
348-
                            -- term.setCursorPos(1, 2)
348+
   elseif Mode == 1 then                            
349-
                            -- term.clearLine()
349+
         ignore_nil_age = 0                         
350-
                            --print("Crop Age: " .. scnmpnt .. "%")
350+
   end                          
351-
                            --term.setCursorPos(1, 4)
351+
end                     
352-
                            --term.clearLine()
352+
353-
                            --if dlprns1 ~= nil then
353+
st_width = Farm_Width
354-
                            --print("" .. dlprns1 .. "")
354+
lenth = Farm_Lenth                       
355-
                            --end
355+
if override_stages == 1 then
356-
                            --term.setCursorPos(1, 6)
356+
totalsteps = totalstages
357-
                            --term.clearLine()
357+
     if Mode == 2 then
358-
                            --print("" .. percentageold .. "")
358+
       grabstage = 5 
359-
                            if scagl > 25 then
359+
       elseif Mode == 1 then
360-
                                sleep()
360+
       grabstage = 2                        
361-
                                scagl = 0
361+
     end                              
362
elseif Mode == 2 then
363-
                            scagl = scagl + 1
363+
   if override_stages == 0 then                         
364-
                            scagtmen = os.clock()
364+
         grabstage = 5                   
365-
                            scagtm = scagtmen - scagtmst
365+
       totalstages = 1                    
366
 totalsteps = 1   
367-
                        percentageold = percentage
367+
     end                                                       
368
 elseif  Mode == 1 then
369
   if override_stages == 0 then                         
370
       grabstage = 2                     
371
       totalstages = 2                    
372-
                    if (data.name == crop_name[i]) or (sortblock == 0) then
372+
 totalsteps = 2   
373-
                        if data.state.age == crop_max_age or ignore_nil_age == 1 then
373+
     end                           
374-
                            --print("Age Check 2: " .. data.state.age)
374+
  end     
375-
                            turtle.digDown()
375+
  
376-
                            --term.setCursorPos(1, 3)
376+
term.clear()
377-
                            --term.clearLine()
377+
term.setCursorPos(1, 1)
378-
                            --print("dig")   
378+
print("Recentering")              
379
totalsteps = totalstages                                              
380-
                        end 
380+
endsteps = totalsteps + 1                    
381-
                    end 
381+
sub_lenth = lenth - 1                      
382-
                    turtle.suckDown()
382+
function chest()                        
383-
                    if Mode == 1 then
383+
    term.clear()
384-
                        turtle.placeDown()
384+
           term.setCursorPos(1, 1)                                
385
          print("going to chest")                        
386
          gt.goto(chestloc)            
387
       if Mode == 2 then
388-
            ttmen = os.clock()
388+
        chest = 1
389-
            tnstm = ttmen - ttmst
389+
         elseif  Mode == 1 then                         
390-
            tnstm = tnstm - scagtm
390+
       chest = 2
391-
            tnstm = tnstm / 2
391+
                                       end
392-
            if tnstm < 0 then
392+
           term.clear()
393-
                tnstm = 0.02
393+
           term.setCursorPos(1, 1)                          
394
       print("putting in chest")
395
       
396
         
397-
        function scrlage()
397+
       while chest <= 16 do
398-
            for i=1,#crop_name do
398+
       turtle.select(chest)
399-
                success, data = turtle.inspectDown()
399+
     if chestdirection == 0 then  
400-
                if success then
400+
         turtle.drop()                              
401-
                    if dopnt == 1 then
401+
                                      
402-
                    if data.state.age ~= nil then
402+
           elseif chestdirection == 1 then
403-
                        scnmpnt = 0
403+
                       
404-
                        dlprns1 = 0
404+
       turtle.dropDown()
405-
                        percentagefloat = (data.state.age - 0) / (7 - 0) * 100
405+
       elseif chestdirection == 2 then                           
406-
                        percentage = math.floor(percentagefloat+0.5)
406+
         turtle.dropUp()
407-
                        scnmtmst = os.clock()
407+
               end                        
408
                                       
409
                                       
410-
                        while dlprns1 < 1 do
410+
       chest = chest + 1 
411-
                            scnmpnt, dlprns1 = scrlnum(percentageold,percentage,0.5,scnmtmst)
411+
     end
412-
                            if dlprns1 == nil then
412+
         if turnleftchest == 1 then
413-
                                dlprns1 = 0
413+
             turtle.turnLeft()
414
                                   end
415-
                            -- term.setCursorPos(1, 2)
415+
        term.clear()
416-
                            -- term.clearLine()
416+
           term.setCursorPos(1, 1)                                
417-
                            --print("Crop Age: " .. scnmpnt .. "%")
417+
          print("Resetting")                        
418-
                            --term.setCursorPos(1, 4)
418+
      sleep(1) 
419-
                            --term.clearLine()
419+
      os.reboot()                         
420-
                            --if dlprns1 ~= nil then
420+
    end                     
421-
                            --print("" .. dlprns1 .. "")
421+
    --chest()                          
422-
                            --end
422+
423-
                            --term.setCursorPos(1, 6)
423+
424-
                            --term.clearLine()
424+
function turn()
425-
                            --print("" .. percentageold .. "")
425+
 
426-
                                sleep()
426+
427
if width >= 2 then                                   
428-
                        percentageold = percentage
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-
                
439+
440-
        function stage2()
440+
    turtle.turnLeft()
441-
            -- term.setCursorPos(1, 1)
441+
    turtle.forward()
442-
            -- term.clearLine()
442+
    turtle.turnLeft()
443-
            --print ("Stage: " .. done .. "/" .. totalsteps .. " Cleanup")
443+
    dist = sub_lenth
444-
            turtle.suckDown()
444+
    width = width - 1
445-
            --print("grab")
445+
    right = 1
446
end
447
elseif width < 2 then
448-
        function stg1tg()
448+
  dist = sub_lenth
449-
        if dist ~= 0 then
449+
  width = width - 1
450-
            if done == 1 then
450+
  if width <= 0 then
451-
                -- term.clear()
451+
    turtle.turnLeft()
452-
                while width ~= 0 do
452+
    turtle.turnLeft()
453-
                    while dist ~= 0 do
453+
  end
454-
                        dopnt = 1
454+
end
455-
                        parallel.waitForAll(stage1,scrlage)
455+
end
456-
                        --stage1()
456+
457-
                        dopnt = 1
457+
458-
                        turtle.forward()
458+
function recenter()                             
459-
                        --parallel.waitForAll(stage1,scrlage)
459+
working_turn_right_recenter_times = turn_right_recenter_times
460-
                        stage1()
460+
                            
461-
                        --print(dist)
461+
working_forward_recenter_times = forward_recenter_times              
462-
                        dist = dist - 1
462+
gt.goto(setuploc)
463
if turn_right_recenter_times ~= 0 then
464-
                    turn()
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-
        if width == 0 or width == nil  then
471+
turtle.select(1)
472-
            done = done + 1
472+
dist = lenth - 1
473-
            --print ("add")
473+
  if forward_recenter_times ~= 0 then  
474-
            --print ("Steps: " .. done)
474+
     while working_forward_recenter_times ~= 0 do                          
475-
            if done == endsteps then
475+
      turtle.forward()   
476-
                chest()
476+
      working_forward_recenter_times = working_forward_recenter_times - 1                              
477-
                done = 0
477+
     end                         
478-
                farmexit = 1
478+
  end                              
479
                                
480-
            width = st_width
480+
end
481-
            --print("width: " .. width)
481+
482-
            if farmexit ~= 1 then
482+
 
483-
                recenter()
483+
484
                        
485
function stage1()    
486-
        elseif width ~= 0 then
486+
                            
487
                          
488-
            if dist ~= 0 then
488+
                                       term.setCursorPos(1, 1) 
489-
                if done == 1 then
489+
                   term.clearLine()                         
490-
                    -- term.clear()
490+
                 print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest and Plant")    
491-
                    while width ~= 0 do
491+
for i=1,#crop_name do                           
492-
                        while dist ~= 0 do
492+
       success, data = turtle.inspectDown()  
493-
                            dopnt = 1
493+
         if success then         
494-
                            parallel.waitForAll(stage1,scrlage)
494+
                             
495-
                            --stage1()
495+
496-
                            dopnt = 1
496+
                                if data.state.age ~= nil then
497-
                            turtle.forward()
497+
                                    
498-
                            parallel.waitForAll(stage1,scrlage)
498+
                                    
499-
                            --stage1()
499+
                                            term.setCursorPos(1, 2)
500-
                            --print(dist)
500+
                                                term.clearLine()
501-
                            dist = dist - 1
501+
                                               percentagefloat = (data.state.age - 0) / (7 - 0) * 100 
502
                                                percentage = math.floor(percentagefloat+0.5)
503-
                        turn()
503+
                                                
504
                                                print("Crop Age: " .. percentage .. "%")
505
                                    end
506-
                elseif done == grabstage then
506+
--         if ignore_nil_age == 1 then
507-
                    -- term.clear()
507+
 --    if data.state.age == nil then
508-
                    while width ~= 0 do
508+
   --         data.state.age = crop_max_age                        
509-
                        while dist ~= 0 do
509+
   --  end
510-
                            stage2()
510+
 --end                               
511-
                            turtle.forward()
511+
                             
512-
                            stage2()
512+
 if (data.name == crop_name[i]) or (sortblock == 0) then   
513-
                            dist = dist - 1
513+
       if data.state.age == crop_max_age or ignore_nil_age == 1 then
514
           --print("Age Check 2: " .. data.state.age)                                          
515-
                        turn()
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