SHOW:
|
|
- or go back to the newest paste.
1 | local function up(x) | |
2 | repeat | |
3 | x=x-1 | |
4 | while not turtle.up() do | |
5 | print("Failed to move UP") | |
6 | sleep(0.2) | |
7 | end | |
8 | until x==0 | |
9 | end | |
10 | ||
11 | local function down(x) | |
12 | repeat | |
13 | x=x-1 | |
14 | while not turtle.down() do | |
15 | print("Failed to move DOWN") | |
16 | sleep(0.2) | |
17 | end | |
18 | until x==0 | |
19 | end | |
20 | ||
21 | local function forward(x) | |
22 | repeat | |
23 | x=x-1 | |
24 | while not turtle.forward() do | |
25 | print("Failed to move FORWARD") | |
26 | sleep(0.2) | |
27 | end | |
28 | until x==0 | |
29 | end | |
30 | ||
31 | local function back(x) | |
32 | repeat | |
33 | x=x-1 | |
34 | while not turtle.back() do | |
35 | print("Failed to move BACK") | |
36 | sleep(0.2) | |
37 | end | |
38 | until x==0 | |
39 | end | |
40 | ||
41 | local function left(x) | |
42 | repeat | |
43 | x=x-1 | |
44 | turtle.turnLeft() | |
45 | until x==0 | |
46 | end | |
47 | ||
48 | local function right(x) | |
49 | repeat | |
50 | x=x-1 | |
51 | turtle.turnRight() | |
52 | until x==0 | |
53 | end | |
54 | ||
55 | local function fuel() | |
56 | if turtle.getFuelLevel() < 1000 then do | |
57 | turtle.select(1) | |
58 | turtle.refuel(10) | |
59 | end | |
60 | end | |
61 | end | |
62 | ||
63 | local function fell() | |
64 | forward(10) | |
65 | right(1) | |
66 | turtle.select(2) | |
67 | while not turtle.compare() do | |
68 | print("Tree not grown yet") | |
69 | sleep(5.0) | |
70 | end | |
71 | turtle.dig() | |
72 | forward(1) | |
73 | while turtle.compare() do | |
74 | turtle.dig() | |
75 | turtle.digUp() | |
76 | up(1) | |
77 | end | |
78 | fuel() | |
79 | left(1) | |
80 | turtle.dig() | |
81 | forward(1) | |
82 | right(1) | |
83 | while turtle.compareDown() do | |
84 | turtle.digDown() | |
85 | down(1) | |
86 | turtle.dig() | |
87 | end | |
88 | fuel() | |
89 | end | |
90 | ||
91 | local function plant() | |
92 | up(1) | |
93 | turtle.select(3) | |
94 | x=2 | |
95 | repeat | |
96 | x=x-1 | |
97 | turtle.placeDown() | |
98 | forward(1) | |
99 | right(1) | |
100 | until x==0 | |
101 | turtle.placeDown() | |
102 | forward(1) | |
103 | turtle.placeDown() | |
104 | forward(1) | |
105 | down(1) | |
106 | left(1) | |
107 | forward(10) | |
108 | left(1) | |
109 | - | turtle.suck(4) |
109 | + | j = turtle.getItemCount() |
110 | turtle.suck(5-j) | |
111 | left(1) | |
112 | fuel() | |
113 | end | |
114 | ||
115 | local function drop() | |
116 | for i=4,16 do | |
117 | turtle.select(i) | |
118 | p = turtle.getItemCount(i) | |
119 | turtle.dropDown(p-1) | |
120 | end | |
121 | end | |
122 | ||
123 | local function suck() | |
124 | turtle.select(1) | |
125 | turtle.suckDown() | |
126 | end | |
127 | ||
128 | local function supply() | |
129 | left(1) | |
130 | up(4) | |
131 | forward(24) | |
132 | left(1) | |
133 | forward(12) | |
134 | down(1) | |
135 | drop() | |
136 | - | forward(6) |
136 | + | |
137 | suck() | |
138 | left(2) | |
139 | up(1) | |
140 | forward(13) | |
141 | - | forward(15) |
141 | + | |
142 | forward(24) | |
143 | down(4) | |
144 | left(1) | |
145 | - | forward(3) |
145 | + | |
146 | - | down(3) |
146 | + | |
147 | ||
148 | local function program() | |
149 | y=1 | |
150 | repeat | |
151 | fell() | |
152 | plant() | |
153 | supply() | |
154 | until y==2 | |
155 | end | |
156 | ||
157 | ||
158 | function stopLoop() | |
159 | repeat | |
160 | local ev, key = os.pullEvent('key') | |
161 | until key == keys.backspace | |
162 | y=2 | |
163 | end | |
164 | ||
165 | parallel.waitForAll(stopLoop, program) |