SHOW:
|
|
- or go back to the newest paste.
1 | local args = {...} | |
2 | --slot id: | |
3 | --1 = mining well, 2=tesseract wtih shiny dust, 3 pipes | |
4 | print("Dont forget to shiny dust the tesseract to retain their setting upon destroy"); | |
5 | local zz=turtle | |
6 | - | placeAt(0,0,0,1);--well |
6 | + | |
7 | - | turnRight(); |
7 | + | |
8 | - | placeAt(0,0,0,1);--well |
8 | + | |
9 | local currentZ=0 -- depth | |
10 | ||
11 | - | placeAt(0,0,0,1);--well |
11 | + | local isUndroppable={}; |
12 | function setCurrentItemsUndroppable() | |
13 | - | placeAt(1,0,0,2); --pipe |
13 | + | isUndroppable={}; |
14 | - | turnRight(); |
14 | + | for undroppableItems=1,16 do |
15 | - | placeAt(1,0,0,3);--tesseract |
15 | + | local data = turtle.getItemDetail(undroppableItems); |
16 | - | turnRight(); |
16 | + | |
17 | - | placeAt(1,0,0,2);--pipe |
17 | + | isUndroppable[data.name..data.damage]=true; |
18 | - | goToCord(0,0,0); |
18 | + | end |
19 | - | placeUpAt(0,0,0,2);--pipe |
19 | + | |
20 | end | |
21 | ||
22 | local memorizedItemInventory={}; | |
23 | - | goToCord(0,0,0); |
23 | + | function memorizeItemSlot() |
24 | - | turtle.select(1); |
24 | + | memorizedItemInventory={}; |
25 | - | turtle.dig(); -- well |
25 | + | for slotIDMemory=1,16 do |
26 | - | turnRight(); |
26 | + | local data = turtle.getItemDetail(slotIDMemory); |
27 | - | turtle.dig(); -- well |
27 | + | |
28 | memorizedItemInventory[data.name..data.damage]=slotIDMemory; | |
29 | end | |
30 | - | turtle.dig(); --well |
30 | + | |
31 | - | turtle.digUp()--pipe |
31 | + | |
32 | - | turtle.select(1); |
32 | + | |
33 | - | goToCord(1,0,0); |
33 | + | function sortInventoryByMemory() |
34 | - | turtle.dig();--pipe |
34 | + | for slotIDMemory=1,16 do |
35 | - | turnRight(); |
35 | + | local data = turtle.getItemDetail(slotIDMemory); |
36 | - | turtle.dig();--tesseract |
36 | + | if data and memorizedItemInventory[data.name..data.damage] > 0 then |
37 | - | turnRight();--pipe |
37 | + | turtle.select(slotIDMemory); |
38 | - | turtle.dig(); |
38 | + | turtle.transferTo(memorizedItemInventory[data.name..data.damage]); |
39 | - | goToCord(0,0,0); |
39 | + | end |
40 | end | |
41 | end | |
42 | ||
43 | ||
44 | - | if i ~=2 then |
44 | + | |
45 | placeAt(1,0,0,1);--well | |
46 | turnLeft(); | |
47 | placeAt(1,0,0,1);--well | |
48 | turnLeft(); | |
49 | - | until turtle.drop() or turtle.dropDown(); |
49 | + | placeAt(1,0,0,1);--well |
50 | turnLeft(); | |
51 | placeAt(1,0,0,1);--well | |
52 | turnLeft(); | |
53 | placeDownAt(1,0,0,1);--bottom well | |
54 | goToCord(2,0,0);--turtle resting spot | |
55 | placeDownAt(2,0,0,2);--tesseract | |
56 | ||
57 | end | |
58 | ||
59 | function loadSystems() | |
60 | - | return peripheral.call("front","hasWork") |
60 | + | |
61 | end | |
62 | function dumpAllItems() | |
63 | ||
64 | for i=1,16 do | |
65 | if true then | |
66 | local data = turtle.getItemDetail(i); | |
67 | if data and not isUndroppable[data.name..data.damage] then | |
68 | goToCord(2,0,0); | |
69 | repeat | |
70 | turtle.select(i); | |
71 | until turtle.dropDown(); | |
72 | ||
73 | end | |
74 | end | |
75 | end | |
76 | end | |
77 | ||
78 | function dumpAllItemsAndReturnToWork() | |
79 | local rememberCordX=currentX; | |
80 | local rememberCordY=currentY; | |
81 | local rememberCordZ=currentZ; | |
82 | for iDropReturn=1,16 do | |
83 | if true then | |
84 | local data = turtle.getItemDetail(iDropReturn); | |
85 | if data and not isUndroppable[data.name..data.damage] then | |
86 | print("trying at "..iDropReturn,currentX,currentY,currentZ); | |
87 | goToCord(2,0,0); | |
88 | repeat | |
89 | turtle.select(iDropReturn); | |
90 | until turtle.dropDown(); | |
91 | ||
92 | end | |
93 | end | |
94 | end | |
95 | goToCord(rememberCordY,rememberCordX,rememberCordZ); | |
96 | end | |
97 | ||
98 | ||
99 | ||
100 | function isStillWorking() | |
101 | return peripheral.call("bottom","hasWork") | |
102 | end | |
103 | ||
104 | ||
105 | local currRad=1 -- 0 is the right, 1 is default (original direction), 2 is the left, 3 is the back | |
106 | local cacheSlot = {} | |
107 | function place(slotID) | |
108 | zz.select(slotID) | |
109 | if zz.getItemCount()>0 then | |
110 | return zz.place() | |
111 | end | |
112 | return false | |
113 | end | |
114 | function placeUp(slotID) | |
115 | zz.select(slotID) | |
116 | if zz.getItemCount()>0 then | |
117 | return zz.placeUp() | |
118 | end | |
119 | return false | |
120 | end | |
121 | function placeDown(slotID) | |
122 | zz.select(slotID) | |
123 | if zz.getItemCount()>0 then | |
124 | return zz.placeDown() | |
125 | end | |
126 | return false | |
127 | end | |
128 | function refuel(amount) | |
129 | while zz.getFuelLevel()<=math.abs(amount) do | |
130 | zz.select(16) | |
131 | zz.refuel(1) | |
132 | print("Refueling") | |
133 | end | |
134 | end | |
135 | function turnRight() | |
136 | while zz.turnRight() do | |
137 | currRad=(currRad-1)%4 | |
138 | break | |
139 | end | |
140 | end | |
141 | function turnLeft() | |
142 | while zz.turnLeft() do | |
143 | currRad=(currRad+1)%4 | |
144 | break | |
145 | end | |
146 | end | |
147 | function turnToRad(r) | |
148 | if currRad==r then | |
149 | return true | |
150 | end | |
151 | while currRad~=r do | |
152 | if currRad>r then | |
153 | turnRight() | |
154 | elseif currRad<r then | |
155 | turnLeft() | |
156 | end | |
157 | end | |
158 | end | |
159 | function alertForProblem(stringCauseOfProblem) | |
160 | zz.turnRight() | |
161 | zz.turnRight() | |
162 | zz.turnRight() | |
163 | zz.turnRight() | |
164 | print(stringCauseOfProblem) | |
165 | end | |
166 | function moveByX(ox) | |
167 | local x=currentX+ox | |
168 | turnToRad(0) | |
169 | refuel(ox) | |
170 | while ox~=0 do | |
171 | if ox<0 then | |
172 | if zz.back() then | |
173 | ox=ox+1 | |
174 | currentX=currentX-1 | |
175 | else | |
176 | alertForProblem("can not move - check fuel or obstacle") | |
177 | moveByX(ox) | |
178 | break | |
179 | end | |
180 | else | |
181 | if zz.forward() then | |
182 | ox=ox-1 | |
183 | currentX=currentX+1 | |
184 | else | |
185 | alertForProblem("can not move - check fuel or obstacle") | |
186 | moveByX(ox) | |
187 | break | |
188 | end | |
189 | end | |
190 | end | |
191 | end | |
192 | function moveByZ(oz) | |
193 | local z=currentZ+oz | |
194 | turnToRad(1) | |
195 | refuel(oz) | |
196 | while oz~=0 do | |
197 | if oz<0 then | |
198 | if zz.back() then | |
199 | oz=oz+1 | |
200 | currentZ=currentZ-1 | |
201 | else | |
202 | alertForProblem("can not move - check fuel or obstacle") | |
203 | moveByZ(oz) | |
204 | break | |
205 | end | |
206 | else | |
207 | if zz.forward() then | |
208 | oz=oz-1 | |
209 | currentZ=currentZ+1 | |
210 | else | |
211 | alertForProblem("can not move - check fuel or obstacle") | |
212 | moveByZ(oz) | |
213 | break | |
214 | end | |
215 | end | |
216 | end | |
217 | end | |
218 | function moveByY(oy) | |
219 | local y=currentY+oy | |
220 | refuel(oy) | |
221 | while oy~=0 do | |
222 | if oy<0 then | |
223 | if zz.down() then | |
224 | oy=oy+1 | |
225 | currentY=currentY-1 | |
226 | else | |
227 | alertForProblem("can not move down - check fuel or obstacle") | |
228 | - | unloadSystems() |
228 | + | |
229 | break | |
230 | end | |
231 | else | |
232 | if zz.up() then | |
233 | - | turnLeft(); |
233 | + | |
234 | - | |
234 | + | |
235 | - | turtle.select(2); |
235 | + | |
236 | - | turtle.digUp(); |
236 | + | |
237 | - | goToCord(1,0,0); |
237 | + | |
238 | - | dumpAllItems(); |
238 | + | |
239 | - | loadSystems(); |
239 | + | |
240 | end | |
241 | - | turtle.forward(); |
241 | + | |
242 | end | |
243 | function goToCord(y,x,z) | |
244 | local differenceX=x-(currentX) | |
245 | local differenceY=y-currentY | |
246 | local differenceZ=z-currentZ | |
247 | if differenceX~=0 then moveByX(differenceX) end | |
248 | if differenceY~=0 then moveByY(differenceY) end | |
249 | if differenceZ~=0 then moveByZ(differenceZ) end | |
250 | end | |
251 | ||
252 | function placeAt(y,x,z,slotID) | |
253 | goToCord(y,x,z) | |
254 | if place(slotID) then return true | |
255 | else | |
256 | alertForProblem("can not place ahead - must be air ahead or do I have a material to place") | |
257 | placeAt(y,x,z,slotID) | |
258 | end | |
259 | end | |
260 | function placeUpAt(y,x,z,slotID) | |
261 | goToCord(y,x,z) | |
262 | if placeUp(slotID) then return true | |
263 | else | |
264 | alertForProblem("can not place up - must be air ahead or do I have a material to place") | |
265 | placeUpAt(y,x,z,slotID) | |
266 | end | |
267 | end | |
268 | ||
269 | function placeDownAt(y,x,z,slotID) | |
270 | goToCord(y,x,z) | |
271 | if placeDown(slotID) then return true | |
272 | else | |
273 | alertForProblem("can not place down - must be air ahead or do I have a material to place") | |
274 | placeUpAt(y,x,z,slotID) | |
275 | end | |
276 | end | |
277 | ||
278 | ||
279 | local repeatUntil=1; | |
280 | ||
281 | setCurrentItemsUndroppable(); | |
282 | memorizeItemSlot(); | |
283 | if (#args==1) and tonumber(args[1])>1 then | |
284 | repeatUntil=tonumber(args[1]); | |
285 | end | |
286 | for zd=1,repeatUntil do | |
287 | unloadSystems(); | |
288 | turtle.select(4); | |
289 | goToCord(2,1,0); | |
290 | repeat | |
291 | os.sleep(1); | |
292 | until not isStillWorking(); | |
293 | ||
294 | --finished work, lets pack it up here | |
295 | dumpAllItemsAndReturnToWork(); | |
296 | turtle.select(1); | |
297 | turtle.digDown(); | |
298 | goToCord(2,0,1); | |
299 | repeat | |
300 | os.sleep(1); | |
301 | until not isStillWorking(); | |
302 | dumpAllItemsAndReturnToWork(); | |
303 | turtle.select(1); | |
304 | turtle.digDown(); | |
305 | goToCord(2,-1,0); | |
306 | repeat | |
307 | os.sleep(1); | |
308 | until not isStillWorking(); | |
309 | dumpAllItemsAndReturnToWork(); | |
310 | turtle.select(1); | |
311 | turtle.digDown(); | |
312 | goToCord(2,0,-1); | |
313 | repeat | |
314 | os.sleep(1); | |
315 | until not isStillWorking(); | |
316 | dumpAllItemsAndReturnToWork(); | |
317 | turtle.select(1); | |
318 | turtle.digDown(); | |
319 | goToCord(2,0,0); | |
320 | turtle.select(2); | |
321 | turtle.digDown(); | |
322 | goToCord(1,0,0); | |
323 | turtle.select(1); | |
324 | turtle.digDown();--destroying bottom well | |
325 | goToCord(0,0,0); | |
326 | if repeatUntil>1 then | |
327 | local moveForward=0; | |
328 | repeat | |
329 | if turtle.forward() then moveForward=moveForward+1; end | |
330 | until moveForward==3; | |
331 | end | |
332 | end | |
333 | print("done"); |