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