SHOW:
|
|
- or go back to the newest paste.
1 | rednet.open("left") | |
2 | local data = {} | |
3 | local x, y, z | |
4 | p = peripheral.wrap("right") | |
5 | ||
6 | function waitDone() | |
7 | while not p.isActionDone() do | |
8 | sleep(1) | |
9 | end | |
10 | end | |
11 | ||
12 | function isDone(data, id) | |
13 | rednet.send(id, p.isActionDone()) | |
14 | end | |
15 | ||
16 | function hasItem(data, id) | |
17 | if data[1] ~= "" then | |
18 | p.clearWhitelistItemFilter() | |
19 | p.addWhitelistItemFilter(data[1], 0, false, false, false, false) | |
20 | end | |
21 | p.setAction("droneConditionItem") | |
22 | rednet.send(id, p.evaluateCondition()) | |
23 | p.clearWhitelistItemFilter() | |
24 | end | |
25 | ||
26 | function getPressure(data, id) | |
27 | rednet.send(id, p.getDronePressure()) | |
28 | end | |
29 | ||
30 | function getPosition(data, id) | |
31 | local tempdata = {} | |
32 | tempdata[1], tempdata[2], tempdata[3] = p.getDronePosition() | |
33 | rednet.send(id, textutils.serialize(tempdata)) | |
34 | end | |
35 | ||
36 | function goto(data) | |
37 | p.clearArea() | |
38 | p.addArea(data[1], data[2], data[3]) | |
39 | p.setAction("goto") | |
40 | end | |
41 | ||
42 | function setSpot(data) | |
43 | p.addArea(data[1], data[2], data[3]) | |
44 | end | |
45 | ||
46 | function setArea(data) | |
47 | p.addArea(data[1], data[2], data[3], data[4], data[5], data[6], data[7]) | |
48 | end | |
49 | ||
50 | function showArea() | |
51 | if data[1] then | |
52 | p.showArea() | |
53 | else | |
54 | p.hideArea() | |
55 | end | |
56 | end | |
57 | ||
58 | function clearArea() | |
59 | p.clearArea() | |
60 | end | |
61 | ||
62 | function dig() | |
63 | p.clearWhitelistItemFilter() | |
64 | p.setAction("dig") | |
65 | end | |
66 | ||
67 | function place() | |
68 | p.clearWhitelistItemFilter() | |
69 | p.setAction("place") | |
70 | end | |
71 | ||
72 | function attack() | |
73 | p.forgetTarget() | |
74 | p.setAction("entityAttack") | |
75 | end | |
76 | ||
77 | function pickup() | |
78 | p.clearWhitelistItemFilter() | |
79 | p.setAction("pickupItem") | |
80 | end | |
81 | ||
82 | function inventoryImport(data) | |
83 | if data[1] ~= "" then | |
84 | p.clearWhitelistItemFilter() | |
85 | p.addWhitelistItemFilter(data[1], 0, false, false, false, false) | |
86 | else | |
87 | p.clearWhitelistItemFilter() | |
88 | end | |
89 | p.setSides(true, true, true, true, true, true) | |
90 | p.setAction("inventoryImport") | |
91 | --p.clearWhitelistItemFilter() | |
92 | --p.setSides(false, false, false, false, false, false) | |
93 | end | |
94 | ||
95 | function inventoryExport(data) | |
96 | if data[1] ~= "" then | |
97 | p.clearWhitelistItemFilter() | |
98 | p.addWhitelistItemFilter(data[1], 0, false, false, false, false) | |
99 | else | |
100 | p.clearWhitelistItemFilter() | |
101 | end | |
102 | p.setSides(true, true, true, true, true, true) | |
103 | p.setAction("inventoryExport") | |
104 | --p.clearWhitelistItemFilter() | |
105 | --p.setSides(false, false, false, false, false, false) | |
106 | end | |
107 | ||
108 | function msg() | |
109 | data = {} | |
110 | id, message, distance, protocol = rednet.receive() | |
111 | print(message) | |
112 | data = textutils.unserialize(message) | |
113 | if data[0] == "goto" then | |
114 | goto(data) | |
115 | elseif data[0] == "setSpot" then | |
116 | setSpot(data) | |
117 | elseif data[0] == "setArea" then | |
118 | setArea(data) | |
119 | elseif data[0] == "dig" then | |
120 | dig() | |
121 | elseif data[0] == "pickup" then | |
122 | pickup() | |
123 | elseif data[0] == "clearArea" then | |
124 | clearArea() | |
125 | elseif data[0] == "showArea" then | |
126 | showArea(data) | |
127 | elseif data[0] == "inventoryImport" then | |
128 | inventoryImport(data) | |
129 | elseif data[0] == "inventoryExport" then | |
130 | inventoryExport(data) | |
131 | elseif data[0] == "isDone" then | |
132 | isDone(data, id) | |
133 | elseif data[0] == "getPressure" then | |
134 | getPressure(data, id) | |
135 | elseif data[0] == "getPosition" then | |
136 | getPosition(data, id) | |
137 | elseif data[0] == "hasItem" then | |
138 | hasItem(data, id) | |
139 | elseif data[0] == "attack" then | |
140 | attack() | |
141 | elseif data[0] == "place" then | |
142 | place() | |
143 | end | |
144 | ||
145 | end | |
146 | ||
147 | while true do | |
148 | msg() | |
149 | end |