SHOW:
|
|
- or go back to the newest paste.
1 | rednet.open("back") | |
2 | os.loadAPI("button") | |
3 | local m = term | |
4 | local areaShown = false | |
5 | ||
6 | local homex = -847 | |
7 | local homey = 168 | |
8 | local homez = 970 | |
9 | ||
10 | local setx = 0 | |
11 | local sety = 0 | |
12 | local setz = 0 | |
13 | local setx2 = 0 | |
14 | local sety2 = 0 | |
15 | local setz2 = 0 | |
16 | local currx = 0 | |
17 | local curry = 0 | |
18 | local currz = 0 | |
19 | local chestx = 0 | |
20 | local chesty = 0 | |
21 | local chestz = 0 | |
22 | ||
23 | local menuType = "mainMenu" | |
24 | local areaType = "Filled" | |
25 | local moveMode = "Normal" | |
26 | ||
27 | ||
28 | function sendMessage(message) | |
29 | rednet.send(59, message) | |
30 | end | |
31 | ||
32 | function mainMenu() | |
33 | m.clear() | |
34 | button.clearTable() | |
35 | button.setTable("Come Here", comeHere, "", 3, 13, 1, 1) | |
36 | button.setTable("Go Home", goHome, "", 15, 25, 1, 1) | |
37 | button.setTable("Set Area", setXYZMenu, "", 3, 13, 3, 3) | |
38 | button.setTable("GoTo", goTo, "", 15, 25, 3, 3) | |
39 | button.setTable("Dig", dig, "", 3, 13, 5, 5) | |
40 | button.setTable("Get Pick", getPickaxe, "", 15, 25, 5, 5) | |
41 | button.setTable("Pickup", pickup, "", 3, 13, 7, 7) | |
42 | button.setTable("GetItems", getItems, "", 15, 25, 7, 7) | |
43 | button.setTable("ItemsChest", dropItems, "", 15, 25, 9, 9) | |
44 | button.setTable("Attack", attack, "", 3, 13, 9, 9) | |
45 | button.setTable("Build", place, "", 3, 13, 11, 11) | |
46 | button.setTable("Set Chest", setChest, "", 3, 13, 16, 16) | |
47 | button.setTable("Show Area", showAreaToggle, "", 15, 25, 18, 18) | |
48 | button.setTable("Status", setStatusMenu, "", 3, 13, 18, 18) | |
49 | if chesty ~= 0 then | |
50 | button.toggleButton("Set Chest") | |
51 | end | |
52 | button.setButton("Show Area", areaShown) | |
53 | button.screen() | |
54 | end | |
55 | ||
56 | function statusMenu() | |
57 | local x,y,z = getPosition() | |
58 | m.clear() | |
59 | button.clearTable() | |
60 | button.setTable("Back", setMainMenu, "", 1, 6, 1, 1) | |
61 | button.setTable("Refresh", displayScreen, "", 2, 25, 20,20) | |
62 | button.label(1,3,"Pressure: "..getPressure()) | |
63 | button.label(1,4,"Position: "..math.floor(x)..","..math.floor(y)..","..math.floor(z)) | |
64 | button.label(1,5,"Action: "..tostring(not isDone())) | |
65 | -- button.label(1,6,"Pickaxe: "..tostring(hasPickaxe())) | |
66 | button.screen() | |
67 | end | |
68 | ||
69 | function xyzMenu() | |
70 | m.clear() | |
71 | button.clearTable() | |
72 | button.label(1,1,"Position: "..currx..","..curry..","..currz) | |
73 | button.setTable("Back", setMainMenu, "", 1, 6, 2, 2) | |
74 | button.setTable(moveMode, toggleMoveMode, "", 10, 20, 2, 2) | |
75 | button.label(1,4,"X: ") | |
76 | button.setTable("x-10", changeX, -10, 4, 7, 4, 4) | |
77 | button.setTable("x-1", changeX, -1, 9, 11, 4, 4) | |
78 | button.label(15, 4, setx) | |
79 | button.setTable("x+1", changeX, 1, 18, 20, 4, 4) | |
80 | button.setTable("x+10", changeX, 10, 22, 25, 4, 4) | |
81 | button.label(1,6,"Y: ") | |
82 | button.setTable("y-10", changeY, -10, 4, 7, 6, 6) | |
83 | button.setTable("y-1", changeY, -1, 9, 11, 6, 6) | |
84 | button.label(15, 6, sety) | |
85 | button.setTable("y+1", changeY, 1, 18, 20, 6, 6) | |
86 | button.setTable("y+10", changeY, 10, 22, 25, 6, 6) | |
87 | button.label(1,8,"Z: ") | |
88 | button.setTable("z-10", changeZ, -10, 4, 7, 8, 8) | |
89 | button.setTable("z-1", changeZ, -1, 9, 11, 8, 8) | |
90 | button.label(15, 8, setz) | |
91 | button.setTable("z+1", changeZ, 1, 18, 20, 8, 8) | |
92 | button.setTable("z+10", changeZ, 10, 22, 25, 8, 8) | |
93 | if moveMode == "Normal" then | |
94 | button.label(1,10,"X2: ") | |
95 | button.setTable("a-10", changeX2, -10, 4, 7, 10, 10) | |
96 | button.setTable("a-1", changeX2, -1, 9, 11, 10, 10) | |
97 | button.label(15, 10, setx2) | |
98 | button.setTable("a+1", changeX2, 1, 18, 20, 10, 10) | |
99 | button.setTable("a+10", changeX2, 10, 22, 25, 10, 10) | |
100 | button.label(1,12,"Y2: ") | |
101 | button.setTable("b-10", changeY2, -10, 4, 7, 12, 12) | |
102 | button.setTable("b-1", changeY2, -1, 9, 11, 12, 12) | |
103 | button.label(15, 12, sety2) | |
104 | button.setTable("b+1", changeY2, 1, 18, 20, 12, 12) | |
105 | button.setTable("b+10", changeY2, 10, 22, 25, 12, 12) | |
106 | button.label(1,14,"Z2: ") | |
107 | button.setTable("c-10", changeZ2, -10, 4, 7, 14, 14) | |
108 | button.setTable("c-1", changeZ2, -1, 9, 11, 14, 14) | |
109 | button.label(15, 14, setz2) | |
110 | button.setTable("c+1", changeZ2, 1, 18, 20, 14, 14) | |
111 | button.setTable("c+10", changeZ2, 10, 22, 25, 14, 14) | |
112 | end | |
113 | button.setTable("Reset", resetXYZ, "", 10, 20, 16, 16) | |
114 | button.setTable(areaType, toggleAreaType, "", 3, 13, 18, 18) | |
115 | button.setTable("Show Area", showAreaToggle, "", 15, 25, 18, 18) | |
116 | button.setTable("Clear Area", clearArea, "", 3, 13, 20, 20) | |
117 | button.setTable("Apply", refreshArea, "", 15, 25, 20, 20) | |
118 | button.setButton("Show Area", areaShown) | |
119 | button.screen() | |
120 | end | |
121 | ||
122 | function toggleMoveMode() | |
123 | if moveMode == "Normal" then | |
124 | moveMode = "Move" | |
125 | elseif moveMode == "Move" then | |
126 | moveMode = "Expand" | |
127 | elseif moveMode == "Expand" then | |
128 | moveMode = "Normal" | |
129 | end | |
130 | end | |
131 | ||
132 | function getPressure() | |
133 | local data = {} | |
134 | data[0] = "getPressure" | |
135 | sendMessage(textutils.serialize(data)) | |
136 | local id, message, distance, protocol = rednet.receive(5) | |
137 | return(message) | |
138 | end | |
139 | ||
140 | function getPosition() | |
141 | local data = {} | |
142 | data[0] = "getPosition" | |
143 | sendMessage(textutils.serialize(data)) | |
144 | local id, message, distance, protocol = rednet.receive(5) | |
145 | local returnData = textutils.unserialize(message) | |
146 | return returnData[1], returnData[2], returnData[3] | |
147 | end | |
148 | ||
149 | function toggleAreaType() | |
150 | if areaType == "Filled" then | |
151 | areaType = "Frame" | |
152 | elseif areaType == "Frame" then | |
153 | areaType = "Walls" | |
154 | elseif areaType == "Walls" then | |
155 | areaType = "Filled" | |
156 | else | |
157 | areaType = "Filled" | |
158 | end | |
159 | refreshArea() | |
160 | end | |
161 | ||
162 | function resetXYZ() | |
163 | setx = 0 | |
164 | sety = 0 | |
165 | setz = 0 | |
166 | setx2 = 0 | |
167 | sety2 = 0 | |
168 | setz2 = 0 | |
169 | currx,curry,currz = gpsLocate() | |
170 | refreshArea() | |
171 | end | |
172 | ||
173 | function setXYZMenu() | |
174 | if curry==0 then | |
175 | currx,curry,currz = gpsLocate() | |
176 | end | |
177 | menuType = "xyzMenu" | |
178 | end | |
179 | ||
180 | function setMainMenu() | |
181 | menuType = "mainMenu" | |
182 | end | |
183 | ||
184 | function setStatusMenu() | |
185 | menuType = "statusMenu" | |
186 | end | |
187 | ||
188 | function refreshArea() | |
189 | setAreaGlobal() | |
190 | showArea(false) | |
191 | showArea(true) | |
192 | areaShown = true | |
193 | end | |
194 | ||
195 | function setChest() | |
196 | chestx = currx+setx | |
197 | chesty = curry+sety | |
198 | chestz = currz+setz | |
199 | end | |
200 | ||
201 | function setAreaGlobal() | |
202 | clearArea() | |
203 | local data = {} | |
204 | data[0] = "setArea" | |
205 | data[1] = currx+setx | |
206 | data[2] = curry+sety | |
207 | data[3] = currz+setz | |
208 | data[4] = currx+setx2 | |
209 | data[5] = curry+sety2 | |
210 | data[6] = currz+setz2 | |
211 | data[7] = areaType | |
212 | sendMessage(textutils.serialize(data)) | |
213 | end | |
214 | ||
215 | function showAreaToggle() | |
216 | areaShown = not areaShown | |
217 | showArea(areaShown) | |
218 | end | |
219 | ||
220 | function changeX(change) | |
221 | setx = setx + change | |
222 | if moveMode == "Move" then | |
223 | setx2 = setx2 + change | |
224 | elseif moveMode == "Expand" then | |
225 | setx2 = setx2 - change | |
226 | end | |
227 | end | |
228 | ||
229 | function changeY(change) | |
230 | sety = sety+change | |
231 | if moveMode == "Move" then | |
232 | sety2 = sety2 + change | |
233 | elseif moveMode == "Expand" then | |
234 | sety2 = sety2 - change | |
235 | end | |
236 | end | |
237 | ||
238 | function changeZ(change) | |
239 | setz = setz+change | |
240 | if moveMode == "Move" then | |
241 | setz2 = setz2 + change | |
242 | elseif moveMode == "Expand" then | |
243 | setz2 = setz2 - change | |
244 | end | |
245 | end | |
246 | ||
247 | function changeX2(change) | |
248 | setx2 = setx2 + change | |
249 | end | |
250 | ||
251 | function changeY2(change) | |
252 | sety2 = sety2+change | |
253 | end | |
254 | ||
255 | function changeZ2(change) | |
256 | setz2 = setz2+change | |
257 | end | |
258 | ||
259 | function gpsLocate() | |
260 | local x,y,z = gps.locate() | |
261 | return math.floor(x)-1, math.floor(y), math.floor(z) | |
262 | end | |
263 | ||
264 | function comeHere() | |
265 | local data = {} | |
266 | local x,y,z = gpsLocate() | |
267 | data[0] = "goto" | |
268 | data[1] = x | |
269 | data[2] = y | |
270 | data[3] = z | |
271 | sendMessage(textutils.serialize(data)) | |
272 | end | |
273 | ||
274 | function setSpot(x,y,z) | |
275 | clearArea() | |
276 | local data = {} | |
277 | data[0] = "setSpot" | |
278 | data[1] = x | |
279 | data[2] = y | |
280 | data[3] = z | |
281 | sendMessage(textutils.serialize(data)) | |
282 | end | |
283 | ||
284 | function setArea(x1,y1,z1,x2,y2,z2) | |
285 | clearArea() | |
286 | local data = {} | |
287 | data[0] = "setArea" | |
288 | data[1] = x1 | |
289 | data[2] = y1 | |
290 | data[3] = z1 | |
291 | data[4] = x2 | |
292 | data[5] = y2 | |
293 | data[6] = z2 | |
294 | sendMessage(textutils.serialize(data)) | |
295 | end | |
296 | ||
297 | function hasItem(itemName) | |
298 | local data = {} | |
299 | data[0] = "hasItem" | |
300 | data[1] = itemName | |
301 | sendMessage(textutils.serialize(data)) | |
302 | local id, message, distance, protocol = rednet.receive(5) | |
303 | return(message) | |
304 | end | |
305 | ||
306 | function inventoryImport(itemName) | |
307 | local data = {} | |
308 | data[0] = "inventoryImport" | |
309 | data[1] = itemName | |
310 | sendMessage(textutils.serialize(data)) | |
311 | end | |
312 | ||
313 | function inventoryExport(itemName) | |
314 | local data = {} | |
315 | data[0] = "inventoryExport" | |
316 | data[1] = itemName | |
317 | sendMessage(textutils.serialize(data)) | |
318 | end | |
319 | ||
320 | function showArea(show) | |
321 | local data = {} | |
322 | data[0] = "showArea" | |
323 | data[1] = show | |
324 | sendMessage(textutils.serialize(data)) | |
325 | end | |
326 | ||
327 | function clearArea() | |
328 | local data = {} | |
329 | data[0] = "clearArea" | |
330 | sendMessage(textutils.serialize(data)) | |
331 | areaShown = false | |
332 | showArea(areaShown) | |
333 | end | |
334 | ||
335 | function pickup() | |
336 | local data = {} | |
337 | data[0] = "pickup" | |
338 | sendMessage(textutils.serialize(data)) | |
339 | end | |
340 | ||
341 | function dig() | |
342 | local data = {} | |
343 | data[0] = "dig" | |
344 | sendMessage(textutils.serialize(data)) | |
345 | end | |
346 | ||
347 | function place() | |
348 | local data = {} | |
349 | data[0] = "place" | |
350 | sendMessage(textutils.serialize(data)) | |
351 | end | |
352 | ||
353 | function attack() | |
354 | local data = {} | |
355 | data[0] = "attack" | |
356 | sendMessage(textutils.serialize(data)) | |
357 | end | |
358 | ||
359 | ||
360 | function isDone() | |
361 | local data = {} | |
362 | data[0] = "isDone" | |
363 | sendMessage(textutils.serialize(data)) | |
364 | local id, message, distance, protocol = rednet.receive(5) | |
365 | return(message) | |
366 | end | |
367 | ||
368 | function waitDone() | |
369 | while not isDone() do | |
370 | sleep(1) | |
371 | end | |
372 | end | |
373 | ||
374 | function hasPickaxe() | |
375 | return(hasItem("minecraft:diamond_pickaxe")) | |
376 | end | |
377 | ||
378 | function getPickaxe() | |
379 | if chesty ~= 0 then | |
380 | setSpot(chestx, chesty, chestz) | |
381 | inventoryImport("minecraft:diamond_pickaxe") | |
382 | setAreaGlobal() | |
383 | else | |
384 | button.label(1,20,"No Chest Location Set.") | |
385 | sleep(1) | |
386 | end | |
387 | end | |
388 | ||
389 | function getItems() | |
390 | if chesty ~= 0 then | |
391 | setSpot(chestx, chesty, chestz) | |
392 | inventoryImport("") | |
393 | setAreaGlobal() | |
394 | else | |
395 | button.label(1,20,"No Chest Location Set.") | |
396 | sleep(1) | |
397 | end | |
398 | end | |
399 | ||
400 | function dropItems() | |
401 | if chesty ~= 0 then | |
402 | setSpot(chestx, chesty, chestz) | |
403 | inventoryExport("") | |
404 | setAreaGlobal() | |
405 | else | |
406 | button.label(1,20,"No Chest Location Set.") | |
407 | sleep(1) | |
408 | end | |
409 | end | |
410 | ||
411 | function tempShowArea() | |
412 | showArea(true) | |
413 | sleep(3) | |
414 | showArea(false) | |
415 | end | |
416 | ||
417 | function setRadius(xRad, zRad, yUp, yDown) | |
418 | local x,y,z = gpsLocate() | |
419 | x = x | |
420 | y = y | |
421 | print(x..y..z) | |
422 | setArea(x-xRad, y-yDown, z-zRad, x+xRad, y+yUp, z+zRad) | |
423 | tempShowArea() | |
424 | end | |
425 | ||
426 | function setXYZ() | |
427 | local x,y,z = gpsLocate() | |
428 | x = x | |
429 | y = y | |
430 | ||
431 | setArea(x-xRad, y-yDown, z-zRad, x+xRad, y+yUp, z+zRad) | |
432 | ||
433 | end | |
434 | ||
435 | function goHome() | |
436 | local data = {} | |
437 | data[0] = "goto" | |
438 | data[1] = homex | |
439 | data[2] = homey | |
440 | data[3] = homez | |
441 | sendMessage(textutils.serialize(data)) | |
442 | end | |
443 | ||
444 | function goTo() | |
445 | local data = {} | |
446 | data[0] = "goto" | |
447 | data[1] = currx+setx | |
448 | data[2] = curry+sety | |
449 | data[3] = currz+setz | |
450 | sendMessage(textutils.serialize(data)) | |
451 | end | |
452 | ||
453 | function displayScreen() | |
454 | if menuType == "mainMenu" then | |
455 | mainMenu() | |
456 | elseif menuType == "xyzMenu" then | |
457 | xyzMenu() | |
458 | elseif menuType == "statusMenu" then | |
459 | statusMenu() | |
460 | end | |
461 | local event, side, x, y | |
462 | event, side, x, y = os.pullEvent() | |
463 | while event ~= "mouse_click" do | |
464 | event, side, x, y = os.pullEvent() | |
465 | end | |
466 | button.checkxy(x,y) | |
467 | end | |
468 | ||
469 | while true do | |
470 | displayScreen() | |
471 | end | |
472 | ||
473 | --clearArea() | |
474 | --dropItems() | |
475 | --getPickaxe() | |
476 | --setRadius(3,3,1,2) | |
477 | --dig() | |
478 | --waitDone() | |
479 | --clearArea() | |
480 | --setRadius(5,5,2,3) | |
481 | --pickup() | |
482 | --waitDone() | |
483 | --dropItems() | |
484 | ||
485 | --comeHere() |