SHOW:
|
|
- or go back to the newest paste.
1 | --Direction: 0=up 1=right 2=down 3=left | |
2 | - | |
2 | + | |
3 | tX = 0 | |
4 | tY = 0 | |
5 | tDirection = 0 | |
6 | - | |
6 | + | |
7 | backX = 0 | |
8 | backY = 0 | |
9 | backDirection = 0 | |
10 | - | |
10 | + | |
11 | waiting = 12 | |
12 | i = 0 | |
13 | imax = 9 | |
14 | j = 0 | |
15 | jmax = 9 | |
16 | direction = 0 | |
17 | SelectedSlot = 13 | |
18 | imax = imax - 1 | |
19 | - | |
19 | + | |
20 | local function tTurnLeft() | |
21 | - | if tDirection ~= 0 then |
21 | + | if tDirection ~= 0 then |
22 | - | tDirection = tDirection - 1 |
22 | + | tDirection = tDirection - 1 |
23 | - | else |
23 | + | else |
24 | - | tDirection = 3 |
24 | + | tDirection = 3 |
25 | - | end |
25 | + | end |
26 | - | turtle.turnLeft() |
26 | + | turtle.turnLeft() |
27 | end | |
28 | - | |
28 | + | |
29 | local function tTurnRight() | |
30 | - | if tDirection ~= 3 then |
30 | + | if tDirection ~= 3 then |
31 | - | tDirection = tDirection + 1 |
31 | + | tDirection = tDirection + 1 |
32 | - | else |
32 | + | else |
33 | - | tDirection = 0 |
33 | + | tDirection = 0 |
34 | - | end |
34 | + | end |
35 | - | turtle.turnRight() |
35 | + | turtle.turnRight() |
36 | end | |
37 | - | |
37 | + | |
38 | local function tForward() | |
39 | - | while turtle.forward() == false do |
39 | + | while turtle.forward() == false do |
40 | - | turtle.forward() |
40 | + | turtle.forward() |
41 | - | end |
41 | + | end |
42 | - | |
42 | + | |
43 | - | if tDirection == 0 then |
43 | + | if tDirection == 0 then |
44 | - | tY = tY + 1 |
44 | + | tY = tY + 1 |
45 | - | elseif tDirection == 1 then |
45 | + | elseif tDirection == 1 then |
46 | - | tX = tX + 1 |
46 | + | tX = tX + 1 |
47 | - | elseif tDirection == 2 then |
47 | + | elseif tDirection == 2 then |
48 | - | tY = tY - 1 |
48 | + | tY = tY - 1 |
49 | - | elseif tDirection == 3 then |
49 | + | elseif tDirection == 3 then |
50 | - | tX = tX - 1 |
50 | + | tX = tX - 1 |
51 | - | end |
51 | + | end |
52 | end | |
53 | - | |
53 | + | |
54 | local function goToStartPos() | |
55 | - | print("Back to home.") |
55 | + | print("Back to home.") |
56 | - | backX = tX |
56 | + | backX = tX |
57 | - | backY = tY |
57 | + | backY = tY |
58 | - | backDirection = tDirection |
58 | + | backDirection = tDirection |
59 | - | |
59 | + | |
60 | - | if tDirection == 0 then |
60 | + | if tDirection == 0 then |
61 | - | tTurnLeft() |
61 | + | tTurnLeft() |
62 | - | tTurnLeft() |
62 | + | tTurnLeft() |
63 | - | elseif tDirection == 1 then |
63 | + | elseif tDirection == 1 then |
64 | - | tTurnRight() |
64 | + | tTurnRight() |
65 | - | elseif tDirection == 3 then |
65 | + | elseif tDirection == 3 then |
66 | - | tTurnLeft() |
66 | + | tTurnLeft() |
67 | - | end |
67 | + | end |
68 | - | |
68 | + | |
69 | - | while tY ~= 0 do |
69 | + | while tY ~= 0 do |
70 | - | tForward() |
70 | + | tForward() |
71 | - | end |
71 | + | end |
72 | - | |
72 | + | |
73 | - | tTurnLeft() |
73 | + | tTurnLeft() |
74 | - | |
74 | + | |
75 | - | while tX ~= 0 do |
75 | + | while tX ~= 0 do |
76 | - | tForward() |
76 | + | tForward() |
77 | - | end |
77 | + | end |
78 | - | |
78 | + | |
79 | - | tTurnRight() |
79 | + | tTurnRight() |
80 | end | |
81 | - | |
81 | + | |
82 | local function goToOldPos() | |
83 | - | print("Back to work.") |
83 | + | print("Back to work.") |
84 | - | if tDirection == 1 then |
84 | + | if tDirection == 1 then |
85 | - | tTurnLeft() |
85 | + | tTurnLeft() |
86 | - | elseif tDirection == 2 then |
86 | + | elseif tDirection == 2 then |
87 | - | tTurnLeft() |
87 | + | tTurnLeft() |
88 | - | tTurnLeft() |
88 | + | tTurnLeft() |
89 | - | elseif tDirection == 3 then |
89 | + | elseif tDirection == 3 then |
90 | - | tTurnRight() |
90 | + | tTurnRight() |
91 | - | end |
91 | + | end |
92 | - | |
92 | + | |
93 | - | while tY ~= backY do |
93 | + | while tY ~= backY do |
94 | - | tForward() |
94 | + | tForward() |
95 | - | end |
95 | + | end |
96 | - | |
96 | + | |
97 | - | tTurnLeft() |
97 | + | tTurnLeft() |
98 | - | |
98 | + | |
99 | - | while tX ~= backX do |
99 | + | while tX ~= backX do |
100 | - | tForward() |
100 | + | tForward() |
101 | - | end |
101 | + | end |
102 | - | |
102 | + | |
103 | - | if tDirection ~= backDirection then |
103 | + | if tDirection ~= backDirection then |
104 | - | while tDirection ~= backDirection do |
104 | + | while tDirection ~= backDirection do |
105 | - | tTurnLeft() |
105 | + | tTurnLeft() |
106 | - | end |
106 | + | end |
107 | - | end |
107 | + | end |
108 | end | |
109 | - | |
109 | + | |
110 | local function dropWheat() | |
111 | - | for slotI = 1, 12 do |
111 | + | for slotI = 1, 12 do |
112 | - | turtle.select(slotI) |
112 | + | turtle.select(slotI) |
113 | - | if turtle.drop() == false and turtle.getItemCount(slotI) ~= 0 then |
113 | + | if turtle.drop() == false and turtle.getItemCount(slotI) ~= 0 then |
114 | - | print("Chest is full!") |
114 | + | print("Chest is full!") |
115 | - | while turtle.drop() == false do |
115 | + | while turtle.drop() == false and turtle.getItemCount(slotI) ~= 0 do |
116 | - | turtle.drop() |
116 | + | turtle.drop() |
117 | - | end |
117 | + | end |
118 | - | end |
118 | + | end |
119 | - | end |
119 | + | end |
120 | end | |
121 | - | |
121 | + | |
122 | local function turnAround() | |
123 | - | turtle.turnLeft() |
123 | + | turtle.turnLeft() |
124 | - | turtle.turnLeft() |
124 | + | turtle.turnLeft() |
125 | end | |
126 | - | |
126 | + | |
127 | local function isFilled() | |
128 | - | count = 0 |
128 | + | count = 0 |
129 | - | slot = 1 |
129 | + | slot = 1 |
130 | - | |
130 | + | |
131 | - | while slot < 13 do |
131 | + | while slot < 13 do |
132 | - | count = count + turtle.getItemSpace(slot) |
132 | + | count = count + turtle.getItemSpace(slot) |
133 | - | slot = slot + 1 |
133 | + | slot = slot + 1 |
134 | - | end |
134 | + | end |
135 | - | |
135 | + | |
136 | - | --print("Count: " .. count) |
136 | + | --print("Count: " .. count) |
137 | - | |
137 | + | |
138 | - | if count ~= 0 then |
138 | + | if count ~= 0 then |
139 | - | return false |
139 | + | return false |
140 | - | else |
140 | + | else |
141 | - | return true |
141 | + | return true |
142 | - | end |
142 | + | end |
143 | end | |
144 | - | |
144 | + | |
145 | local function isLast() | |
146 | - | if turtle.getItemCount(13) == 1 then |
146 | + | if turtle.getItemCount(13) == 1 then |
147 | - | return true |
147 | + | return true |
148 | - | else |
148 | + | else |
149 | - | return false |
149 | + | return false |
150 | - | end |
150 | + | end |
151 | end | |
152 | - | |
152 | + | |
153 | local function fillSeeds() | |
154 | - | if isLast() then |
154 | + | if isLast() then |
155 | - | turtle.select(13) |
155 | + | turtle.select(13) |
156 | - | for slot = 1, 12 do |
156 | + | for slot = 1, 12 do |
157 | - | if turtle.compareTo(slot) then |
157 | + | if turtle.compareTo(slot) then |
158 | - | turtle.select(slot) |
158 | + | turtle.select(slot) |
159 | - | turtle.transferTo(13) |
159 | + | turtle.transferTo(13) |
160 | - | turtle.select(13) |
160 | + | turtle.select(13) |
161 | - | end |
161 | + | end |
162 | - | |
162 | + | |
163 | - | if turtle.getItemSpace(13) == 0 then |
163 | + | if turtle.getItemSpace(13) == 0 then |
164 | - | break |
164 | + | break |
165 | - | end |
165 | + | end |
166 | - | end |
166 | + | end |
167 | - | |
167 | + | |
168 | - | if isLast() then |
168 | + | if isLast() then |
169 | - | goToStartPos() |
169 | + | goToStartPos() |
170 | - | turtle.select(13) |
170 | + | turtle.select(13) |
171 | - | |
171 | + | |
172 | - | if turtle.suck() == false then |
172 | + | if turtle.suck() == false then |
173 | - | print("Put seeds in chest!!!") |
173 | + | print("Put seeds in chest!!!") |
174 | - | while isLast() do |
174 | + | while isLast() do |
175 | - | turtle.suck() |
175 | + | turtle.suck() |
176 | - | end |
176 | + | end |
177 | - | end |
177 | + | end |
178 | - | goToOldPos() |
178 | + | goToOldPos() |
179 | - | end |
179 | + | end |
180 | - | end |
180 | + | end |
181 | end | |
182 | - | |
182 | + | |
183 | local function unloading() | |
184 | - | if isFilled() == true then |
184 | + | if isFilled() == true then |
185 | - | print("Unloading...") |
185 | + | print("Unloading...") |
186 | - | goToStartPos() |
186 | + | goToStartPos() |
187 | - | dropWheat() |
187 | + | dropWheat() |
188 | - | goToOldPos() |
188 | + | goToOldPos() |
189 | - | end |
189 | + | end |
190 | end | |
191 | - | |
191 | + | |
192 | local function plow() | |
193 | - | if turtle.detectDown() == false and turtle.digDown() == true then |
193 | + | if turtle.detectDown() == true and turtle.digDown() == true then |
194 | - | turtle.digDown() |
194 | + | turtle.digDown() |
195 | - | end |
195 | + | end |
196 | end | |
197 | - | |
197 | + | |
198 | while true do | |
199 | - | SelectedSlot = 13 |
199 | + | SelectedSlot = 13 |
200 | - | turtle.select(SelectedSlot) |
200 | + | turtle.select(SelectedSlot) |
201 | - | |
201 | + | |
202 | - | while j < jmax do |
202 | + | while j < jmax do |
203 | - | while i < imax do |
203 | + | while i < imax do |
204 | - | turtle.select(1) |
204 | + | turtle.select(1) |
205 | - | unloading() |
205 | + | unloading() |
206 | - | plow() |
206 | + | plow() |
207 | - | turtle.select(SelectedSlot) |
207 | + | turtle.select(SelectedSlot) |
208 | - | fillSeeds() |
208 | + | fillSeeds() |
209 | - | turtle.placeDown() |
209 | + | turtle.placeDown() |
210 | - | tForward() |
210 | + | tForward() |
211 | - | |
211 | + | |
212 | - | i = i + 1 |
212 | + | i = i + 1 |
213 | - | end |
213 | + | end |
214 | - | |
214 | + | |
215 | - | unloading() |
215 | + | unloading() |
216 | - | plow() |
216 | + | plow() |
217 | - | fillSeeds() |
217 | + | fillSeeds() |
218 | - | turtle.placeDown() |
218 | + | turtle.placeDown() |
219 | - | |
219 | + | |
220 | - | if imax ~= 0 then |
220 | + | if j + 1 ~= jmax then |
221 | - | if direction == 0 then |
221 | + | if direction == 0 then |
222 | - | tTurnLeft() |
222 | + | tTurnLeft() |
223 | - | tForward() |
223 | + | tForward() |
224 | - | tTurnLeft() |
224 | + | tTurnLeft() |
225 | - | direction = 1 |
225 | + | direction = 1 |
226 | - | else |
226 | + | else |
227 | - | tTurnRight() |
227 | + | tTurnRight() |
228 | - | tForward() |
228 | + | tForward() |
229 | - | tTurnRight() |
229 | + | tTurnRight() |
230 | - | direction = 0 |
230 | + | direction = 0 |
231 | - | end |
231 | + | end |
232 | - | end |
232 | + | end |
233 | - | |
233 | + | |
234 | - | turtle.select(1) |
234 | + | turtle.select(1) |
235 | - | unloading() |
235 | + | unloading() |
236 | - | plow() |
236 | + | plow() |
237 | - | turtle.select(SelectedSlot) |
237 | + | turtle.select(SelectedSlot) |
238 | - | fillSeeds() |
238 | + | fillSeeds() |
239 | - | turtle.placeDown() |
239 | + | turtle.placeDown() |
240 | - | |
240 | + | |
241 | - | j = j + 1 |
241 | + | j = j + 1 |
242 | - | i = 0 |
242 | + | i = 0 |
243 | - | end |
243 | + | end |
244 | - | |
244 | + | |
245 | - | i = 0 |
245 | + | i = 0 |
246 | - | j = 0 |
246 | + | j = 0 |
247 | - | |
247 | + | |
248 | - | goToStartPos() |
248 | + | goToStartPos() |
249 | - | dropWheat() |
249 | + | dropWheat() |
250 | - | turnAround() |
250 | + | turnAround() |
251 | - | for wait = 1, waiting do |
251 | + | for wait = 1, waiting do |
252 | - | sleep(60) |
252 | + | sleep(60) |
253 | - | print("Remaining " .. (waiting - wait) .. " minutes.") |
253 | + | print("Remaining " .. (waiting - wait) .. " minutes.") |
254 | - | end |
254 | + | end |
255 | end |