SHOW:
|
|
- or go back to the newest paste.
1 | -- AndyLogger a Computercraft Turtle Program by Andrakon | |
2 | -- Version 1.72 | |
3 | -- Get the startup script with "pastebin get nDgxjQas startup" | |
4 | ||
5 | ||
6 | -- Section: Variables ----------------------------------------------------------------------------- | |
7 | -- these are defaults loaded when the turtle runs for the first time | |
8 | local whatsMyName = "Andy Logger" | |
9 | local logSlot = 2 | |
10 | local fuelSlot1 = 13 | |
11 | local fuelSlot2 = 14 | |
12 | local saplingSlot1 = 9 | |
13 | local saplingSlot2 = 10 | |
14 | local dirtSlot = 1 | |
15 | local minFuel = 100 -- the turtle will refuel itself if the fuel level dips below this | |
16 | local firstRun = true -- do I need to place down the dirt for the first time | |
17 | local saplingGap = 2 -- blocks between saplings | |
18 | local wallGap = 2 -- blocks between turtle's starting position and the first tree | |
19 | local sleepTime = 600 -- automatically adjusted by program | |
20 | local baseTime = 600 -- used for making the sleepTime calculation and is not saved in logger.cfg | |
21 | local useFurnace = true -- do you want the turtle to make its own charcoal? Put a furnace above it to use. | |
22 | local poweredFurnace = false -- set to true if your furnace is powered by something else | |
23 | local charcoalNumber = 2 -- number of charcoal to make each logging run, in multiples of 8 | |
24 | local dumpStuff = true -- if true the turtle will drop off extra stuff in a chest on its right | |
25 | local getSaplings = true -- if true the turtle will get saplings from a chest on its left, put only saplings in there | |
26 | local treeTotal = 0 -- keeps track of how many trees it has cut down | |
27 | local charcoalMade = 0 -- keeps track of how many charcoal it has made | |
28 | local saplingsPlanted = 0 -- keeps track of how many saplings it has planted | |
29 | local fuelOn = true -- setting for if the server has fuel disabled for turtles | |
30 | local rowOffset = 0 -- scoot the first row left (+) or right (-) with a positive or negative number | |
31 | local needsBroken = false -- if the turtle can't find its way back home you will need to break it before it runs again | |
32 | local omgDirt = 0 | |
33 | -- variables for saving the turtle's cordinates, saved in loggercords.dat | |
34 | local cordsx = 0 | |
35 | local cordsy = 0 | |
36 | local cordsz = 0 | |
37 | local facing = 1 | |
38 | ||
39 | -- SECTION: Settings Saving and Loading ----------------------------------------------------------- | |
40 | function saveSettings() -- write the settings to logger.cfg | |
41 | term.setCursorPos (3, 2) | |
42 | write ("Commiting to memory") | |
43 | local file = fs.open ("logger.cfg", "w") | |
44 | file.writeLine (whatsMyName) | |
45 | file.writeLine (logSlot) | |
46 | file.writeLine (fuelSlot1) | |
47 | file.writeLine (fuelSlot2) | |
48 | file.writeLine (saplingSlot1) | |
49 | file.writeLine (saplingSlot2) | |
50 | file.writeLine (dirtSlot) | |
51 | file.writeLine (minFuel) | |
52 | file.writeLine (firstRun) | |
53 | file.writeLine (saplingGap) | |
54 | file.writeLine (wallGap) | |
55 | file.writeLine (sleepTime) | |
56 | file.writeLine (long) | |
57 | file.writeLine (wide) | |
58 | file.writeLine (useFurnace) | |
59 | file.writeLine (poweredFurnace) | |
60 | file.writeLine (charcoalNumber) | |
61 | file.writeLine (dumpStuff) | |
62 | file.writeLine (getSaplings) | |
63 | file.writeLine (treeTotal) | |
64 | file.writeLine (charcoalMade) | |
65 | file.writeLine (saplingsPlanted) | |
66 | file.writeLine (fuelOn) | |
67 | file.writeLine (rowOffset) | |
68 | file.writeLine (needsBroken) | |
69 | file.close ( ) | |
70 | sleep (0.3) | |
71 | term.setCursorPos (3, 2) | |
72 | write (" ") | |
73 | end | |
74 | ||
75 | function loadSettings() -- load values from logger.cfg | |
76 | term.setCursorPos (3, 2) | |
77 | write (" Trying to Remember...") | |
78 | local file = fs.open ("logger.cfg", "r") | |
79 | whatsMyName = file.readLine ( ) | |
80 | logSlot = tonumber (file.readLine ( )) | |
81 | fuelSlot1 = tonumber (file.readLine ( )) | |
82 | fuelSlot2 = tonumber (file.readLine ( )) | |
83 | saplingSlot1 = tonumber (file.readLine ( )) | |
84 | saplingSlot2 = tonumber (file.readLine ( )) | |
85 | dirtSlot = tonumber (file.readLine ( )) | |
86 | minFuel = tonumber (file.readLine ( )) | |
87 | firstRun = file.readLine ( ) == "true" | |
88 | saplingGap = tonumber (file.readLine ( )) | |
89 | wallGap = tonumber (file.readLine ( )) | |
90 | sleepTime = tonumber (file.readLine ( )) | |
91 | long = tonumber (file.readLine ( )) | |
92 | wide = tonumber (file.readLine ( )) | |
93 | useFurnace = file.readLine ( ) == "true" | |
94 | poweredFurnace = file.readLine ( ) == "true" | |
95 | charcoalNumber = tonumber (file.readLine ( )) | |
96 | dumpStuff = file.readLine ( ) == "true" | |
97 | getSaplings = file.readLine ( ) == "true" | |
98 | treeTotal = tonumber (file.readLine ( )) | |
99 | charcoalMade = tonumber (file.readLine ( )) | |
100 | saplingsPlanted = tonumber (file.readLine ( )) | |
101 | fuelOn = file.readLine ( ) == "true" | |
102 | liltest = (file.readLine ( )) | |
103 | if type( tonumber (liltest) ) == "number" then | |
104 | -- rowOffset = tonumber (file.readLine ( )) | |
105 | rowOffset = tonumber (liltest) | |
106 | else | |
107 | rowOffset = 0 | |
108 | rowOffset = tonumber (rowOffset) | |
109 | end | |
110 | needsBroken = file.readLine ( ) == "true" | |
111 | file.close ( ) | |
112 | end | |
113 | ||
114 | ||
115 | -- SECTION: Cordinate Handling | |
116 | -- cords notes: x is forward and backward, z is left and right | |
117 | -- faceing is as follows: 1 is x+, 2 is z+, 3 is x-, 4 is z- or | |
118 | -- Forward, Right, Backward, Left from inital placement | |
119 | -- all cords and facings are relative to turtles initial placement, not minecraft cords | |
120 | ||
121 | function saveCords() -- write cordinates to loggercords.dat | |
122 | local file = fs.open ("loggercords.dat", "w") | |
123 | file.writeLine (cordsx) | |
124 | file.writeLine (cordsy) | |
125 | file.writeLine (cordsz) | |
126 | file.writeLine (facing) | |
127 | file.close ( ) | |
128 | end | |
129 | ||
130 | function loadCords() -- read cordinates from loggercords.dat | |
131 | local file = fs.open ("loggercords.dat", "r") | |
132 | cordsx = tonumber (file.readLine ( )) | |
133 | cordsy = tonumber (file.readLine ( )) | |
134 | cordsz = tonumber (file.readLine ( )) | |
135 | facing = tonumber (file.readLine ( )) | |
136 | file.close ( ) | |
137 | end | |
138 | ||
139 | function homeCheck() -- see if turtle is at home after booting up | |
140 | -- checks to see if turtle was broken, most likely the player will not refill logslot | |
141 | if turtle.getItemCount(logSlot) == 0 then | |
142 | cordsx = 0 | |
143 | cordsy = 0 | |
144 | cordsz = 0 | |
145 | facing = 1 | |
146 | saveCords() | |
147 | loadCords() | |
148 | return true | |
149 | end | |
150 | -- check cords and returns true if at home position and facing | |
151 | if cordsx == 0 then | |
152 | if cordsy == 0 then | |
153 | if cordsz == 0 then | |
154 | if facing == 1 then | |
155 | return true | |
156 | else | |
157 | return false | |
158 | end | |
159 | else | |
160 | return false | |
161 | end | |
162 | else | |
163 | return false | |
164 | end | |
165 | else | |
166 | return false | |
167 | end | |
168 | end | |
169 | ||
170 | function goHome() -- turtle was out in the field when restarted, lets get it home | |
171 | -- finish cutting down tree first | |
172 | if cordsx == 0 then -- Dodge the furnace! | |
173 | if cordsz == 0 then | |
174 | if cordsy == 2 then | |
175 | while facing ~= 1 do | |
176 | turn ("left") | |
177 | end | |
178 | forward(1) | |
179 | down(2) | |
180 | turn("back") | |
181 | forward(1) | |
182 | turn("back") | |
183 | return | |
184 | end | |
185 | end | |
186 | end | |
187 | turtle.select(logSlot) | |
188 | if cordsy ~= 0 then | |
189 | height = 0 | |
190 | up(1) | |
191 | height = height + 1 | |
192 | while turtle.compareUp() do | |
193 | turtle.digUp () | |
194 | up (1) | |
195 | height = height + 1 | |
196 | end | |
197 | down(height) | |
198 | end | |
199 | -- get to the right height | |
200 | term.setCursorPos (1, 2) | |
201 | clearLine() | |
202 | write ("| Im heading home! :D") | |
203 | while cordsy > 0 do | |
204 | down (1) | |
205 | sleep (0.2) | |
206 | end | |
207 | if cordsy < 0 then | |
208 | up (1) | |
209 | end | |
210 | -- face the correct z direction to go home | |
211 | if cordsz < 0 then | |
212 | while facing ~= 2 do | |
213 | turn ("right") | |
214 | end | |
215 | elseif cordsz > 0 then | |
216 | while facing ~= 4 do | |
217 | turn ("left") | |
218 | end | |
219 | end | |
220 | -- get to z = 0 | |
221 | while cordsz ~= 0 do | |
222 | forward (1) | |
223 | sleep (0.3) | |
224 | end | |
225 | -- face towards home | |
226 | while facing ~= 3 do | |
227 | turn ("left") | |
228 | end | |
229 | -- go home | |
230 | while cordsx ~= 0 do | |
231 | forward (1) | |
232 | sleep (0.2) | |
233 | end | |
234 | turn ("back") -- should now be home facing the right direction | |
235 | if useFurnace == true then -- lets make sure the turtle made it home, assuming a chest or furnace is nearby | |
236 | if furnaceCheck() == false then | |
237 | needsBroken = true | |
238 | saveSettings() | |
239 | term.clear() | |
240 | term.setCursorPos (1, 1) | |
241 | print ("Logger may not have made it home so the program was closed. Break the turtle and replace it to continue.") | |
242 | running = false | |
243 | return | |
244 | end | |
245 | elseif dumpStuff == true then -- if useFurnace is off, check for a dump chest | |
246 | turn ("right") | |
247 | if turtle.detect() == false then | |
248 | needsBroken = true | |
249 | saveSettings() | |
250 | turn ("left") | |
251 | term.clear() | |
252 | term.setCursorPos (1, 1) | |
253 | print ("Logger may not have made it home so the program was closed. Break the turtle and replace it to continue.") | |
254 | running = false | |
255 | return | |
256 | end | |
257 | elseif getSaplings == true then -- if dumpchest is off, check for a sapling chest | |
258 | turn ("left") | |
259 | if turtle.detect() == false then | |
260 | needsBroken = true | |
261 | saveSettings() | |
262 | turn ("right") | |
263 | term.clear() | |
264 | term.setCursorPos (1, 1) | |
265 | print ("Logger may not have made it home so the program was closed. Break the turtle and replace it to continue.") | |
266 | running = false | |
267 | return | |
268 | end | |
269 | 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. | |
270 | end | |
271 | ||
272 | -- SECTION: Settings Menus, used for changing variables ------------------------------------------- | |
273 | ||
274 | function settings() -- main settings menu | |
275 | -- display settings menu | |
276 | -- allow for selection of different setting categories | |
277 | -- some settings categories goes to their own page, some toggles | |
278 | -- menus: | |
279 | -- Turtle Name, change slots, Farm layout, Sleep Time, | |
280 | -- Furnace (toggle), Sapling chest (toggle), Output chest (toggle) | |
281 | -- Powered Furnace (toggle), Quit Program | |
282 | if running == false then return end | |
283 | term.clear() | |
284 | box() | |
285 | term.setCursorPos (15, 1) | |
286 | write ("Settings Menu") | |
287 | term.setCursorPos (1, 13) | |
288 | write ("O---a=back, d=select, w=up, s=down ---O") | |
289 | keypress = 0 | |
290 | selection = 1 | |
291 | while gotosettings == true do -- menus start here | |
292 | if selection == 1 then -- Turtle Name | |
293 | term.setCursorPos (14, 3) | |
294 | write ("*Turtle Name ") | |
295 | if keypress == 32 then | |
296 | changeName() | |
297 | return | |
298 | end | |
299 | else | |
300 | term.setCursorPos (14, 3) | |
301 | write (" Turtle Name ") | |
302 | end | |
303 | if selection == 2 then | |
304 | term.setCursorPos (14, 4) | |
305 | write ("*Change Slots") | |
306 | if keypress == 32 then | |
307 | changeSlots() | |
308 | return | |
309 | end | |
310 | else | |
311 | term.setCursorPos (14, 4) | |
312 | write (" Change Slots ") | |
313 | end | |
314 | if selection == 3 then -- Farm Layout | |
315 | term.setCursorPos (14, 5) | |
316 | write ("*Farm Layout") | |
317 | if keypress == 32 then | |
318 | farmLayout() | |
319 | return | |
320 | end | |
321 | else | |
322 | term.setCursorPos (14, 5) | |
323 | write (" Farm Layout ") | |
324 | end | |
325 | if selection == 4 then -- Sleep Time | |
326 | term.setCursorPos (14, 6) | |
327 | write ("*Sleep Time") | |
328 | if keypress == 32 then | |
329 | changeSleepTime() | |
330 | return | |
331 | end | |
332 | else | |
333 | term.setCursorPos (14, 6) | |
334 | write (" Sleep Time ") | |
335 | end | |
336 | if selection == 5 then -- Furnace (toggle) | |
337 | term.setCursorPos (14, 7) | |
338 | write ("*Furnace ("..tostring(useFurnace)..") ") | |
339 | if keypress == 32 then | |
340 | if useFurnace == false then | |
341 | useFurnace = true | |
342 | else | |
343 | useFurnace = false | |
344 | end | |
345 | term.setCursorPos (14, 7) | |
346 | write ("*Furnace ("..tostring(useFurnace)..") ") | |
347 | end | |
348 | else | |
349 | term.setCursorPos (14, 7) | |
350 | write (" Furnace ("..tostring(useFurnace)..") ") | |
351 | end | |
352 | if selection == 6 then -- Powered Furnace (toggle) | |
353 | term.setCursorPos (14, 8) | |
354 | write ("*Powered Furnace ("..tostring(poweredFurnace)..") ") | |
355 | if keypress == 32 then | |
356 | if poweredFurnace == false then | |
357 | poweredFurnace = true | |
358 | else | |
359 | poweredFurnace = false | |
360 | end | |
361 | term.setCursorPos (14, 8) | |
362 | write ("*Powered Furnace ("..tostring(poweredFurnace)..") ") | |
363 | end | |
364 | else | |
365 | term.setCursorPos (14, 8) | |
366 | write (" Powered Furnace ("..tostring(poweredFurnace)..") ") | |
367 | end | |
368 | if selection == 7 then -- Sapling Chest (toggle) | |
369 | term.setCursorPos (14, 9) | |
370 | write ("*Sapling Chest ("..tostring(getSaplings)..") ") | |
371 | if keypress == 32 then | |
372 | if getSaplings == false then | |
373 | getSaplings = true | |
374 | else | |
375 | getSaplings = false | |
376 | end | |
377 | term.setCursorPos (14, 9) | |
378 | write ("*Sapling Chest ("..tostring(getSaplings)..") ") | |
379 | end | |
380 | else | |
381 | term.setCursorPos (14, 9) | |
382 | write (" Sapling Chest ("..tostring(getSaplings)..") ") | |
383 | end | |
384 | if selection == 8 then -- Output Chest (toggle) | |
385 | term.setCursorPos (14, 10) | |
386 | write ("*Output Chest ("..tostring(dumpStuff)..") ") | |
387 | if keypress == 32 then | |
388 | if dumpStuff == false then | |
389 | dumpStuff = true | |
390 | else | |
391 | dumpStuff = false | |
392 | end | |
393 | term.setCursorPos (14, 10) | |
394 | write ("*Output Chest ("..tostring(dumpStuff)..") ") | |
395 | end | |
396 | else | |
397 | term.setCursorPos (14, 10) | |
398 | write (" Output Chest ("..tostring(dumpStuff)..") ") | |
399 | end | |
400 | if selection == 9 then -- Quit Program | |
401 | term.setCursorPos (14, 11) | |
402 | write ("*Quit Program ") | |
403 | if keypress == 32 then | |
404 | gotosettings = false | |
405 | term.clear() | |
406 | saveSettings() | |
407 | term.clear() | |
408 | running = false | |
409 | term.clear() | |
410 | term.setCursorPos (1, 1) | |
411 | return | |
412 | end | |
413 | else | |
414 | term.setCursorPos (14, 11) | |
415 | write (" Quit Program ") | |
416 | end | |
417 | --------------------controls----------------------- | |
418 | keypress = 0 | |
419 | sleep (0.2) | |
420 | event, keypress = os.pullEvent("key") | |
421 | if keypress == 17 then -- w key or UP on the menu | |
422 | selection = selection - 1 | |
423 | if selection < 1 then | |
424 | selection = 9 | |
425 | end | |
426 | elseif keypress == 31 then -- s key or DOWN on the menu | |
427 | selection = selection + 1 | |
428 | if selection > 9 then | |
429 | selection = 1 | |
430 | end | |
431 | elseif keypress == 30 then -- a key or Back on the menu | |
432 | gotosettings = false | |
433 | term.clear() | |
434 | graphics() | |
435 | saveSettings() | |
436 | loadSettings() | |
437 | sleep(1) | |
438 | return | |
439 | end | |
440 | end | |
441 | end | |
442 | ||
443 | function changeName() -- Change the turtles name (whatsMyName) | |
444 | term.clear() | |
445 | box() | |
446 | term.setCursorPos (15, 1) | |
447 | write ("Turtle Name") | |
448 | term.setCursorPos (5, 3) | |
449 | write ("My name is "..os.getComputerLabel()) | |
450 | term.setCursorPos (5, 5) | |
451 | write ("Would you like to change it? y/n") | |
452 | sleep(0.3) | |
453 | while true do | |
454 | keypress = 0 | |
455 | event, keypress = os.pullEvent("key") | |
456 | if keypress == 49 then | |
457 | settings() | |
458 | break | |
459 | elseif keypress == 21 then | |
460 | term.setCursorPos (5, 5) | |
461 | write ("What is my new name? ") | |
462 | term.setCursorPos (5, 6) | |
463 | sleep(0.3) | |
464 | whatsMyName = read () | |
465 | os.setComputerLabel(whatsMyName) | |
466 | sleep(1.5) | |
467 | settings() | |
468 | break | |
469 | elseif keypress == 30 then | |
470 | settings() | |
471 | break | |
472 | end | |
473 | end | |
474 | end | |
475 | ||
476 | function changeSlots() -- Slots for dirt, log, sapling 1 and 2, fuel 1 and 2 | |
477 | term.clear() | |
478 | box() | |
479 | term.setCursorPos (15, 1) | |
480 | write ("Change Slots") | |
481 | term.setCursorPos (1, 13) | |
482 | write ("O---a=back, d=select, w=up, s=down ---O") | |
483 | selection = 1 | |
484 | keypress = 0 | |
485 | while true do | |
486 | term.setCursorPos (15, 3) | |
487 | ||
488 | if selection == 1 then -- dirtSlot | |
489 | write ("*Dirt: "..dirtSlot) | |
490 | turtle.select(dirtSlot) | |
491 | if keypress == 32 then | |
492 | term.setCursorPos (10, 9) | |
493 | write ("Type new Dirt slot: ") | |
494 | sleep(0.1) | |
495 | newlong = read () | |
496 | liltest = tonumber ( newlong ) | |
497 | if type( liltest ) ~= "number" then | |
498 | term.setCursorPos (10, 10) | |
499 | write ("I was expecting a number") | |
500 | sleep(1.5) | |
501 | term.setCursorPos (10, 10) | |
502 | write (" ") | |
503 | else | |
504 | dirtSlot = tonumber(newlong) | |
505 | changeSlots() | |
506 | return | |
507 | end | |
508 | term.setCursorPos (10, 9) | |
509 | write (" ") | |
510 | end | |
511 | else | |
512 | write (" Dirt: "..dirtSlot) | |
513 | end | |
514 | term.setCursorPos (15, 4) | |
515 | ||
516 | if selection == 2 then -- logSlot | |
517 | write ("*Log: "..logSlot) | |
518 | turtle.select(logSlot) | |
519 | if keypress == 32 then | |
520 | term.setCursorPos (10, 9) | |
521 | write ("Type new Log Slot: ") | |
522 | sleep(0.1) | |
523 | newwide = read () | |
524 | liltest = tonumber ( newwide ) | |
525 | if type( liltest ) ~= "number" then | |
526 | term.setCursorPos (10, 10) | |
527 | write ("I was expecting a number") | |
528 | sleep(1.5) | |
529 | term.setCursorPos (10, 10) | |
530 | write (" ") | |
531 | else | |
532 | logSlot = tonumber(newwide) | |
533 | changeSlots() | |
534 | return | |
535 | end | |
536 | term.setCursorPos (10, 9) | |
537 | write (" ") | |
538 | end | |
539 | else | |
540 | write (" Log: "..logSlot) | |
541 | end | |
542 | term.setCursorPos (15, 5) | |
543 | ||
544 | if selection == 3 then -- saplingSlot1 | |
545 | write ("*Sapling 1: "..saplingSlot1) | |
546 | turtle.select(saplingSlot1) | |
547 | if keypress == 32 then | |
548 | term.setCursorPos (10, 9) | |
549 | write ("Type new Sapling 1 slot: ") | |
550 | sleep(0.1) | |
551 | newgap = read () | |
552 | liltest = tonumber ( newgap ) | |
553 | if type( liltest ) ~= "number" then | |
554 | term.setCursorPos (10, 10) | |
555 | write ("I was expecting a number") | |
556 | sleep(1.5) | |
557 | term.setCursorPos (10, 10) | |
558 | write (" ") | |
559 | else | |
560 | saplingSlot1 = tonumber(newgap) | |
561 | changeSlots() | |
562 | return | |
563 | end | |
564 | term.setCursorPos (10, 9) | |
565 | write (" ") | |
566 | end | |
567 | else | |
568 | write (" Sapling 1: "..saplingSlot1) | |
569 | end | |
570 | term.setCursorPos (15, 6) | |
571 | ||
572 | if selection == 4 then -- saplingSlot2 | |
573 | write ("*Sapling 2: "..saplingSlot2) | |
574 | turtle.select(saplingSlot2) | |
575 | if keypress == 32 then | |
576 | term.setCursorPos (10, 9) | |
577 | write ("Type new Sapling 2 slot: ") | |
578 | sleep(0.1) | |
579 | newgap = read () | |
580 | liltest = tonumber ( newgap ) | |
581 | if type( liltest ) ~= "number" then | |
582 | term.setCursorPos (10, 10) | |
583 | write ("I was expecting a number") | |
584 | sleep(1.5) | |
585 | term.setCursorPos (10, 10) | |
586 | write (" ") | |
587 | else | |
588 | saplingSlot2 = tonumber(newgap) | |
589 | changeSlots() | |
590 | return | |
591 | end | |
592 | term.setCursorPos (10, 9) | |
593 | write (" ") | |
594 | end | |
595 | else | |
596 | write (" Sapling 2: "..saplingSlot2) | |
597 | end | |
598 | term.setCursorPos (15, 7) | |
599 | ||
600 | if selection == 5 then -- fuelSlot1 | |
601 | write ("*Fuel 1: "..fuelSlot1) | |
602 | turtle.select(fuelSlot1) | |
603 | if keypress == 32 then | |
604 | term.setCursorPos (10, 9) | |
605 | write ("Type new Fuel 1 slot: ") | |
606 | sleep(0.1) | |
607 | newgap = read () | |
608 | liltest = tonumber ( newgap ) | |
609 | if type( liltest ) ~= "number" then | |
610 | term.setCursorPos (10, 10) | |
611 | write ("I was expecting a number") | |
612 | sleep(1.5) | |
613 | term.setCursorPos (10, 10) | |
614 | write (" ") | |
615 | else | |
616 | fuelSlot1 = tonumber(newgap) | |
617 | changeSlots() | |
618 | return | |
619 | end | |
620 | term.setCursorPos (10, 9) | |
621 | write (" ") | |
622 | end | |
623 | else | |
624 | write (" Fuel 1: "..fuelSlot1) | |
625 | end | |
626 | term.setCursorPos (15, 8) | |
627 | ||
628 | if selection == 6 then ---- fuelSlot2 | |
629 | write ("*Fuel 2: "..fuelSlot2) | |
630 | turtle.select(fuelSlot2) | |
631 | if keypress == 32 then | |
632 | term.setCursorPos (10, 9) | |
633 | write ("Type new Sapling 2 slot: ") | |
634 | sleep(0.1) | |
635 | newgap = read () | |
636 | liltest = tonumber ( newgap ) | |
637 | if type( liltest ) ~= "number" then | |
638 | term.setCursorPos (10, 10) | |
639 | write ("I was expecting a number") | |
640 | sleep(1.5) | |
641 | term.setCursorPos (10, 10) | |
642 | write (" ") | |
643 | else | |
644 | fuelSlot2 = tonumber(newgap) | |
645 | changeSlots() | |
646 | return | |
647 | end | |
648 | term.setCursorPos (10, 9) | |
649 | write (" ") | |
650 | end | |
651 | else | |
652 | write (" Fuel 2: "..fuelSlot2) | |
653 | end | |
654 | ||
655 | -- listen for keyboard input | |
656 | sleep(0.3) | |
657 | keypress = 0 | |
658 | event, keypress = os.pullEvent("key") | |
659 | if keypress == 17 then | |
660 | selection = selection - 1 | |
661 | if selection < 1 then | |
662 | selection = 6 | |
663 | end | |
664 | elseif keypress == 31 then | |
665 | selection = selection + 1 | |
666 | if selection > 6 then | |
667 | selection = 1 | |
668 | end | |
669 | elseif keypress == 30 then | |
670 | settings() | |
671 | return | |
672 | end | |
673 | term.setCursorPos (15, 8) | |
674 | write (" ") | |
675 | end | |
676 | end | |
677 | ||
678 | function changeSleepTime() -- Change how long the turtle waits (sleepTime) | |
679 | term.clear() | |
680 | box() | |
681 | term.setCursorPos (15, 1) | |
682 | write ("Sleep Time") | |
683 | term.setCursorPos (3, 3) | |
684 | write ("I will currently sleep "..sleepTime.." seconds.") | |
685 | term.setCursorPos (3, 5) | |
686 | write ("Would you like to change that? y/n") | |
687 | sleep(0.3) | |
688 | while true do | |
689 | keypress = 0 | |
690 | event, keypress = os.pullEvent("key") | |
691 | if keypress == 49 then | |
692 | settings() | |
693 | break | |
694 | elseif keypress == 21 then | |
695 | term.setCursorPos (3, 5) | |
696 | write ("How long should I sleep? ") | |
697 | term.setCursorPos (3, 6) | |
698 | sleep(0.3) | |
699 | newTime = read () | |
700 | liltest = tonumber ( newTime ) | |
701 | if type( liltest ) ~= "number" then | |
702 | term.setCursorPos (15, 10) | |
703 | write ("I was expecting a number") | |
704 | sleep(1.5) | |
705 | term.setCursorPos (15, 10) | |
706 | write (" ") | |
707 | changeSleepTime() | |
708 | return | |
709 | else | |
710 | sleepTime = tonumber(newTime) | |
711 | end | |
712 | sleep(1.5) | |
713 | settings() | |
714 | break | |
715 | elseif keypress == 30 then | |
716 | settings() | |
717 | break | |
718 | end | |
719 | end | |
720 | end | |
721 | ||
722 | function farmLayout() -- Change the layout for the farm | |
723 | -- graphical setup | |
724 | term.clear() | |
725 | box() | |
726 | line(13) | |
727 | selection = 1 | |
728 | keypress = 0 | |
729 | -- show demonstration | |
730 | term.setCursorPos (15, 1) | |
731 | write ("Farm Layout") | |
732 | term.setCursorPos (1, 13) | |
733 | write ("O---a=back, d=select, w=up, s=down ---O") | |
734 | term.setCursorPos (4, 3) | |
735 | write ("Width") | |
736 | term.setCursorPos (3, 4) | |
737 | write ("T T T") | |
738 | term.setCursorPos (3, 5) | |
739 | write ("T T T") -- last char is on 10, 4 | |
740 | term.setCursorPos (3, 6) | |
741 | write ("T T T") | |
742 | term.setCursorPos (3, 7) | |
743 | write ("T T T") | |
744 | term.setCursorPos (3, 8) | |
745 | write ("T T T") | |
746 | term.setCursorPos (3, 9) | |
747 | write ("@") | |
748 | term.setCursorPos (3, 10) | |
749 | write ("^ Turtle") | |
750 | term.setCursorPos (3, 11) | |
751 | write ("| facing") | |
752 | term.setCursorPos (3, 12) | |
753 | write ("| Up") | |
754 | -- write the word length vertically | |
755 | term.setCursorPos (11, 3) | |
756 | write ("L") | |
757 | term.setCursorPos (11, 4) | |
758 | write ("e") | |
759 | term.setCursorPos (11, 5) | |
760 | write ("n") | |
761 | term.setCursorPos (11, 6) | |
762 | write ("g") | |
763 | term.setCursorPos (11, 7) | |
764 | write ("t") | |
765 | term.setCursorPos (11, 8) | |
766 | write ("h") | |
767 | ||
768 | while true do | |
769 | term.setCursorPos (15, 3) | |
770 | ||
771 | if selection == 1 then -- long | |
772 | write ("*Length: "..long) | |
773 | term.setCursorPos (15, 8) | |
774 | write ("Number of trees long") | |
775 | if keypress == 32 then | |
776 | term.setCursorPos (15, 9) | |
777 | write ("Type new Length: ") | |
778 | sleep(0.4) | |
779 | newlong = read () | |
780 | liltest = tonumber ( newlong ) | |
781 | if type( liltest ) ~= "number" then | |
782 | term.setCursorPos (15, 10) | |
783 | write ("I was expecting a number") | |
784 | sleep(1.5) | |
785 | term.setCursorPos (15, 10) | |
786 | write (" ") | |
787 | elseif liltest > 0 then | |
788 | long = tonumber(newlong) | |
789 | firstRun = true | |
790 | farmLayout() | |
791 | return | |
792 | elseif liltest == 0 then | |
793 | term.setCursorPos (15, 10) | |
794 | write ("Must be more than Zero") | |
795 | sleep(1.5) | |
796 | farmLayout() | |
797 | return | |
798 | end | |
799 | term.setCursorPos (15, 10) | |
800 | write (" ") | |
801 | end | |
802 | else | |
803 | write (" Length: "..long) | |
804 | end | |
805 | ||
806 | term.setCursorPos (15, 4) | |
807 | ||
808 | if selection == 2 then -- wide | |
809 | write ("*Width: "..wide) | |
810 | term.setCursorPos (15, 8) | |
811 | write ("Number of trees wide") | |
812 | if keypress == 32 then | |
813 | term.setCursorPos (15, 9) | |
814 | write ("Type new Width: ") | |
815 | sleep(0.4) | |
816 | newwide = read () | |
817 | liltest = tonumber ( newwide ) | |
818 | if type( liltest ) ~= "number" then | |
819 | term.setCursorPos (15, 10) | |
820 | write ("I was expecting a number") | |
821 | sleep(1.5) | |
822 | term.setCursorPos (15, 10) | |
823 | write (" ") | |
824 | elseif liltest > 0 then | |
825 | wide = tonumber(newwide) | |
826 | firstRun = true | |
827 | farmLayout() | |
828 | return | |
829 | elseif liltest == 0 then | |
830 | term.setCursorPos (15, 10) | |
831 | write ("Must be more than Zero") | |
832 | sleep(1.5) | |
833 | farmLayout() | |
834 | return | |
835 | end | |
836 | term.setCursorPos (15, 9) | |
837 | write (" ") | |
838 | end | |
839 | else | |
840 | write (" Width: "..wide) | |
841 | end | |
842 | ||
843 | term.setCursorPos (15, 5) | |
844 | ||
845 | if selection == 3 then -- saplingGap/Tree Gap | |
846 | write ("*Tree Gap: "..saplingGap) | |
847 | term.setCursorPos (15, 8) | |
848 | write ("Blocks between Trees") | |
849 | if keypress == 32 then | |
850 | term.setCursorPos (15, 9) | |
851 | write ("Type new Gap size: ") | |
852 | sleep(0.4) | |
853 | newgap = read () | |
854 | liltest = tonumber ( newgap ) | |
855 | if type( liltest ) ~= "number" then | |
856 | term.setCursorPos (15, 10) | |
857 | write ("I was expecting a number") | |
858 | sleep(1.5) | |
859 | term.setCursorPos (15, 10) | |
860 | write (" ") | |
861 | else | |
862 | saplingGap = tonumber(newgap) | |
863 | farmLayout() | |
864 | return | |
865 | end | |
866 | term.setCursorPos (15, 9) | |
867 | write (" ") | |
868 | end | |
869 | else | |
870 | write (" Tree Gap: "..saplingGap) | |
871 | end | |
872 | term.setCursorPos (15, 6) | |
873 | ||
874 | if selection == 4 then -- wallGap/ Turtle Gap | |
875 | write ("*Turtle Gap: "..wallGap) | |
876 | term.setCursorPos (15, 8) | |
877 | write ("Distance to First tree") | |
878 | if keypress == 32 then | |
879 | term.setCursorPos (15, 9) | |
880 | write ("Type new Gap size: ") | |
881 | sleep(0.1) | |
882 | newgap = read () | |
883 | liltest = tonumber ( newgap ) | |
884 | if type( liltest ) ~= "number" then | |
885 | term.setCursorPos (15, 10) | |
886 | write ("I was expecting a number") | |
887 | sleep(1.5) | |
888 | term.setCursorPos (15, 10) | |
889 | write (" ") | |
890 | elseif liltest > 0 then | |
891 | wallGap = tonumber(newgap) | |
892 | farmLayout() | |
893 | return | |
894 | elseif liltest == 0 then | |
895 | term.setCursorPos (15, 10) | |
896 | write ("Must be more than Zero") | |
897 | sleep(1.5) | |
898 | farmLayout() | |
899 | return | |
900 | end | |
901 | term.setCursorPos (15, 9) | |
902 | write (" ") | |
903 | end | |
904 | else | |
905 | write (" Turtle Gap: "..wallGap) | |
906 | end | |
907 | -- rowOffset | |
908 | term.setCursorPos (15, 7) | |
909 | ||
910 | if selection == 5 then -- rowOffset | |
911 | write ("*Row Offset: "..rowOffset) | |
912 | term.setCursorPos (15, 8) | |
913 | write ("Move first row") | |
914 | term.setCursorPos (15, 9) | |
915 | write ("left with positive num") | |
916 | term.setCursorPos (15, 10) | |
917 | write ("right with negative num") | |
918 | if keypress == 32 then | |
919 | term.setCursorPos (15, 11) | |
920 | write ("Type new Row Offset: ") | |
921 | sleep(0.1) | |
922 | newgap = read () | |
923 | liltest = tonumber ( newgap ) | |
924 | if type( liltest ) ~= "number" then | |
925 | term.setCursorPos (15, 10) | |
926 | write ("I was expecting a number") | |
927 | sleep(1.5) | |
928 | term.setCursorPos (15, 10) | |
929 | write (" ") | |
930 | else | |
931 | rowOffset = tonumber(newgap) | |
932 | farmLayout() | |
933 | return | |
934 | end | |
935 | term.setCursorPos (15, 11) | |
936 | write (" ") | |
937 | end | |
938 | else | |
939 | write (" Row Offset: "..rowOffset) | |
940 | end | |
941 | ||
942 | -- listen for keyboard input | |
943 | sleep(0.4) | |
944 | keypress = 0 | |
945 | event, keypress = os.pullEvent("key") | |
946 | if keypress == 17 then | |
947 | selection = selection - 1 | |
948 | if selection < 1 then | |
949 | selection = 5 | |
950 | end | |
951 | elseif keypress == 31 then | |
952 | selection = selection + 1 | |
953 | if selection > 5 then | |
954 | selection = 1 | |
955 | end | |
956 | elseif keypress == 30 then | |
957 | sleepTime = baseTime - ((long * wide) * 5) | |
958 | if sleepTime < 60 then | |
959 | sleepTime = 60 | |
960 | end | |
961 | settings() | |
962 | return | |
963 | end | |
964 | term.setCursorPos (15, 8) | |
965 | write (" ") | |
966 | term.setCursorPos (15, 9) | |
967 | write (" ") | |
968 | term.setCursorPos (15, 10) | |
969 | write (" ") | |
970 | end | |
971 | end | |
972 | ||
973 | function startup() -- Get inital lengh and width on first startup | |
974 | term.clear() | |
975 | term.setCursorPos (1, 1) | |
976 | print ("") | |
977 | print ("W I D E") | |
978 | print ("T T T L") | |
979 | print ("T T T O") | |
980 | print ("T T T N") | |
981 | print ("T T T G") | |
982 | print ("@ <-- Turtle facing Up") | |
983 | print ("") | |
984 | print ("How many trees Long?") | |
985 | long = read () | |
986 | liltesta = tonumber ( long ) | |
987 | if type( liltesta ) ~= "number" then | |
988 | print ("I was expecting a number...") | |
989 | print ("Lets try that again.") | |
990 | sleep(2) | |
991 | startup() | |
992 | return | |
993 | end | |
994 | print ("How many trees Wide?") | |
995 | wide = read () | |
996 | liltestb = tonumber ( wide ) | |
997 | if type( liltestb ) ~= "number" then | |
998 | print ("I was expecting a number...") | |
999 | print ("Lets try that again.") | |
1000 | sleep(2) | |
1001 | startup() | |
1002 | return | |
1003 | end | |
1004 | sleep (1) | |
1005 | if liltesta == 0 then long = 1 end | |
1006 | if liltestb == 0 then wide = 1 end | |
1007 | while ((wide + long) * saplingGap) > minFuel do | |
1008 | minFuel = minFuel + 50 | |
1009 | end | |
1010 | sleepTime = baseTime - ((long * wide) * 5) | |
1011 | if sleepTime < 60 then | |
1012 | sleepTime = 60 | |
1013 | end | |
1014 | end | |
1015 | ||
1016 | -- SECTION: Graphics ------------------------------------------------------------------------------ | |
1017 | ||
1018 | function box() -- 39x12 box used in some menus | |
1019 | term.setCursorPos (1, 1) | |
1020 | write ("O-------------------------------------O") | |
1021 | for i = 2, 12 do | |
1022 | term.setCursorPos (1, i) | |
1023 | clearLine() | |
1024 | end | |
1025 | term.setCursorPos (1, 13) | |
1026 | write ("O-------------------------------------O") | |
1027 | end | |
1028 | ||
1029 | function line(char) -- 12 long vertical line used in some menus | |
1030 | for i = 2, 12 do | |
1031 | term.setCursorPos (char, i) | |
1032 | write ("|") | |
1033 | end | |
1034 | end | |
1035 | ||
1036 | function totals() -- updates the totals on main GUI | |
1037 | term.setCursorPos (3, 6) | |
1038 | write ("Tree Total: "..treeTotal) | |
1039 | term.setCursorPos (24, 6) | |
1040 | write ("Fuel "..turtle.getFuelLevel().."/" ..minFuel.." ") | |
1041 | term.setCursorPos (5, 7) | |
1042 | write ("Charcoal: "..charcoalMade) | |
1043 | term.setCursorPos (5, 8) | |
1044 | write ("Saplings: "..saplingsPlanted) | |
1045 | term.setCursorPos (24, 8) | |
1046 | write ("Farm: "..long.."x"..wide) | |
1047 | end | |
1048 | ||
1049 | function graphics() -- displays graphics for main GUI, not run often | |
1050 | term.setCursorPos (1, 1) | |
1051 | write ("O----(^u^)----------------------------O") | |
1052 | mylable = os.getComputerLabel() | |
1053 | term.setCursorPos (15, 1) | |
1054 | write (mylable) | |
1055 | term.setCursorPos (1, 2) | |
1056 | write ("|") | |
1057 | term.setCursorPos (39, 2) | |
1058 | write ("|") | |
1059 | term.setCursorPos (1, 3) | |
1060 | write ("|") | |
1061 | term.setCursorPos (39, 3) | |
1062 | write ("|") | |
1063 | term.setCursorPos (1, 4) | |
1064 | write ("|") | |
1065 | term.setCursorPos (39, 4) | |
1066 | write ("|") | |
1067 | term.setCursorPos (1, 5) | |
1068 | write ("O--------------------O----------------O") | |
1069 | term.setCursorPos (1, 6) | |
1070 | write ("|") | |
1071 | term.setCursorPos (22, 6) | |
1072 | write ("|") | |
1073 | term.setCursorPos (39, 6) | |
1074 | write ("|") | |
1075 | term.setCursorPos (1, 7) | |
1076 | write ("|") | |
1077 | term.setCursorPos (22, 7) | |
1078 | write ("O----------------O") | |
1079 | term.setCursorPos (1, 8) | |
1080 | write ("|") | |
1081 | term.setCursorPos (22, 8) | |
1082 | write ("|") | |
1083 | term.setCursorPos (39, 8) | |
1084 | write ("|") | |
1085 | term.setCursorPos (1, 9) | |
1086 | write ("O--------------------O----------------O") | |
1087 | if useFurnace == true then | |
1088 | term.setCursorPos (12, 11) | |
1089 | write ("Furnace Above Me") | |
1090 | end | |
1091 | if getSaplings == true then | |
1092 | term.setCursorPos (3, 12) | |
1093 | write ("<--Sapling Chest") | |
1094 | end | |
1095 | if dumpStuff == true then | |
1096 | term.setCursorPos (22, 12) | |
1097 | write ("Dropoff Chest-->") | |
1098 | end | |
1099 | if useFurnace == true or getSaplings == true or dumpStuff == true then | |
1100 | term.setCursorPos (14, 10) | |
1101 | write ("Configuration") | |
1102 | term.setCursorPos (17, 13) | |
1103 | write ("My Back") | |
1104 | end | |
1105 | totals() | |
1106 | end | |
1107 | ||
1108 | function clearLine() -- used to clear a line at the previously set cursor postion | |
1109 | local x, y = term.getCursorPos() | |
1110 | write ("| |") | |
1111 | term.setCursorPos (1, y) | |
1112 | end | |
1113 | ||
1114 | -- SECTION: Movement ------------------------------------------------------------------------------ | |
1115 | ||
1116 | function forward(value) -- moves a quantity of blocks forward even with obstructions | |
1117 | for i = 1, value do | |
1118 | if turtle.detect() == true then | |
1119 | turtle.dig() | |
1120 | end | |
1121 | if facing == 1 then -- Cordinates code for movement x, z | |
1122 | cordsx = cordsx + 1 | |
1123 | elseif facing == 2 then | |
1124 | cordsz = cordsz + 1 | |
1125 | elseif facing == 3 then | |
1126 | cordsx = cordsx - 1 | |
1127 | elseif facing == 4 then | |
1128 | cordsz = cordsz - 1 | |
1129 | end | |
1130 | saveCords() | |
1131 | local movement = false | |
1132 | while not movement do | |
1133 | movement = turtle.forward () | |
1134 | if not movement and turtle.detect () then | |
1135 | turtle.dig () | |
1136 | end | |
1137 | end | |
1138 | end | |
1139 | end | |
1140 | ||
1141 | function up(value) -- moves up | |
1142 | for i = 1, value do | |
1143 | cordsy = cordsy + 1 -- cords code for y up | |
1144 | saveCords() | |
1145 | local movement = false | |
1146 | while not movement do | |
1147 | movement = turtle.up () | |
1148 | if not movement and turtle.detectUp () then | |
1149 | turtle.digUp () | |
1150 | end | |
1151 | end | |
1152 | end | |
1153 | end | |
1154 | ||
1155 | function down (value) -- moves down | |
1156 | for i = 1, value do | |
1157 | cordsy = cordsy - 1 | |
1158 | saveCords() | |
1159 | movement = false | |
1160 | while not movement do | |
1161 | movement = turtle.down () | |
1162 | if not movement and turtle.detectDown () then | |
1163 | turtle.digDown () | |
1164 | end | |
1165 | end | |
1166 | end | |
1167 | end | |
1168 | ||
1169 | function turn(way) -- easier turning | |
1170 | if way == "left" then -- faces left | |
1171 | facing = facing - 1 | |
1172 | if facing < 1 then | |
1173 | facing = 4 | |
1174 | end | |
1175 | saveCords() | |
1176 | turtle.turnLeft() | |
1177 | elseif way == "right" then -- faces right | |
1178 | facing = facing + 1 | |
1179 | if facing > 4 then | |
1180 | facing = 1 | |
1181 | end | |
1182 | saveCords() | |
1183 | turtle.turnRight() | |
1184 | elseif way == "back" then -- turnes around | |
1185 | facing = facing + 1 | |
1186 | if facing > 4 then | |
1187 | facing = 1 | |
1188 | end | |
1189 | saveCords() | |
1190 | turtle.turnRight() | |
1191 | facing = facing + 1 | |
1192 | if facing > 4 then | |
1193 | facing = 1 | |
1194 | end | |
1195 | saveCords() | |
1196 | turtle.turnRight() | |
1197 | end | |
1198 | end | |
1199 | ||
1200 | -- SECTION: Resource Checking --------------------------------------------------------------------- | |
1201 | ||
1202 | local function saplingTotal() -- returns curent total of saplings | |
1203 | if running == false then return end | |
1204 | if saplingSlot1 ~= saplingSlot2 then | |
1205 | sTotal1 = turtle.getItemCount(saplingSlot1) | |
1206 | sTotal2 = turtle.getItemCount(saplingSlot2) | |
1207 | return sTotal1 + sTotal2 | |
1208 | else | |
1209 | return turtle.getItemCount(saplingSlot1) + 1 | |
1210 | end | |
1211 | end | |
1212 | ||
1213 | function saplings() -- ensures the turtle has enough saplings for a logging run + 1 | |
1214 | if running == false then return end | |
1215 | imdone = false | |
1216 | term.setCursorPos (1, 4) | |
1217 | clearLine() | |
1218 | term.setCursorPos (1, 3) | |
1219 | clearLine() | |
1220 | term.setCursorPos (1, 2) | |
1221 | clearLine() | |
1222 | sapNeed = saplingTotal() | |
1223 | while sapNeed-1 < (long * wide) do | |
1224 | turtle.select(saplingSlot1) | |
1225 | term.setCursorPos(1, 2) | |
1226 | write ("| Put saplings in slot "..saplingSlot1..". Extras ") | |
1227 | term.setCursorPos (1, 3) | |
1228 | write ("| go into the Left chest and slot "..saplingSlot2..".") | |
1229 | term.setCursorPos (1, 4) | |
1230 | write ("| "..(1+(long*wide)-sapNeed).." more saplings needed...") | |
1231 | sleep (0.5) | |
1232 | sapNeed = saplingTotal() | |
1233 | end | |
1234 | imdone = true | |
1235 | end | |
1236 | ||
1237 | function dirt() -- ensure the turtle has enough dirt | |
1238 | if running == false then return end | |
1239 | imdone = false | |
1240 | term.setCursorPos (1, 4) | |
1241 | clearLine() | |
1242 | term.setCursorPos (1, 3) | |
1243 | clearLine() | |
1244 | term.setCursorPos (1, 2) | |
1245 | clearLine() | |
1246 | if firstRun == true then | |
1247 | if (long * wide) + 1 < 64 then | |
1248 | while turtle.getItemCount(dirtSlot) < (long * wide) + 1 do | |
1249 | term.setCursorPos(1, 2) | |
1250 | turtle.select(dirtSlot) | |
1251 | write ("| Please put dirt in slot "..dirtSlot) | |
1252 | dirtplox = (long*wide) - turtle.getItemCount(dirtSlot) + 1 | |
1253 | term.setCursorPos(1, 3) | |
1254 | write ("| "..dirtplox.." dirt needed...") | |
1255 | term.setCursorPos (1, 4) | |
1256 | write ("| Press any key to change settings.") | |
1257 | sleep (0.5) | |
1258 | end | |
1259 | else | |
1260 | while turtle.getItemCount(dirtSlot) < 64 do | |
1261 | omgDirt = 1 +(long * wide) - 63 | |
1262 | term.setCursorPos(1, 2) | |
1263 | turtle.select(dirtSlot) | |
1264 | write ("| Please put 64 dirt in slot "..dirtSlot) | |
1265 | dirtplox = (long*wide) - turtle.getItemCount(dirtSlot) + 1 | |
1266 | term.setCursorPos(1, 3) | |
1267 | write ("| "..omgDirt.." dirt will be needed next run") | |
1268 | term.setCursorPos (1, 4) | |
1269 | write ("| Press any key to change settings.") | |
1270 | sleep (0.5) | |
1271 | end | |
1272 | end | |
1273 | else | |
1274 | if (long * wide) + 1 < 64 then | |
1275 | while turtle.getItemCount(dirtSlot) < 1 do | |
1276 | term.setCursorPos(1, 2) | |
1277 | turtle.select(dirtSlot) | |
1278 | write ("| Please put dirt in slot "..dirtSlot) | |
1279 | term.setCursorPos(1, 3) | |
1280 | write ("| 1 dirt needed...") | |
1281 | term.setCursorPos (1, 4) | |
1282 | write ("| Press any key to change settings.") | |
1283 | sleep (0.5) | |
1284 | end | |
1285 | else | |
1286 | if omgDirt == 0 then | |
1287 | while turtle.getItemCount(dirtSlot) < 1 do | |
1288 | term.setCursorPos(1, 2) | |
1289 | turtle.select(dirtSlot) | |
1290 | write ("| Please put dirt in slot "..dirtSlot) | |
1291 | term.setCursorPos(1, 3) | |
1292 | write ("| 1 dirt needed...") | |
1293 | term.setCursorPos (1, 4) | |
1294 | write ("| Press any key to change settings.") | |
1295 | sleep (0.5) | |
1296 | end | |
1297 | elseif omgDirt > 0 then | |
1298 | if omgDirt > 64 then | |
1299 | while turtle.getItemCount(dirtSlot) < 64 do -- 64 + | |
1300 | omgDirt = omgDirt - 63 | |
1301 | term.setCursorPos(1, 2) | |
1302 | turtle.select(dirtSlot) | |
1303 | write ("| Please put 64 dirt in slot "..dirtSlot) | |
1304 | dirtplox = (long*wide) - turtle.getItemCount(dirtSlot) + 1 | |
1305 | term.setCursorPos(1, 3) | |
1306 | write ("| "..omgDirt.." dirt will be needed next run") | |
1307 | term.setCursorPos (1, 4) | |
1308 | write ("| Press any key to change settings.") | |
1309 | sleep (0.5) | |
1310 | end | |
1311 | else | |
1312 | while turtle.getItemCount(dirtSlot) < omgDirt do -- 64 or less | |
1313 | term.setCursorPos(1, 2) | |
1314 | turtle.select(dirtSlot) | |
1315 | write ("| Please put "..omgDirt.." dirt in slot "..dirtSlot) | |
1316 | dirtplox = (long*wide) - turtle.getItemCount(dirtSlot) + 1 | |
1317 | term.setCursorPos(1, 3) | |
1318 | write ("| No more dirt will be needed next run") | |
1319 | term.setCursorPos (1, 4) | |
1320 | write ("| Press any key to change settings.") | |
1321 | sleep (0.5) | |
1322 | end | |
1323 | omgDirt = 0 | |
1324 | end | |
1325 | end | |
1326 | end | |
1327 | end | |
1328 | imdone = true | |
1329 | end | |
1330 | ||
1331 | function someFuel() -- ensure the turtle has fuel before leaving home | |
1332 | if running == false then return end | |
1333 | imdone = false | |
1334 | if fuelOn == true then | |
1335 | treeNumbers = ((wide * long) / 5) + 1 | |
1336 | fuelCheck = turtle.getItemCount(fuelSlot1) + turtle.getItemCount(fuelSlot2) | |
1337 | while fuelCheck < (treeNumbers + charcoalNumber) do | |
1338 | term.setCursorPos (1, 4) | |
1339 | clearLine() | |
1340 | term.setCursorPos (1, 3) | |
1341 | clearLine() | |
1342 | term.setCursorPos (1, 2) | |
1343 | clearLine() | |
1344 | write ("| Please put more fuel in slot "..fuelSlot1.." or "..fuelSlot2) | |
1345 | term.setCursorPos (1, 3) | |
1346 | write ("| I need at least "..(treeNumbers + charcoalNumber).." fuel before") | |
1347 | term.setCursorPos (1, 4) | |
1348 | write ("| I can go logging!") | |
1349 | turtle.select(fuelSlot1) | |
1350 | sleep(1) | |
1351 | fuelCheck = turtle.getItemCount(fuelSlot1) + turtle.getItemCount(fuelSlot2) | |
1352 | end | |
1353 | end | |
1354 | imdone = true | |
1355 | end | |
1356 | ||
1357 | function refillSaplings() -- get saplings from sapling chest | |
1358 | if running == false then return end | |
1359 | if getSaplings == true then | |
1360 | term.setCursorPos (1, 4) | |
1361 | clearLine() | |
1362 | term.setCursorPos (1, 3) | |
1363 | clearLine() | |
1364 | term.setCursorPos (1, 2) | |
1365 | clearLine() | |
1366 | write ("| Refilling Saplings") | |
1367 | turn("left") | |
1368 | checkfuelSlot2 = turtle.getItemCount(fuelSlot2) | |
1369 | turtle.select(saplingSlot1) | |
1370 | turtle.suck() | |
1371 | turtle.select(saplingSlot2) | |
1372 | turtle.suck() | |
1373 | if not turtle.compareTo(saplingSlot1) then | |
1374 | for cnt = 1, 16 do | |
1375 | if cnt ~= logSlot then | |
1376 | if cnt ~= fuelSlot1 then | |
1377 | if cnt ~= fuelSlot2 then | |
1378 | if cnt ~= saplingSlot1 then | |
1379 | if cnt ~= saplingSlot2 then | |
1380 | if cnt ~= dirtSlot then | |
1381 | turtle.transferTo(cnt, 64) | |
1382 | end | |
1383 | end | |
1384 | end | |
1385 | end | |
1386 | end | |
1387 | end | |
1388 | end | |
1389 | end | |
1390 | for cnt=1, 16 do -- picked up too many? put them back! | |
1391 | if cnt ~= saplingSlot1 then | |
1392 | if cnt ~= saplingSlot2 then | |
1393 | if turtle.getItemCount(cnt) > 0 then | |
1394 | turtle.select(cnt) | |
1395 | if turtle.compareTo(saplingSlot1) then | |
1396 | turtle.drop() | |
1397 | end | |
1398 | end | |
1399 | end | |
1400 | end | |
1401 | end | |
1402 | if checkfuelSlot2 < turtle.getItemCount(fuelSlot2) then | |
1403 | turtle.select(fuelSlot2) | |
1404 | for cnt = 1, 16 do | |
1405 | if cnt ~= logSlot then | |
1406 | if cnt ~= fuelSlot1 then | |
1407 | if cnt ~= fuelSlot2 then | |
1408 | if cnt ~= saplingSlot1 then | |
1409 | if cnt ~= saplingSlot2 then | |
1410 | if cnt ~= dirtSlot then | |
1411 | turtle.transferTo(cnt, 64) | |
1412 | end | |
1413 | end | |
1414 | end | |
1415 | end | |
1416 | end | |
1417 | end | |
1418 | end | |
1419 | end | |
1420 | turn("right") | |
1421 | end | |
1422 | end | |
1423 | ||
1424 | -- SECTION: Fueling and Charcoal Making ----------------------------------------------------------- | |
1425 | ||
1426 | function fuel() -- refuels the turtle and ensures it has fuel | |
1427 | if running == false then return end | |
1428 | imdone = false | |
1429 | if fuelOn == true then | |
1430 | term.setCursorPos (1, 4) | |
1431 | clearLine() | |
1432 | term.setCursorPos (1, 3) | |
1433 | clearLine() | |
1434 | term.setCursorPos (1, 2) | |
1435 | clearLine() | |
1436 | write ("| I'm checking my fuel") | |
1437 | while turtle.getFuelLevel() < minFuel do -- compare current fuel level to the minimum | |
1438 | if turtle.getItemCount(fuelSlot1) > 1 then -- refuels from slot 1 if there is more than 1 fuel | |
1439 | turtle.select(fuelSlot1) | |
1440 | turtle.refuel(1) | |
1441 | elseif turtle.getItemCount(fuelSlot2) ~= 0 then -- if slot 1 is empty, tries to fuel from slot 2 | |
1442 | turtle.select(fuelSlot2) | |
1443 | turtle.refuel(1) | |
1444 | else -- if there is not enough fuel, ask the player for some | |
1445 | term.setCursorPos (1, 2) | |
1446 | turtle.select(fuelSlot1) | |
1447 | if useFurnace == false then | |
1448 | write ("| Please put more fuel in slot "..fuelSlot1.." or "..fuelSlot2) | |
1449 | term.setCursorPos (1, 4) | |
1450 | write ("| Press any key to change settings.") | |
1451 | sleep (1) | |
1452 | else | |
1453 | write ("| Please put more fuel in slot "..fuelSlot1) | |
1454 | term.setCursorPos (1, 3) | |
1455 | write ("| Reserve slot "..fuelSlot2.." for charcoal") | |
1456 | term.setCursorPos (1, 4) | |
1457 | write ("| Press any key to change settings.") | |
1458 | sleep (1) | |
1459 | end | |
1460 | end | |
1461 | end | |
1462 | term.setCursorPos (24, 6) | |
1463 | write ("Fuel "..turtle.getFuelLevel().."/" ..minFuel.." ") | |
1464 | end | |
1465 | imdone = true | |
1466 | end | |
1467 | ||
1468 | function furnaceCheck() -- checks to see if it has a furnace, but only if fuelOn is enabled and poweredFurnace is disabled | |
1469 | if running == false then return end | |
1470 | if fuelOn == true then | |
1471 | if poweredFurnace == false then | |
1472 | term.setCursorPos (1, 4) | |
1473 | clearLine() | |
1474 | term.setCursorPos (1, 3) | |
1475 | clearLine() | |
1476 | term.setCursorPos (1, 2) | |
1477 | clearLine() | |
1478 | write ("| Do I have a furnace?") | |
1479 | if turtle.detectUp() then -- check for a furnace | |
1480 | if turtle.getItemCount(fuelSlot1) > 2 then | |
1481 | turtle.select(fuelSlot1) | |
1482 | rememberNumber = turtle.getItemCount(fuelSlot1) | |
1483 | turtle.dropUp(2) | |
1484 | sleep(0.5) | |
1485 | turtle.suckUp() | |
1486 | if rememberNumber == turtle.getItemCount(fuelSlot1) then | |
1487 | return true | |
1488 | elseif rememberNumber == turtle.getItemCount(fuelSlot1)+1 then | |
1489 | turtle.suckDown() | |
1490 | return true | |
1491 | elseif rememberNumber < turtle.getItemCount(fuelSlot1) then | |
1492 | return true | |
1493 | end | |
1494 | elseif turtle.getItemCount(fuelSlot2) > 2 then | |
1495 | turtle.select(fuelSlot2) | |
1496 | rememberNumber = turtle.getItemCount(fuelSlot2) | |
1497 | turtle.dropUp(2) | |
1498 | sleep(0.5) | |
1499 | turtle.suckUp() | |
1500 | if rememberNumber == turtle.getItemCount(fuelSlot2) then | |
1501 | return true | |
1502 | elseif rememberNumber == turtle.getItemCount(fuelSlot2)+1 then | |
1503 | turtle.suckDown() | |
1504 | return true | |
1505 | elseif rememberNumber < turtle.getItemCount(fuelSlot2) then | |
1506 | return true | |
1507 | end | |
1508 | else | |
1509 | turtle.suckDown() | |
1510 | return false | |
1511 | end | |
1512 | end | |
1513 | else return true | |
1514 | end | |
1515 | end | |
1516 | end | |
1517 | ||
1518 | function makeCharcoal(anumber) -- makes specified number of charcoal in multiples of 8 | |
1519 | if fuelOn == true then | |
1520 | if useFurnace == true then | |
1521 | if furnaceCheck() == true then | |
1522 | quickcheck = turtle.getItemSpace(fuelSlot1) + turtle.getItemSpace(fuelSlot2) -- adds empty space in both slots | |
1523 | if quickcheck > 8 * charcoalNumber then -- if there is enough room for more fuel then make some charcoal | |
1524 | term.setCursorPos (1, 4) | |
1525 | clearLine() | |
1526 | term.setCursorPos (1, 3) | |
1527 | clearLine() | |
1528 | term.setCursorPos (1, 2) | |
1529 | clearLine() | |
1530 | write ("| I'm making Charcoal") | |
1531 | hadfuel = "false" | |
1532 | if poweredFurnace == false then | |
1533 | if turtle.getItemCount(fuelSlot1) > 1 + anumber then -- checks for fuel and logs, puts fuel in furnace | |
1534 | if turtle.getItemCount(logSlot) > 8 * anumber then | |
1535 | turtle.select(fuelSlot1) | |
1536 | turtle.suckUp() | |
1537 | turtle.dropUp(1 * anumber) | |
1538 | turtle.suckDown() -- incase of overflow | |
1539 | hadfuel = "true" | |
1540 | end | |
1541 | elseif turtle.getItemCount(fuelSlot2) > 1 + anumber then -- not enough in fuelSlot1, then try fuelSlot2 | |
1542 | if turtle.getItemCount(logSlot) > 8 * anumber then | |
1543 | turtle.select(fuelSlot2) | |
1544 | turtle.suckUp() | |
1545 | turtle.dropUp(1 * anumber) | |
1546 | turtle.suckDown() -- incase of overflow | |
1547 | hadfuel = "true" | |
1548 | end | |
1549 | end | |
1550 | end | |
1551 | if poweredFurnace == true then -- assume the furnace has fuel and don't put any in | |
1552 | hadfuel = "true" | |
1553 | end | |
1554 | forward(1) | |
1555 | up(2) | |
1556 | turn("back") | |
1557 | forward(1) | |
1558 | if turtle.getItemCount(logSlot) > 8 * anumber and hadfuel == "true" then -- if there are enough logs and the furnace has been fueled, put in some logs | |
1559 | turtle.select(logSlot) | |
1560 | turtle.dropDown(8 * anumber) | |
1561 | charcoalMade = charcoalMade + (8 * anumber) | |
1562 | term.setCursorPos (5, 7) | |
1563 | write ("Charcoal: "..charcoalMade) | |
1564 | end | |
1565 | turn("back") -- go back home, grabbing fuel along the way | |
1566 | forward(1) | |
1567 | down(1) | |
1568 | turn("back") | |
1569 | turtle.select(fuelSlot1) | |
1570 | turtle.suck() | |
1571 | turtle.select(fuelSlot2) | |
1572 | turtle.suck() | |
1573 | down(1) | |
1574 | forward(1) | |
1575 | turn("back") | |
1576 | else | |
1577 | return | |
1578 | end | |
1579 | end | |
1580 | end | |
1581 | end | |
1582 | end | |
1583 | ||
1584 | -- SECTION: Docking and Undocking ----------------------------------------------------------------- | |
1585 | ||
1586 | function undock() -- moves from docking station to first tree | |
1587 | if running == false then return end | |
1588 | parallel.waitForAny(dirt, wakeUp) | |
1589 | if gotosettings == true then -- goes to settings first if another function wanted it to happen | |
1590 | settings() | |
1591 | end | |
1592 | if imdone == false then -- if settings wasn't done and somehow got back here, return to the beginning of undocking | |
1593 | undock() | |
1594 | return | |
1595 | end | |
1596 | refillSaplings() -- don't leave without saplings | |
1597 | parallel.waitForAny(saplings, wakeUp) | |
1598 | if gotosettings == true then | |
1599 | settings() | |
1600 | end | |
1601 | if imdone == false then | |
1602 | undock() | |
1603 | return | |
1604 | end | |
1605 | parallel.waitForAny(fuel, wakeUp) -- don't leave without fuel | |
1606 | if gotosettings == true then | |
1607 | settings() | |
1608 | end | |
1609 | if imdone == false then | |
1610 | undock() | |
1611 | return | |
1612 | end | |
1613 | parallel.waitForAny(someFuel, wakeUp) -- make sure you have enough too! | |
1614 | if gotosettings == true then | |
1615 | settings() | |
1616 | end | |
1617 | if imdone == false then | |
1618 | undock() | |
1619 | return | |
1620 | end | |
1621 | dropOff() -- drop off all extra inventory items | |
1622 | if dumpStuff == false then -- check that there is inventry room for another run | |
1623 | emptySpace = 0 | |
1624 | for cnt=1, 16 do | |
1625 | if cnt ~= logSlot then | |
1626 | if cnt ~= fuelSlot1 then | |
1627 | if cnt ~= fuelSlot2 then | |
1628 | if cnt ~= saplingSlot1 then | |
1629 | if cnt ~= saplingSlot2 then | |
1630 | if cnt ~= dirtSlot then | |
1631 | turtle.select(cnt) | |
1632 | emptySpace = emptySpace + turtle.getItemSpace(cnt) | |
1633 | end | |
1634 | end | |
1635 | end | |
1636 | end | |
1637 | end | |
1638 | end | |
1639 | end | |
1640 | end | |
1641 | dropFail() -- if there was not enough inventory the program will quit, happens if the output chest is full | |
1642 | if running == false then return end -- something quit the program, cancel everything! | |
1643 | term.setCursorPos (1, 4) | |
1644 | clearLine() | |
1645 | term.setCursorPos (1, 3) | |
1646 | clearLine() | |
1647 | term.setCursorPos (1, 2) | |
1648 | clearLine() | |
1649 | sleep(1) | |
1650 | write ("| Let's get going!") -- start getting into position | |
1651 | turtle.select(saplingSlot2) | |
1652 | forward(wallGap) | |
1653 | up(1) | |
1654 | if rowOffset > 0 then -- move first row to the left | |
1655 | turn ("left") | |
1656 | forward (rowOffset) | |
1657 | turn ("right") | |
1658 | end | |
1659 | if rowOffset < 0 then -- or move first row to the right | |
1660 | adjOffset = rowOffset - (rowOffset + rowOffset) | |
1661 | turn ("right") | |
1662 | forward (adjOffset) | |
1663 | turn ("left") | |
1664 | end | |
1665 | turtle.select(logSlot) | |
1666 | end | |
1667 | ||
1668 | function redock() -- logging is done so lets get back home | |
1669 | fuel() | |
1670 | term.setCursorPos (1, 4) | |
1671 | clearLine() | |
1672 | term.setCursorPos (1, 3) | |
1673 | clearLine() | |
1674 | term.setCursorPos (1, 2) | |
1675 | clearLine() | |
1676 | write ("| Going Home") | |
1677 | if wide % 2 == 1 then -- check to see if we are far from home or close by | |
1678 | turn ("right") | |
1679 | forward (1) | |
1680 | turn ("right") | |
1681 | forward ((long - 1) * (saplingGap + 1) + 1) | |
1682 | turn ("right") | |
1683 | forward (1 ) | |
1684 | else | |
1685 | forward (1) | |
1686 | turn ("right") | |
1687 | end | |
1688 | if ((wide - 1) * (saplingGap + 1)) >= rowOffset then -- if we are far away, move closer | |
1689 | forward ((wide - 1) * (saplingGap + 1) - rowOffset) | |
1690 | down(1) | |
1691 | turn("left") | |
1692 | else -- move to being in front of home | |
1693 | turn("back") | |
1694 | forward(rowOffset) | |
1695 | down(1) | |
1696 | turn("right") | |
1697 | end -- move the wallGap distance to home | |
1698 | forward(wallGap) | |
1699 | turn("back") | |
1700 | fuel() | |
1701 | end | |
1702 | ||
1703 | -- SECTION: Drop off stuff ------------------------------------------------------------------------ | |
1704 | ||
1705 | function dropOff() -- put stuff in the output chest | |
1706 | if dumpStuff == true then | |
1707 | term.setCursorPos (1, 4) | |
1708 | clearLine() | |
1709 | term.setCursorPos (1, 3) | |
1710 | clearLine() | |
1711 | term.setCursorPos (1, 2) | |
1712 | clearLine() | |
1713 | write ("| Dropping Off Inventory") | |
1714 | turn("right") | |
1715 | emptySpace = 0 | |
1716 | for cnt=1, 16 do -- check all slots except the designated resource slots for stuff we want to keep | |
1717 | if cnt ~= logSlot then | |
1718 | if cnt ~= fuelSlot1 then | |
1719 | if cnt ~= fuelSlot2 then | |
1720 | if cnt ~= saplingSlot1 then | |
1721 | if cnt ~= saplingSlot2 then | |
1722 | if cnt ~= dirtSlot then | |
1723 | emptySpace = emptySpace + turtle.getItemSpace(cnt) | |
1724 | if turtle.getItemCount(cnt) > 0 then | |
1725 | turtle.select(cnt) | |
1726 | turtle.drop() | |
1727 | end | |
1728 | end | |
1729 | end | |
1730 | end | |
1731 | end | |
1732 | end | |
1733 | end | |
1734 | end | |
1735 | turn("left") | |
1736 | end | |
1737 | end | |
1738 | ||
1739 | function dropFail() -- if inventory is full quit program | |
1740 | if emptySpace < 64 then | |
1741 | term.setCursorPos (1, 4) | |
1742 | clearLine() | |
1743 | term.setCursorPos (1, 3) | |
1744 | clearLine() | |
1745 | term.setCursorPos (1, 2) | |
1746 | clearLine() | |
1747 | write ("| Oh Noes! The dropoff chest is full!") | |
1748 | sleep(2) | |
1749 | running = false | |
1750 | term.clear() | |
1751 | term.setCursorPos (1, 2) | |
1752 | write (whatsMyName.." Stopped logging") | |
1753 | write ("\nbecause the output chest is Full.") | |
1754 | write ("\nPlease make room in the chest") | |
1755 | write ("\nand restart the program") | |
1756 | term.setCursorPos (1, 6) | |
1757 | return | |
1758 | end | |
1759 | end | |
1760 | ||
1761 | -- SECTION: Farming Functions --------------------------------------------------------------------- | |
1762 | ||
1763 | function checkPlant() -- ensure there is a sapling and dirt where a tree is to be grown | |
1764 | term.setCursorPos (1, 4) | |
1765 | clearLine() | |
1766 | term.setCursorPos (1, 3) | |
1767 | clearLine() | |
1768 | term.setCursorPos (1, 2) | |
1769 | clearLine() | |
1770 | write ("| Checking for Sapling and Dirt") | |
1771 | forward(1) | |
1772 | if treeCheckDown() == true then | |
1773 | turtle.digDown() | |
1774 | end | |
1775 | turtle.select(dirtSlot) | |
1776 | if turtle.compareDown() == true then | |
1777 | turtle.digDown() | |
1778 | end | |
1779 | if turtle.detectDown() == false then | |
1780 | down(1) | |
1781 | if turtle.compareDown() == false then | |
1782 | turtle.digDown() | |
1783 | turtle.placeDown() | |
1784 | end | |
1785 | up(1) | |
1786 | turtle.select(saplingSlot1) | |
1787 | if turtle.getItemCount(saplingSlot1) > 1 then | |
1788 | turtle.placeDown() | |
1789 | saplingsPlanted = saplingsPlanted + 1 | |
1790 | term.setCursorPos (5, 8) | |
1791 | write ("Saplings: "..saplingsPlanted) | |
1792 | elseif turtle.getItemCount(saplingSlot2) > 1 then | |
1793 | if turtle.compareTo(saplingSlot1) then | |
1794 | turtle.select(saplingSlot2) | |
1795 | turtle.placeDown() | |
1796 | saplingsPlanted = saplingsPlanted + 1 | |
1797 | term.setCursorPos (5, 8) | |
1798 | write ("Saplings: "..saplingsPlanted) | |
1799 | end | |
1800 | end | |
1801 | end | |
1802 | turtle.select(logSlot) | |
1803 | checkup = treeCheckUp() | |
1804 | if checkup == true then | |
1805 | term.setCursorPos (1, 2) | |
1806 | clearLine() | |
1807 | write ("| Chopping Tree") | |
1808 | height = 0 | |
1809 | while turtle.compareUp() do | |
1810 | turtle.digUp () | |
1811 | up (1) | |
1812 | height = height + 1 | |
1813 | end | |
1814 | down(height) | |
1815 | treeTotal = treeTotal +1 | |
1816 | term.setCursorPos (3, 6) | |
1817 | write ("Tree Total: "..treeTotal) | |
1818 | end | |
1819 | end | |
1820 | ||
1821 | function treeCheckUp() -- return true if turtle faces a tree | |
1822 | logCount = turtle.getItemCount(logSlot) | |
1823 | if logCount > 0 then | |
1824 | turtle.select(logSlot) | |
1825 | ret = turtle.compareUp() | |
1826 | return ret | |
1827 | else | |
1828 | return false | |
1829 | end | |
1830 | end | |
1831 | ||
1832 | -- function treeCheck() -- return true if turtle faces a tree (NOT IN USE) | |
1833 | -- logCount = turtle.getItemCount(logSlot) | |
1834 | -- if logCount > 0 then | |
1835 | -- turtle.select(logSlot) | |
1836 | -- ret = turtle.compare() | |
1837 | -- return ret | |
1838 | -- else | |
1839 | -- return true | |
1840 | -- end | |
1841 | -- end | |
1842 | ||
1843 | function treeCheckDown() -- return true if turtle faces a tree | |
1844 | logCount = turtle.getItemCount(logSlot) | |
1845 | if logCount > 0 then | |
1846 | turtle.select(logSlot) | |
1847 | ret = turtle.compareDown() | |
1848 | return ret | |
1849 | else | |
1850 | return false | |
1851 | end | |
1852 | end | |
1853 | ||
1854 | -- function fellTree() -- cut down a tree | |
1855 | -- term.setCursorPos (1, 4) | |
1856 | -- clearLine() | |
1857 | -- term.setCursorPos (1, 3) | |
1858 | -- clearLine() | |
1859 | -- term.setCursorPos (1, 2) | |
1860 | -- clearLine() | |
1861 | -- write ("| Chopping Tree") | |
1862 | -- turtle.select(logSlot) | |
1863 | -- turtle.dig() | |
1864 | -- forward(1) | |
1865 | -- turtle.digDown () | |
1866 | -- down(1) | |
1867 | -- turtle.select(dirtSlot) | |
1868 | -- if not turtle.compareDown() then | |
1869 | -- turtle.digDown() | |
1870 | -- turtle.placeDown() | |
1871 | -- end | |
1872 | -- up (1) | |
1873 | -- turtle.select(saplingSlot1) | |
1874 | -- if turtle.getItemCount(saplingSlot1) > 1 then | |
1875 | -- turtle.placeDown() | |
1876 | -- saplingsPlanted = saplingsPlanted + 1 | |
1877 | -- term.setCursorPos (5, 8) | |
1878 | -- write ("Saplings: "..saplingsPlanted) | |
1879 | -- elseif turtle.getItemCount(saplingSlot2) > 1 then | |
1880 | -- if turtle.compareTo(saplingSlot1) then | |
1881 | -- turtle.select(saplingSlot2) | |
1882 | -- turtle.placeDown() | |
1883 | -- saplingsPlanted = saplingsPlanted + 1 | |
1884 | -- term.setCursorPos (5, 8) | |
1885 | -- write ("Saplings: "..saplingsPlanted) | |
1886 | -- end | |
1887 | -- end | |
1888 | -- turtle.select(logSlot) | |
1889 | -- height = 0 | |
1890 | -- while turtle.compareUp() do | |
1891 | -- turtle.digUp () | |
1892 | -- up (1) | |
1893 | -- height = height + 1 | |
1894 | -- end | |
1895 | -- down(height) | |
1896 | -- treeTotal = treeTotal +1 | |
1897 | -- term.setCursorPos (3, 6) | |
1898 | -- write ("Tree Total: "..treeTotal) | |
1899 | -- end | |
1900 | ||
1901 | function logging() -- MAIN FARMING FUNCTION, calls checkPlant(), treeCheck(), fellTree(), and moves tree to tree | |
1902 | undock() | |
1903 | if running == false then return end | |
1904 | turnleftnow = 0 | |
1905 | for countWide=1, wide do | |
1906 | for countLong=1, long do -- loop for each tree | |
1907 | fuel() | |
1908 | turtle.select(logSlot) | |
1909 | -- treeTest = treeCheck() | |
1910 | -- if treeTest == true then | |
1911 | -- fellTree() | |
1912 | -- else | |
1913 | checkPlant() | |
1914 | -- end | |
1915 | if countLong ~= long then | |
1916 | turtle.select(saplingSlot1) | |
1917 | forward(saplingGap) | |
1918 | term.setCursorPos (1, 4) | |
1919 | clearLine() | |
1920 | term.setCursorPos (1, 3) | |
1921 | clearLine() | |
1922 | term.setCursorPos (1, 2) | |
1923 | clearLine() | |
1924 | write ("| Moving to next tree") | |
1925 | end | |
1926 | end | |
1927 | term.setCursorPos (1, 4) | |
1928 | clearLine() | |
1929 | term.setCursorPos (1, 3) | |
1930 | clearLine() | |
1931 | term.setCursorPos (1, 2) | |
1932 | clearLine() | |
1933 | write ("| Moving to next row") | |
1934 | if countWide < wide then -- loop for moving to next row of trees | |
1935 | forward(1) | |
1936 | if turnleftnow == 1 then | |
1937 | turn("left") | |
1938 | forward(saplingGap + 1) | |
1939 | turn("left") | |
1940 | turnleftnow = 0 | |
1941 | else | |
1942 | turn("right") | |
1943 | forward(saplingGap + 1) | |
1944 | turn("right") | |
1945 | turnleftnow = 1 | |
1946 | end | |
1947 | end | |
1948 | end | |
1949 | redock() | |
1950 | end | |
1951 | ||
1952 | -- SECTION: Sleeping between logging runs --------------------------------------------------------- | |
1953 | ||
1954 | goodNight = function() -- Waiting between runs | |
1955 | imdone = false | |
1956 | term.setCursorPos (1, 4) | |
1957 | clearLine() | |
1958 | term.setCursorPos (1, 2) | |
1959 | clearLine() | |
1960 | term.setCursorPos (1, 3) | |
1961 | clearLine() | |
1962 | write ("| Press any key to change settings.") | |
1963 | if sleepTime > 0 then | |
1964 | while resetsleep < sleepTime do | |
1965 | if running == false then break end | |
1966 | term.setCursorPos (1, 2) | |
1967 | write ("| Sleeping for "..sleepTime-resetsleep.." seconds...") | |
1968 | sleep(1) | |
1969 | resetsleep = resetsleep + 1 | |
1970 | end | |
1971 | end | |
1972 | term.setCursorPos (1, 3) | |
1973 | clearLine() | |
1974 | term.setCursorPos (1, 2) | |
1975 | clearLine() | |
1976 | resetsleep = 1 | |
1977 | imdone = true | |
1978 | end | |
1979 | ||
1980 | wakeUp = function() -- inturrption by keyboard input, goes to settings menu | |
1981 | sleep(1) | |
1982 | os.pullEvent("char") | |
1983 | gotosettings = true | |
1984 | end | |
1985 | ||
1986 | function nowISleep() -- sets up for sleeping and inturrupting the sleep for the settings menu | |
1987 | parallel.waitForAny(goodNight, wakeUp) | |
1988 | if running == false then term.clear() return end | |
1989 | if gotosettings == true then | |
1990 | sleep(0.4) | |
1991 | settings() | |
1992 | end | |
1993 | if imdone == false then | |
1994 | nowISleep() | |
1995 | end | |
1996 | end | |
1997 | ||
1998 | -- SECTION: Misc. --------------------------------------------------------------------------------- | |
1999 | ||
2000 | function fuelSettingCheck() -- checks to see if the server has fuel use disabled | |
2001 | if turtle.getFuelLevel() ~= "unlimited" then | |
2002 | fuelOn = true | |
2003 | else | |
2004 | fuelOn = false | |
2005 | end | |
2006 | end | |
2007 | ||
2008 | function breakTest() -- if the turtle coulden't find its way home it will need broken before restarting itself | |
2009 | if turtle.getItemCount(logSlot) == 0 then | |
2010 | needsBroken = false | |
2011 | saveSettings() | |
2012 | end | |
2013 | if needsBroken == true then | |
2014 | term.clear() | |
2015 | term.setCursorPos (1, 1) | |
2016 | print ("Logger may not have made it home so the program was closed. Break the turtle and replace it to continue.") | |
2017 | running = false | |
2018 | end | |
2019 | end | |
2020 | ||
2021 | -------------------- PROGRAM START ---------------------------------------------------------------- | |
2022 | ||
2023 | -- Make sure files exist | |
2024 | while not fs.exists ("logger.cfg") do | |
2025 | os.setComputerLabel(whatsMyName) | |
2026 | startup() | |
2027 | saveSettings() | |
2028 | saveCords() | |
2029 | end | |
2030 | ||
2031 | while not fs.exists ("loggercords.dat") do | |
2032 | saveCords() | |
2033 | end | |
2034 | ||
2035 | -- Load settings and start initial graphical setup | |
2036 | term.clear() | |
2037 | gotosettings = false | |
2038 | imdone = true | |
2039 | loadSettings() | |
2040 | graphics() -- renders the GUI | |
2041 | fuelSettingCheck() -- checks for unlimeted fuel setting | |
2042 | running = true | |
2043 | ||
2044 | -- Checks cordinates and goes back to starting position if out in the field | |
2045 | loadCords() | |
2046 | if homeCheck() == false then | |
2047 | goHome() | |
2048 | end | |
2049 | breakTest() | |
2050 | ||
2051 | -- Start main loop | |
2052 | while running == true do | |
2053 | logging() | |
2054 | if running == false then break end | |
2055 | firstRun = false | |
2056 | makeCharcoal(charcoalNumber) | |
2057 | saveSettings() | |
2058 | resetsleep = 1 | |
2059 | nowISleep() | |
2060 | if running == false then break end | |
2061 | end |