SHOW:
|
|
- or go back to the newest paste.
1 | - | --[[ Running this script on a turtle with saplings in slot 1, bone-meal in slot 2 and coal in slot 16 and a chest behind the turtle for the wood drop off point will create an automatic tree farm. combining this with a chest to the left of the turtle for sapling replenishment and chest to the right for coal replenishment will ensure a long running automated process.]] |
1 | + | --[[ Running this script on a turtle with saplings in slot 1, bone-meal in slot 2 and coal in slot 16 and a chest behind the turtle for the wood drop off point will create an automatic tree farm. combining this with a chest to the left of the turtle for sapling replenishment and chest to the right for coal replenishment (or bone meal if boneMealRight = true) will ensure a long running automated process. If you put a Glasses Bridge from OpenPeripherals underneath the turtle, it will keep you updated on the turtle's status.]] |
2 | ||
3 | g = peripheral.wrap("bottom") | |
4 | glasses = false | |
5 | logs = 0 | |
6 | boneMealRight = true | |
7 | ||
8 | - | turtle.place() --fertilizes sapling |
8 | + | |
9 | function plant() | |
10 | turtle.select(1) --selects sapling | |
11 | turtle.place() --places sapling | |
12 | turtle.select(2) --selects bone-meal | |
13 | turtle.place() | |
14 | turtle.place() | |
15 | turtle.place() --fertilizes sapling x3 | |
16 | - | turtle.refuel(5) --picks up any saplings that have fallen |
16 | + | |
17 | end | |
18 | - | print( turtle.getFuelLevel() .. " fuel left.") --displays fuel level to user |
18 | + | |
19 | -- This function checks fuel level and refuels | |
20 | function fuel() | |
21 | if turtle.getFuelLevel() < 50 then --checks fuel level and refuels | |
22 | turtle.select(16) | |
23 | turtle.refuel(5) | |
24 | end | |
25 | remaining = turtle.getFuelLevel() | |
26 | print("Fuel remaining: "..remaining) --displays fuel level to user | |
27 | if glasses then | |
28 | fuel.setText("Fuel remaining: "..remaining.." blocks") | |
29 | end | |
30 | end | |
31 | ||
32 | -- This function cuts a column directly above the turtle and then returns to ground level | |
33 | function column() | |
34 | while turtle.detectUp() == true do --cut tree down | |
35 | turtle.digUp() | |
36 | logs = logs + 1 | |
37 | mined.setText("Logs mined: "..logs) | |
38 | turtle.up() | |
39 | turtle.suck() --picks up any saplings that have fallen | |
40 | end | |
41 | while turtle.detectDown() == false do -- return to ground level | |
42 | turtle.down() | |
43 | turtle.suck() --picks up any saplings that have fallen | |
44 | end | |
45 | end | |
46 | ||
47 | -- This function moves from start position, runs column and returns to start position | |
48 | function fell() | |
49 | turtle.dig() --breaks bottom block of tree | |
50 | logs = logs + 1 | |
51 | mined.setText("Logs mined: "..logs) | |
52 | turtle.forward() --move into gap | |
53 | column() --run column function | |
54 | turtle.turnRight() --return to start | |
55 | turtle.turnRight() | |
56 | turtle.forward() | |
57 | end | |
58 | ||
59 | -- This function empties all collected wood into chest, checks sapling and fuel supplies and restocks | |
60 | function empty() | |
61 | for j = 3, 15 do -- empty slots 3 to 15 into chest | |
62 | turtle.select(j) | |
63 | turtle.drop() | |
64 | end | |
65 | turtle.turnLeft() | |
66 | if turtle.getItemCount(16) < 5 then -- replenish fuel stocks | |
67 | if boneMealRight == false then | |
68 | turtle.select(16) | |
69 | else | |
70 | turtle.select(2) | |
71 | end | |
72 | turtle.suck(10) | |
73 | end | |
74 | turtle.turnLeft() | |
75 | if turtle.getItemCount(1) < 5 then --replenish sapling stocks | |
76 | turtle.turnLeft() | |
77 | turtle.select(1) | |
78 | turtle.suck() | |
79 | turtle.turnRight() | |
80 | end | |
81 | end | |
82 | ||
83 | -- This function checks to see if the sapling has been fertilized into a full tree | |
84 | function compare() | |
85 | turtle.select(1) | |
86 | if turtle.compare() == true then | |
87 | return true -- false could indicate that there is no bonemeal or saplings | |
88 | else | |
89 | return false | |
90 | end | |
91 | end | |
92 | ||
93 | -- This block triggers the appropriate functions in the correct order. | |
94 | if g then | |
95 | print("Running Terminal Glasses mode") | |
96 | glasses = true | |
97 | g.clear() | |
98 | fuel = g.addText(1, 1, "Fuel remaining: ", 0xFFFFFF) | |
99 | mined = g.addText(1, 10, "Logs mined: ", 0xFFFFFF) | |
100 | end | |
101 | repeat --start loop | |
102 | fuel() --check fuel | |
103 | plant() --plant and fertilize tree | |
104 | fuel() --check fuel again | |
105 | if compare() == false then --if tree has grown cut down tree | |
106 | fell() | |
107 | else --if tree hasn't grown display error | |
108 | print("error") | |
109 | repeat | |
110 | sleep(1) | |
111 | turtle.select(2) | |
112 | until turtle.getItemCount() > 20 --this will terminate script | |
113 | end | |
114 | empty() --empty harvest and restock fuel and materials | |
115 | until 1 > 2 -- always false creating infinite loop |