SHOW:
|
|
- or go back to the newest paste.
1 | - | -- Treefarm by itsmartin |
1 | + | -- chtreefarmtest: slightly modified Treefarm by itsmartin (from pastebin.com/tyykzGqj) |
2 | -- | |
3 | -- Place fuel in slot 14, saplings in slot 15 and 1 dirt in slot 16. | |
4 | -- See http://youtu.be/nJYxL_sg96U for setup | |
5 | ||
6 | function forwardBy(n) | |
7 | for i=1,n do | |
8 | turtle.forward() | |
9 | end | |
10 | end | |
11 | ||
12 | function moveHomeFarm() | |
13 | forwardBy(5) | |
14 | turtle.turnLeft() | |
15 | forwardBy(5) | |
16 | turtle.turnLeft() | |
17 | end | |
18 | ||
19 | ||
20 | function plantSapling() | |
21 | turtle.select(16) | |
22 | turtle.place() | |
23 | turtle.up() | |
24 | turtle.select(15) | |
25 | turtle.place() | |
26 | end | |
27 | ||
28 | function waitForSaplings() | |
29 | turtle.select(15) | |
30 | while turtle.getItemCount(15) < 2 do | |
31 | - | os.sleep(5) |
31 | + | os.sleep(2) |
32 | sleep(2) | |
33 | turtle.suckDown() | |
34 | end | |
35 | end | |
36 | ||
37 | function waitForTree() | |
38 | - | while turtle.compare() do |
38 | + | local treeFoundCount = 0 |
39 | - | os.sleep(10) |
39 | + | |
40 | while treeFoundCount<10 do | |
41 | while treeFoundCount<10 do | |
42 | os.sleep(2) | |
43 | sleep(2) | |
44 | while not turtle.detect() do | |
45 | os.sleep(2) | |
46 | sleep(2) | |
47 | end | |
48 | treeFoundCount = treeFoundCount + 1 | |
49 | end | |
50 | turtle.down() | |
51 | turtle.select(15) | |
52 | - | while turtle.compareUp() do |
52 | + | os.sleep(2) |
53 | sleep(2) | |
54 | if turtle.compare() then | |
55 | treeFoundCount = 0 | |
56 | turtle.up() | |
57 | end | |
58 | end | |
59 | turtle.select(16) | |
60 | turtle.down() | |
61 | turtle.dig() | |
62 | turtle.forward() | |
63 | end | |
64 | ||
65 | function cutTree() | |
66 | turtle.select(1) | |
67 | turtle.digUp() | |
68 | turtle.up() | |
69 | local count = 1 | |
70 | while count<12 and turtle.compareUp() and turtle.detectUp() do | |
71 | turtle.digUp() | |
72 | turtle.up() | |
73 | count = count + 1 | |
74 | end | |
75 | for i=1,count do | |
76 | turtle.down() | |
77 | end | |
78 | end | |
79 | ||
80 | function moveFarmDeposit() | |
81 | turtle.turnRight() | |
82 | forwardBy(4) | |
83 | turtle.turnLeft() | |
84 | forwardBy(4) | |
85 | turtle.select(1) | |
86 | turtle.dropDown() | |
87 | turtle.turnLeft() | |
88 | forwardBy(9) | |
89 | turtle.turnLeft() | |
90 | end | |
91 | ||
92 | while true do | |
93 | ||
94 | if turtle.getFuelLevel() < 50 then | |
95 | turtle.select(14) | |
96 | turtle.refuel() | |
97 | if turtle.getFuelLevel() < 50 then | |
98 | write("Not enough fuel\n") | |
99 | return | |
100 | end | |
101 | end | |
102 | ||
103 | if turtle.getItemCount(16) < 1 then | |
104 | write("Dirt goes in slot 16\n") | |
105 | return | |
106 | end | |
107 | if turtle.getItemCount(15) < 2 then | |
108 | write("Multiple saplings go in slot 15\n") | |
109 | return | |
110 | end | |
111 | ||
112 | waitForSaplings() | |
113 | moveHomeFarm() | |
114 | plantSapling() | |
115 | waitForTree() | |
116 | cutTree() | |
117 | moveFarmDeposit() | |
118 | end |