-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathandylogger.cc.lua
2061 lines (1981 loc) · 53.1 KB
/
andylogger.cc.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- AndyLogger a Computercraft Turtle Program by Andrakon
-- Version 1.72
-- Get the startup script with "pastebin get nDgxjQas startup"
-- Section: Variables -----------------------------------------------------------------------------
-- these are defaults loaded when the turtle runs for the first time
local whatsMyName = "Andy Logger"
local logSlot = 2
local fuelSlot1 = 13
local fuelSlot2 = 14
local saplingSlot1 = 9
local saplingSlot2 = 10
local dirtSlot = 1
local minFuel = 100 -- the turtle will refuel itself if the fuel level dips below this
local firstRun = true -- do I need to place down the dirt for the first time
local saplingGap = 2 -- blocks between saplings
local wallGap = 2 -- blocks between turtle's starting position and the first tree
local sleepTime = 600 -- automatically adjusted by program
local baseTime = 600 -- used for making the sleepTime calculation and is not saved in logger.cfg
local useFurnace = true -- do you want the turtle to make its own charcoal? Put a furnace above it to use.
local poweredFurnace = false -- set to true if your furnace is powered by something else
local charcoalNumber = 2 -- number of charcoal to make each logging run, in multiples of 8
local dumpStuff = true -- if true the turtle will drop off extra stuff in a chest on its right
local getSaplings = true -- if true the turtle will get saplings from a chest on its left, put only saplings in there
local treeTotal = 0 -- keeps track of how many trees it has cut down
local charcoalMade = 0 -- keeps track of how many charcoal it has made
local saplingsPlanted = 0 -- keeps track of how many saplings it has planted
local fuelOn = true -- setting for if the server has fuel disabled for turtles
local rowOffset = 0 -- scoot the first row left (+) or right (-) with a positive or negative number
local needsBroken = false -- if the turtle can't find its way back home you will need to break it before it runs again
local omgDirt = 0
-- variables for saving the turtle's cordinates, saved in loggercords.dat
local cordsx = 0
local cordsy = 0
local cordsz = 0
local facing = 1
-- SECTION: Settings Saving and Loading -----------------------------------------------------------
function saveSettings() -- write the settings to logger.cfg
term.setCursorPos (3, 2)
write ("Commiting to memory")
local file = fs.open ("logger.cfg", "w")
file.writeLine (whatsMyName)
file.writeLine (logSlot)
file.writeLine (fuelSlot1)
file.writeLine (fuelSlot2)
file.writeLine (saplingSlot1)
file.writeLine (saplingSlot2)
file.writeLine (dirtSlot)
file.writeLine (minFuel)
file.writeLine (firstRun)
file.writeLine (saplingGap)
file.writeLine (wallGap)
file.writeLine (sleepTime)
file.writeLine (long)
file.writeLine (wide)
file.writeLine (useFurnace)
file.writeLine (poweredFurnace)
file.writeLine (charcoalNumber)
file.writeLine (dumpStuff)
file.writeLine (getSaplings)
file.writeLine (treeTotal)
file.writeLine (charcoalMade)
file.writeLine (saplingsPlanted)
file.writeLine (fuelOn)
file.writeLine (rowOffset)
file.writeLine (needsBroken)
file.close ( )
sleep (0.3)
term.setCursorPos (3, 2)
write (" ")
end
function loadSettings() -- load values from logger.cfg
term.setCursorPos (3, 2)
write (" Trying to Remember...")
local file = fs.open ("logger.cfg", "r")
whatsMyName = file.readLine ( )
logSlot = tonumber (file.readLine ( ))
fuelSlot1 = tonumber (file.readLine ( ))
fuelSlot2 = tonumber (file.readLine ( ))
saplingSlot1 = tonumber (file.readLine ( ))
saplingSlot2 = tonumber (file.readLine ( ))
dirtSlot = tonumber (file.readLine ( ))
minFuel = tonumber (file.readLine ( ))
firstRun = file.readLine ( ) == "true"
saplingGap = tonumber (file.readLine ( ))
wallGap = tonumber (file.readLine ( ))
sleepTime = tonumber (file.readLine ( ))
long = tonumber (file.readLine ( ))
wide = tonumber (file.readLine ( ))
useFurnace = file.readLine ( ) == "true"
poweredFurnace = file.readLine ( ) == "true"
charcoalNumber = tonumber (file.readLine ( ))
dumpStuff = file.readLine ( ) == "true"
getSaplings = file.readLine ( ) == "true"
treeTotal = tonumber (file.readLine ( ))
charcoalMade = tonumber (file.readLine ( ))
saplingsPlanted = tonumber (file.readLine ( ))
fuelOn = file.readLine ( ) == "true"
liltest = (file.readLine ( ))
if type( tonumber (liltest) ) == "number" then
-- rowOffset = tonumber (file.readLine ( ))
rowOffset = tonumber (liltest)
else
rowOffset = 0
rowOffset = tonumber (rowOffset)
end
needsBroken = file.readLine ( ) == "true"
file.close ( )
end
-- SECTION: Cordinate Handling
-- cords notes: x is forward and backward, z is left and right
-- faceing is as follows: 1 is x+, 2 is z+, 3 is x-, 4 is z- or
-- Forward, Right, Backward, Left from inital placement
-- all cords and facings are relative to turtles initial placement, not minecraft cords
function saveCords() -- write cordinates to loggercords.dat
local file = fs.open ("loggercords.dat", "w")
file.writeLine (cordsx)
file.writeLine (cordsy)
file.writeLine (cordsz)
file.writeLine (facing)
file.close ( )
end
function loadCords() -- read cordinates from loggercords.dat
local file = fs.open ("loggercords.dat", "r")
cordsx = tonumber (file.readLine ( ))
cordsy = tonumber (file.readLine ( ))
cordsz = tonumber (file.readLine ( ))
facing = tonumber (file.readLine ( ))
file.close ( )
end
function homeCheck() -- see if turtle is at home after booting up
-- checks to see if turtle was broken, most likely the player will not refill logslot
if turtle.getItemCount(logSlot) == 0 then
cordsx = 0
cordsy = 0
cordsz = 0
facing = 1
saveCords()
loadCords()
return true
end
-- check cords and returns true if at home position and facing
if cordsx == 0 then
if cordsy == 0 then
if cordsz == 0 then
if facing == 1 then
return true
else
return false
end
else
return false
end
else
return false
end
else
return false
end
end
function goHome() -- turtle was out in the field when restarted, lets get it home
-- finish cutting down tree first
if cordsx == 0 then -- Dodge the furnace!
if cordsz == 0 then
if cordsy == 2 then
while facing ~= 1 do
turn ("left")
end
forward(1)
down(2)
turn("back")
forward(1)
turn("back")
return
end
end
end
turtle.select(logSlot)
if cordsy ~= 0 then
height = 0
up(1)
height = height + 1
while turtle.compareUp() do
turtle.digUp ()
up (1)
height = height + 1
end
down(height)
end
-- get to the right height
term.setCursorPos (1, 2)
clearLine()
write ("| Im heading home! :D")
while cordsy > 0 do
down (1)
sleep (0.2)
end
if cordsy < 0 then
up (1)
end
-- face the correct z direction to go home
if cordsz < 0 then
while facing ~= 2 do
turn ("right")
end
elseif cordsz > 0 then
while facing ~= 4 do
turn ("left")
end
end
-- get to z = 0
while cordsz ~= 0 do
forward (1)
sleep (0.3)
end
-- face towards home
while facing ~= 3 do
turn ("left")
end
-- go home
while cordsx ~= 0 do
forward (1)
sleep (0.2)
end
turn ("back") -- should now be home facing the right direction
if useFurnace == true then -- lets make sure the turtle made it home, assuming a chest or furnace is nearby
if furnaceCheck() == false then
needsBroken = true
saveSettings()
term.clear()
term.setCursorPos (1, 1)
print ("Logger may not have made it home so the program was closed. Break the turtle and replace it to continue.")
running = false
return
end
elseif dumpStuff == true then -- if useFurnace is off, check for a dump chest
turn ("right")
if turtle.detect() == false then
needsBroken = true
saveSettings()
turn ("left")
term.clear()
term.setCursorPos (1, 1)
print ("Logger may not have made it home so the program was closed. Break the turtle and replace it to continue.")
running = false
return
end
elseif getSaplings == true then -- if dumpchest is off, check for a sapling chest
turn ("left")
if turtle.detect() == false then
needsBroken = true
saveSettings()
turn ("right")
term.clear()
term.setCursorPos (1, 1)
print ("Logger may not have made it home so the program was closed. Break the turtle and replace it to continue.")
running = false
return
end
end -- if somehow the tests pass, or all chests and furnace are turned off, and the turtle isn't in the right spot, then too bad.
end
-- SECTION: Settings Menus, used for changing variables -------------------------------------------
function settings() -- main settings menu
-- display settings menu
-- allow for selection of different setting categories
-- some settings categories goes to their own page, some toggles
-- menus:
-- Turtle Name, change slots, Farm layout, Sleep Time,
-- Furnace (toggle), Sapling chest (toggle), Output chest (toggle)
-- Powered Furnace (toggle), Quit Program
if running == false then return end
term.clear()
box()
term.setCursorPos (15, 1)
write ("Settings Menu")
term.setCursorPos (1, 13)
write ("O---a=back, d=select, w=up, s=down ---O")
keypress = 0
selection = 1
while gotosettings == true do -- menus start here
if selection == 1 then -- Turtle Name
term.setCursorPos (14, 3)
write ("*Turtle Name ")
if keypress == 32 then
changeName()
return
end
else
term.setCursorPos (14, 3)
write (" Turtle Name ")
end
if selection == 2 then
term.setCursorPos (14, 4)
write ("*Change Slots")
if keypress == 32 then
changeSlots()
return
end
else
term.setCursorPos (14, 4)
write (" Change Slots ")
end
if selection == 3 then -- Farm Layout
term.setCursorPos (14, 5)
write ("*Farm Layout")
if keypress == 32 then
farmLayout()
return
end
else
term.setCursorPos (14, 5)
write (" Farm Layout ")
end
if selection == 4 then -- Sleep Time
term.setCursorPos (14, 6)
write ("*Sleep Time")
if keypress == 32 then
changeSleepTime()
return
end
else
term.setCursorPos (14, 6)
write (" Sleep Time ")
end
if selection == 5 then -- Furnace (toggle)
term.setCursorPos (14, 7)
write ("*Furnace ("..tostring(useFurnace)..") ")
if keypress == 32 then
if useFurnace == false then
useFurnace = true
else
useFurnace = false
end
term.setCursorPos (14, 7)
write ("*Furnace ("..tostring(useFurnace)..") ")
end
else
term.setCursorPos (14, 7)
write (" Furnace ("..tostring(useFurnace)..") ")
end
if selection == 6 then -- Powered Furnace (toggle)
term.setCursorPos (14, 8)
write ("*Powered Furnace ("..tostring(poweredFurnace)..") ")
if keypress == 32 then
if poweredFurnace == false then
poweredFurnace = true
else
poweredFurnace = false
end
term.setCursorPos (14, 8)
write ("*Powered Furnace ("..tostring(poweredFurnace)..") ")
end
else
term.setCursorPos (14, 8)
write (" Powered Furnace ("..tostring(poweredFurnace)..") ")
end
if selection == 7 then -- Sapling Chest (toggle)
term.setCursorPos (14, 9)
write ("*Sapling Chest ("..tostring(getSaplings)..") ")
if keypress == 32 then
if getSaplings == false then
getSaplings = true
else
getSaplings = false
end
term.setCursorPos (14, 9)
write ("*Sapling Chest ("..tostring(getSaplings)..") ")
end
else
term.setCursorPos (14, 9)
write (" Sapling Chest ("..tostring(getSaplings)..") ")
end
if selection == 8 then -- Output Chest (toggle)
term.setCursorPos (14, 10)
write ("*Output Chest ("..tostring(dumpStuff)..") ")
if keypress == 32 then
if dumpStuff == false then
dumpStuff = true
else
dumpStuff = false
end
term.setCursorPos (14, 10)
write ("*Output Chest ("..tostring(dumpStuff)..") ")
end
else
term.setCursorPos (14, 10)
write (" Output Chest ("..tostring(dumpStuff)..") ")
end
if selection == 9 then -- Quit Program
term.setCursorPos (14, 11)
write ("*Quit Program ")
if keypress == 32 then
gotosettings = false
term.clear()
saveSettings()
term.clear()
running = false
term.clear()
term.setCursorPos (1, 1)
return
end
else
term.setCursorPos (14, 11)
write (" Quit Program ")
end
--------------------controls-----------------------
keypress = 0
sleep (0.2)
event, keypress = os.pullEvent("key")
if keypress == 17 then -- w key or UP on the menu
selection = selection - 1
if selection < 1 then
selection = 9
end
elseif keypress == 31 then -- s key or DOWN on the menu
selection = selection + 1
if selection > 9 then
selection = 1
end
elseif keypress == 30 then -- a key or Back on the menu
gotosettings = false
term.clear()
graphics()
saveSettings()
loadSettings()
sleep(1)
return
end
end
end
function changeName() -- Change the turtles name (whatsMyName)
term.clear()
box()
term.setCursorPos (15, 1)
write ("Turtle Name")
term.setCursorPos (5, 3)
write ("My name is "..os.getComputerLabel())
term.setCursorPos (5, 5)
write ("Would you like to change it? y/n")
sleep(0.3)
while true do
keypress = 0
event, keypress = os.pullEvent("key")
if keypress == 49 then
settings()
break
elseif keypress == 21 then
term.setCursorPos (5, 5)
write ("What is my new name? ")
term.setCursorPos (5, 6)
sleep(0.3)
whatsMyName = read ()
os.setComputerLabel(whatsMyName)
sleep(1.5)
settings()
break
elseif keypress == 30 then
settings()
break
end
end
end
function changeSlots() -- Slots for dirt, log, sapling 1 and 2, fuel 1 and 2
term.clear()
box()
term.setCursorPos (15, 1)
write ("Change Slots")
term.setCursorPos (1, 13)
write ("O---a=back, d=select, w=up, s=down ---O")
selection = 1
keypress = 0
while true do
term.setCursorPos (15, 3)
if selection == 1 then -- dirtSlot
write ("*Dirt: "..dirtSlot)
turtle.select(dirtSlot)
if keypress == 32 then
term.setCursorPos (10, 9)
write ("Type new Dirt slot: ")
sleep(0.1)
newlong = read ()
liltest = tonumber ( newlong )
if type( liltest ) ~= "number" then
term.setCursorPos (10, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (10, 10)
write (" ")
else
dirtSlot = tonumber(newlong)
changeSlots()
return
end
term.setCursorPos (10, 9)
write (" ")
end
else
write (" Dirt: "..dirtSlot)
end
term.setCursorPos (15, 4)
if selection == 2 then -- logSlot
write ("*Log: "..logSlot)
turtle.select(logSlot)
if keypress == 32 then
term.setCursorPos (10, 9)
write ("Type new Log Slot: ")
sleep(0.1)
newwide = read ()
liltest = tonumber ( newwide )
if type( liltest ) ~= "number" then
term.setCursorPos (10, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (10, 10)
write (" ")
else
logSlot = tonumber(newwide)
changeSlots()
return
end
term.setCursorPos (10, 9)
write (" ")
end
else
write (" Log: "..logSlot)
end
term.setCursorPos (15, 5)
if selection == 3 then -- saplingSlot1
write ("*Sapling 1: "..saplingSlot1)
turtle.select(saplingSlot1)
if keypress == 32 then
term.setCursorPos (10, 9)
write ("Type new Sapling 1 slot: ")
sleep(0.1)
newgap = read ()
liltest = tonumber ( newgap )
if type( liltest ) ~= "number" then
term.setCursorPos (10, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (10, 10)
write (" ")
else
saplingSlot1 = tonumber(newgap)
changeSlots()
return
end
term.setCursorPos (10, 9)
write (" ")
end
else
write (" Sapling 1: "..saplingSlot1)
end
term.setCursorPos (15, 6)
if selection == 4 then -- saplingSlot2
write ("*Sapling 2: "..saplingSlot2)
turtle.select(saplingSlot2)
if keypress == 32 then
term.setCursorPos (10, 9)
write ("Type new Sapling 2 slot: ")
sleep(0.1)
newgap = read ()
liltest = tonumber ( newgap )
if type( liltest ) ~= "number" then
term.setCursorPos (10, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (10, 10)
write (" ")
else
saplingSlot2 = tonumber(newgap)
changeSlots()
return
end
term.setCursorPos (10, 9)
write (" ")
end
else
write (" Sapling 2: "..saplingSlot2)
end
term.setCursorPos (15, 7)
if selection == 5 then -- fuelSlot1
write ("*Fuel 1: "..fuelSlot1)
turtle.select(fuelSlot1)
if keypress == 32 then
term.setCursorPos (10, 9)
write ("Type new Fuel 1 slot: ")
sleep(0.1)
newgap = read ()
liltest = tonumber ( newgap )
if type( liltest ) ~= "number" then
term.setCursorPos (10, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (10, 10)
write (" ")
else
fuelSlot1 = tonumber(newgap)
changeSlots()
return
end
term.setCursorPos (10, 9)
write (" ")
end
else
write (" Fuel 1: "..fuelSlot1)
end
term.setCursorPos (15, 8)
if selection == 6 then ---- fuelSlot2
write ("*Fuel 2: "..fuelSlot2)
turtle.select(fuelSlot2)
if keypress == 32 then
term.setCursorPos (10, 9)
write ("Type new Sapling 2 slot: ")
sleep(0.1)
newgap = read ()
liltest = tonumber ( newgap )
if type( liltest ) ~= "number" then
term.setCursorPos (10, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (10, 10)
write (" ")
else
fuelSlot2 = tonumber(newgap)
changeSlots()
return
end
term.setCursorPos (10, 9)
write (" ")
end
else
write (" Fuel 2: "..fuelSlot2)
end
-- listen for keyboard input
sleep(0.3)
keypress = 0
event, keypress = os.pullEvent("key")
if keypress == 17 then
selection = selection - 1
if selection < 1 then
selection = 6
end
elseif keypress == 31 then
selection = selection + 1
if selection > 6 then
selection = 1
end
elseif keypress == 30 then
settings()
return
end
term.setCursorPos (15, 8)
write (" ")
end
end
function changeSleepTime() -- Change how long the turtle waits (sleepTime)
term.clear()
box()
term.setCursorPos (15, 1)
write ("Sleep Time")
term.setCursorPos (3, 3)
write ("I will currently sleep "..sleepTime.." seconds.")
term.setCursorPos (3, 5)
write ("Would you like to change that? y/n")
sleep(0.3)
while true do
keypress = 0
event, keypress = os.pullEvent("key")
if keypress == 49 then
settings()
break
elseif keypress == 21 then
term.setCursorPos (3, 5)
write ("How long should I sleep? ")
term.setCursorPos (3, 6)
sleep(0.3)
newTime = read ()
liltest = tonumber ( newTime )
if type( liltest ) ~= "number" then
term.setCursorPos (15, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (15, 10)
write (" ")
changeSleepTime()
return
else
sleepTime = tonumber(newTime)
end
sleep(1.5)
settings()
break
elseif keypress == 30 then
settings()
break
end
end
end
function farmLayout() -- Change the layout for the farm
-- graphical setup
term.clear()
box()
line(13)
selection = 1
keypress = 0
-- show demonstration
term.setCursorPos (15, 1)
write ("Farm Layout")
term.setCursorPos (1, 13)
write ("O---a=back, d=select, w=up, s=down ---O")
term.setCursorPos (4, 3)
write ("Width")
term.setCursorPos (3, 4)
write ("T T T")
term.setCursorPos (3, 5)
write ("T T T") -- last char is on 10, 4
term.setCursorPos (3, 6)
write ("T T T")
term.setCursorPos (3, 7)
write ("T T T")
term.setCursorPos (3, 8)
write ("T T T")
term.setCursorPos (3, 9)
write ("@")
term.setCursorPos (3, 10)
write ("^ Turtle")
term.setCursorPos (3, 11)
write ("| facing")
term.setCursorPos (3, 12)
write ("| Up")
-- write the word length vertically
term.setCursorPos (11, 3)
write ("L")
term.setCursorPos (11, 4)
write ("e")
term.setCursorPos (11, 5)
write ("n")
term.setCursorPos (11, 6)
write ("g")
term.setCursorPos (11, 7)
write ("t")
term.setCursorPos (11, 8)
write ("h")
while true do
term.setCursorPos (15, 3)
if selection == 1 then -- long
write ("*Length: "..long)
term.setCursorPos (15, 8)
write ("Number of trees long")
if keypress == 32 then
term.setCursorPos (15, 9)
write ("Type new Length: ")
sleep(0.4)
newlong = read ()
liltest = tonumber ( newlong )
if type( liltest ) ~= "number" then
term.setCursorPos (15, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (15, 10)
write (" ")
elseif liltest > 0 then
long = tonumber(newlong)
firstRun = true
farmLayout()
return
elseif liltest == 0 then
term.setCursorPos (15, 10)
write ("Must be more than Zero")
sleep(1.5)
farmLayout()
return
end
term.setCursorPos (15, 10)
write (" ")
end
else
write (" Length: "..long)
end
term.setCursorPos (15, 4)
if selection == 2 then -- wide
write ("*Width: "..wide)
term.setCursorPos (15, 8)
write ("Number of trees wide")
if keypress == 32 then
term.setCursorPos (15, 9)
write ("Type new Width: ")
sleep(0.4)
newwide = read ()
liltest = tonumber ( newwide )
if type( liltest ) ~= "number" then
term.setCursorPos (15, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (15, 10)
write (" ")
elseif liltest > 0 then
wide = tonumber(newwide)
firstRun = true
farmLayout()
return
elseif liltest == 0 then
term.setCursorPos (15, 10)
write ("Must be more than Zero")
sleep(1.5)
farmLayout()
return
end
term.setCursorPos (15, 9)
write (" ")
end
else
write (" Width: "..wide)
end
term.setCursorPos (15, 5)
if selection == 3 then -- saplingGap/Tree Gap
write ("*Tree Gap: "..saplingGap)
term.setCursorPos (15, 8)
write ("Blocks between Trees")
if keypress == 32 then
term.setCursorPos (15, 9)
write ("Type new Gap size: ")
sleep(0.4)
newgap = read ()
liltest = tonumber ( newgap )
if type( liltest ) ~= "number" then
term.setCursorPos (15, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (15, 10)
write (" ")
else
saplingGap = tonumber(newgap)
farmLayout()
return
end
term.setCursorPos (15, 9)
write (" ")
end
else
write (" Tree Gap: "..saplingGap)
end
term.setCursorPos (15, 6)
if selection == 4 then -- wallGap/ Turtle Gap
write ("*Turtle Gap: "..wallGap)
term.setCursorPos (15, 8)
write ("Distance to First tree")
if keypress == 32 then
term.setCursorPos (15, 9)
write ("Type new Gap size: ")
sleep(0.1)
newgap = read ()
liltest = tonumber ( newgap )
if type( liltest ) ~= "number" then
term.setCursorPos (15, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (15, 10)
write (" ")
elseif liltest > 0 then
wallGap = tonumber(newgap)
farmLayout()
return
elseif liltest == 0 then
term.setCursorPos (15, 10)
write ("Must be more than Zero")
sleep(1.5)
farmLayout()
return
end
term.setCursorPos (15, 9)
write (" ")
end
else
write (" Turtle Gap: "..wallGap)
end
-- rowOffset
term.setCursorPos (15, 7)
if selection == 5 then -- rowOffset
write ("*Row Offset: "..rowOffset)
term.setCursorPos (15, 8)
write ("Move first row")
term.setCursorPos (15, 9)
write ("left with positive num")
term.setCursorPos (15, 10)
write ("right with negative num")
if keypress == 32 then
term.setCursorPos (15, 11)
write ("Type new Row Offset: ")
sleep(0.1)
newgap = read ()
liltest = tonumber ( newgap )
if type( liltest ) ~= "number" then
term.setCursorPos (15, 10)
write ("I was expecting a number")
sleep(1.5)
term.setCursorPos (15, 10)
write (" ")
else
rowOffset = tonumber(newgap)
farmLayout()
return
end
term.setCursorPos (15, 11)
write (" ")
end
else
write (" Row Offset: "..rowOffset)
end
-- listen for keyboard input
sleep(0.4)
keypress = 0
event, keypress = os.pullEvent("key")
if keypress == 17 then
selection = selection - 1
if selection < 1 then
selection = 5
end
elseif keypress == 31 then
selection = selection + 1
if selection > 5 then
selection = 1
end
elseif keypress == 30 then
sleepTime = baseTime - ((long * wide) * 5)
if sleepTime < 60 then
sleepTime = 60
end
settings()
return
end
term.setCursorPos (15, 8)
write (" ")
term.setCursorPos (15, 9)
write (" ")
term.setCursorPos (15, 10)
write (" ")
end
end
function startup() -- Get inital lengh and width on first startup
term.clear()
term.setCursorPos (1, 1)
print ("")
print ("W I D E")
print ("T T T L")
print ("T T T O")
print ("T T T N")
print ("T T T G")
print ("@ <-- Turtle facing Up")
print ("")
print ("How many trees Long?")
long = read ()
liltesta = tonumber ( long )
if type( liltesta ) ~= "number" then
print ("I was expecting a number...")
print ("Lets try that again.")
sleep(2)
startup()
return
end
print ("How many trees Wide?")
wide = read ()
liltestb = tonumber ( wide )
if type( liltestb ) ~= "number" then
print ("I was expecting a number...")
print ("Lets try that again.")
sleep(2)