View difference between Paste ID: XYKTa1VH and wY7VSgqt
SHOW: | | - or go back to the newest paste.
1
version = "5"
2
term.clear()
3-
  term.setCursorPos(1, 1)
3+
term.setCursorPos(1, 1)
4
--print(version)
5
sleep(3)
6
done = 0
7
8-
if fs.exists("goto") == false 
8+
9-
then do
9+
if fs.exists("farmapi/gt") == false then do
10-
print("downloading goto")
10+
    print("downloading goto api")
11-
shell.run("pastebin","get","Rj9UiYUJ","goto")
11+
    shell.run("mkdir","farmapi")
12-
     if fs.exists("goto") == true then
12+
    shell.run("cd","farmapi")
13
    shell.run("pastebin","get","a3GBewNp","gt")
14-
                elseif fs.exists("goto") == false then
14+
    shell.run("cd","..")
15-
                print("download failed")
15+
        if fs.exists("farmapi/gt") == true then
16
            print("download complete") 
17
                elseif fs.exists("farmapi/gt") == false then
18
                    print("download failed")
19
                end
20
end
21
22-
 print("recentering")           
22+
23
            
24
  term.clear()
25
  term.setCursorPos(1, 1)                           
26
 print("recentering")  
27
 os.loadAPI("farmapi/gt")         
28
while true do
29
if done ~= 4 then do
30
31
32
33
                        
34
---------------------                        
35
---------------------                        
36
--------------------- 
37
--CHANGE HERE START--
38
---------------------
39
---------------------                        
40
---------------------                        
41
                        
42
                        
43
--"1" is Normal, "2" is Pumpkin/Melon/Probably Sugar Cane                    
44
Mode = 1
45
                        
46
Farm_Lenth = 5
47
Farm_Width = 5
48
 
49
 
50
 
51
                      
52
-- sort for specific crop                        
53-
--Recenter Values
53+
54-
    turn_right_recenter_times = 1
54+
55-
    forward_recenter_times = 2                  
55+
56
--name of the crop                        
57-
--max age of crop should probably be left at 7
57+
58-
crop_max_age = 7                       
58+
                  
59
                        
60
--max age of crop, should probably be left at 7
61
crop_max_age = 7                      
62
                        
63-
--setup1 location
63+
64-
  setup1X = 363
64+
65-
  setup1Y = 89
65+
66-
  setup1Z = 631
66+
--setup location
67-
--setup2 location                        
67+
  setuploc = {361, 89, 629, "e"}
68-
  setup2X = 359
68+
69-
  setup2Y = 89
69+
70-
  setup2Z = 629               
70+
71
                    
72
--chest location                      
73
      chestloc = {359, 88, 629, "e"}
74
  
75
--chest 2 = "up", 1 = "down", or 0 = "forward"                        
76-
      chestX =  359
76+
77-
      chestY =  88                
77+
78-
      chestZ =  629 
78+
79
                        
80
                      --ignore if a crop has no age value should be set at 1 for Pumpkin/Melon and 0 for Normal 
81
                        Override_ignore_nil_age = 0
82
                        ignore_nil_age = 1  
83
                        
84
                        override_stages = 0
85
                        turnleftchest = 0
86
                        totalstages = 1
87
                        
88
                        
89
-------------------                        
90
-------------------
91
--CHANGE HERE END--
92
-------------------        
93
-------------------
94
                        
95
                        
96
        
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--unused!!!! Recenter Values
127
turn_right_recenter_times = 0
128
forward_recenter_times = 0   
129
130
if Override_ignore_nil_age == 0 then
131
   if Mode == 2 then                          
132
         ignore_nil_age = 1
133
   elseif Mode == 1 then                            
134-
                                              
134+
135
   end                          
136
end                     
137
                        
138
st_width = Farm_Width
139
lenth = Farm_Lenth                       
140
if override_stages == 1 then
141-
shell.run("goto", chestX, chestY, chestZ)
141+
142
     if Mode == 2 then
143
       grabstage = 5 
144
       elseif Mode == 1 then
145
       grabstage = 2                        
146
     end                              
147
elseif Mode == 2 then
148
   if override_stages == 0 then                         
149
         grabstage = 5                   
150
       totalstages = 1                    
151
 totalsteps = 1   
152
     end                                                       
153
 elseif  Mode == 1 then
154
   if override_stages == 0 then                         
155
       grabstage = 2                     
156
       totalstages = 2                    
157
 totalsteps = 2   
158
     end                           
159
  end                      
160
totalsteps = totalstages                                              
161
endsteps = totalsteps + 1                    
162
sub_lenth = lenth - 1                      
163
function chest()                        
164
 term.clear()
165
        term.setCursorPos(1, 1)                                
166
       print("going to chest")                         
167
       gt.goto(chestloc)
168
                          
169
    if Mode == 2 then
170
     chest = 1
171
      elseif  Mode == 1 then                         
172
    chest = 2
173
                                    end
174
        term.clear()
175
        term.setCursorPos(1, 1)                          
176
    print("putting in chest")
177
    while chest <= 16 do
178
    turtle.select(chest)
179
  if chestdirection == 0 then  
180-
if right == 1 then 
180+
181-
                                   --print("right")
181+
182-
turtle.turnRight()
182+
183
                    
184-
turtle.turnRight()
184+
185
    elseif chestdirection == 2 then                           
186-
dist = sub_lenth
186+
187-
width = width - 1
187+
188-
right = 0
188+
189-
else
189+
190-
                                    --print("left")
190+
191-
turtle.turnLeft()
191+
192
      if turnleftchest == 1 then
193-
turtle.turnLeft()
193+
194-
dist = sub_lenth
194+
195-
width = width - 1
195+
196
        term.setCursorPos(1, 1)                                
197
       print("Resetting")                        
198
   sleep(20) 
199
   os.reboot()                         
200
 end                               
201
                                
202
                                
203
                                
204
function turn()
205
 
206-
shell.run("goto", setup1X, setup1Y, setup1Z)
206+
207-
shell.run("goto", setup2X, setup2Y, setup2Z) 
207+
if width >= 2 then                                   
208
209
  if right == 1 then 
210
211
    turtle.turnRight()
212
    turtle.forward()
213
    turtle.turnRight()
214
215
    dist = sub_lenth
216
    width = width - 1
217
    right = 0
218
  else
219
220
    turtle.turnLeft()
221
    turtle.forward()
222
    turtle.turnLeft()
223
    dist = sub_lenth
224
    width = width - 1
225
    right = 1
226
end
227
elseif width < 2 then
228
  dist = sub_lenth
229
  width = width - 1
230
  if width <= 0 then
231
    turtle.turnLeft()
232
    turtle.turnLeft()
233
  end
234
end
235
end
236
237
                        
238
function recenter()                             
239
working_turn_right_recenter_times = turn_right_recenter_times
240
                            
241
working_forward_recenter_times = forward_recenter_times
242
                            
243
gt.goto(setuploc)
244
if turn_right_recenter_times ~= 0 then
245
    while working_turn_right_recenter_times ~= 0 do
246
        turtle.turnRight()
247
        working_turn_right_recenter_times = working_turn_right_recenter_times - 1      
248
    end                                
249
end                           
250
                                    
251
right = 1
252
turtle.select(1)
253
dist = lenth - 1
254
  if forward_recenter_times ~= 0 then  
255
     while working_forward_recenter_times ~= 0 do                          
256
      turtle.forward()   
257-
 if data.name == crop_name or sortblock == 0 then   
257+
258
     end                         
259
  end                              
260
                                
261
end
262
                        
263
 
264
                        
265
                        
266
function stage1()    
267
                            
268
                          
269
                                       term.setCursorPos(1, 1) 
270
                   term.clearLine()                         
271
                 print ("Stage: " .. done .. "/" .. totalsteps.. " Harvest and Plant")    
272
                            
273
       success, data = turtle.inspectDown()  
274
         if success then         
275
                             
276
                                
277
                                if data.state.age ~= nil then
278
                                    
279
                                    
280
                                            term.setCursorPos(1, 2)
281
                                                term.clearLine()
282
                                               percentagefloat = (data.state.age - 0) / (7 - 0) * 100 
283
                                                percentage = math.floor(percentagefloat+0.5)
284
                                                
285
                                                print("Crop Age: " .. percentage .. "%")
286
                                    end
287
--         if ignore_nil_age == 1 then
288
 --    if data.state.age == nil then
289
   --         data.state.age = crop_max_age                        
290
   --  end
291
 --end                               
292
                             
293
 if (data.name == crop_name) or (sortblock == 0) then   
294
       if data.state.age == crop_max_age or ignore_nil_age == 1 then
295
           --print("Age Check 2: " .. data.state.age)                                          
296
        turtle.digDown()
297-
 done = done + 1 
297+
298-
      --print ("add")                      
298+
299
                  --term.clearLine()                                   
300-
  if done == endsteps then
300+
301-
                               recenter() 
301+
302-
                                chest()
302+
303-
                                  done = 0
303+
304
                end 
305
                                            
306
                  if Mode == 1 then                          
307
                  turtle.placeDown()                            
308
                    end                 
309
       end        
310
end        
311
312
                        
313
                        
314
function stage2()   
315
                            
316
                            
317
                            
318
                            term.setCursorPos(1, 1)
319
                                  term.clearLine()
320
                            
321
                                            print ("Stage: " .. done .. "/" .. totalsteps .. " Cleanup")                                    
322
        turtle.suckDown()
323-
--print("dig")
323+
324
                                    --print("grab")                       
325
                        
326
                        
327-
         end                               
327+
328-
   turn()
328+
329-
   
329+
330
                        
331
332
if width == 0 or width == nil  then
333
    done = done + 1 
334
    --print ("add")                      
335
    --print ("Steps: " .. done) 
336
    if done == endsteps then
337
        chest()
338
        done = 0
339
    end
340
341
width = st_width 
342-
       turn()                                 
342+
343
                            recenter()
344
 elseif width ~= 0 then
345
                                
346
                            
347
                            
348
if dist ~= 0 then                           
349
           
350
                          
351
if done == 1 then
352
term.clear() 
353
   while width ~= 0 do                                 
354
    while dist ~= 0 do                          
355
stage1()                                
356
turtle.forward()                         
357
stage1() 
358
--print(dist)
359
       dist = dist - 1
360
                                                    
361
              
362
         end                                 
363
        turn()
364
       end                             
365
366
elseif done == grabstage then
367
     term.clear()                                
368
   while width ~= 0 do                                  
369
    while dist ~= 0 do 
370
stage2()                        
371
turtle.forward()
372
stage2()
373
                                               
374
       dist = dist - 1
375
       end                                  
376
        turn()
377
                           
378
    end
379
                                        
380
--unused planting phase not needed because it can be done after digging
381
elseif done == 9 then
382
    
383
   while width ~= 0 do                                 
384
    while dist ~= 0 do
385
        turtle.placeDown()
386
        turtle.forward()
387
       print("plant")
388
            print ("Steps: " .. done)                                  
389
   dist = dist - 1
390
       end
391
       turn()                                       
392
    end
393
      --end- unused planting phase end                         
394
395
 end
396
397
                                    end
398
399
400
                               
401
402
403
404
405
end
406
end
407
end
408
end                    
409
end                    
410
    end                
411
    end