SHOW:
|
|
- or go back to the newest paste.
1 | Sensorside = "bottom" | |
2 | PIPE_SIDE = "right" | |
3 | ||
4 | function ClearPages() | |
5 | sleep(0.5) | |
6 | redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.black)) | |
7 | sleep(0.5) | |
8 | redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.black)) | |
9 | sleep(2) | |
10 | end | |
11 | ||
12 | function ResetSignals() | |
13 | sleep(0.5) | |
14 | redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.orange)) | |
15 | sleep(0.5) | |
16 | redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.blue)) | |
17 | end | |
18 | ||
19 | function RequestItems() | |
20 | -- IMPLEMENTATION | |
21 | function convertNBT(nbt) | |
22 | local conv = {} | |
23 | if (nbt == nil) then | |
24 | return nil | |
25 | elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then | |
26 | for key, value in pairs(nbt["value"]) do | |
27 | conv[key] = convertNBT(value) | |
28 | end | |
29 | else | |
30 | conv = nbt["value"] | |
31 | end | |
32 | return conv | |
33 | end | |
34 | ||
35 | function getItems(pipe) | |
36 | pipe.getAvailableItems() | |
37 | local event, result = os.pullEvent("available_items_return") | |
38 | return result | |
39 | end | |
40 | ||
41 | -- Funktion inList anpassen, um Variablen zu verwenden | |
42 | function inList(item) | |
43 | local id = item.id | |
44 | local dmg = item.dmg | |
45 | local idKey = tostring(id) | |
46 | local exists, requestAmount = false, 0 | |
47 | ||
48 | local variantKey = idKey .. ":" .. tostring(dmg) | |
49 | if REQUEST_IDS[variantKey] then | |
50 | exists = true | |
51 | requestAmount = REQUEST_IDS[variantKey] | |
52 | end | |
53 | ||
54 | return exists, requestAmount | |
55 | end | |
56 | ||
57 | -- MAIN | |
58 | local pipe = peripheral.wrap(PIPE_SIDE) | |
59 | for i, result in pairs(getItems(pipe)) do | |
60 | local iid, amount = unpack(result) | |
61 | local item = { | |
62 | id = pipe.getItemID(iid), | |
63 | dmg = pipe.getItemDamage(iid), | |
64 | nbt = convertNBT(pipe.getNBTTagCompound(iid)) | |
65 | } | |
66 | local exists, requestAmount = inList(item) | |
67 | if exists then | |
68 | pipe.makeRequest(iid, requestAmount) | |
69 | sleep(0.15) | |
70 | end | |
71 | end | |
72 | end | |
73 | ||
74 | function ladeItems(page) | |
75 | local datei = fs.open("ItemsInPage" .. page, "r") -- Datei im Lesemodus åB6ffnen | |
76 | if not datei then | |
77 | print("Fehler: Datei nicht gefunden") | |
78 | return | |
79 | end | |
80 | ||
81 | local items = { | |
82 | ItemName = {}, | |
83 | ItemSize = {}, | |
84 | ItemID_1 = {}, | |
85 | ItemID_2 = {} | |
86 | } | |
87 | ||
88 | -- Schleife durch jede Zeile der Datei | |
89 | MaxItems = 0 | |
90 | repeat | |
91 | local zeile = datei.readLine() | |
92 | if zeile then | |
93 | local itemName, itemSize, itemID = zeile:match("([^%-]+)%-([^%-]+)%-(.+)") | |
94 | if itemName and itemSize and itemID then | |
95 | table.insert(items.ItemName, itemName) | |
96 | table.insert(items.ItemSize, tonumber(itemSize)) | |
97 | table.insert(items.ItemID_1, tonumber(itemID:match("%d+"))) | |
98 | table.insert(items.ItemID_2, tonumber(itemID:match(":(%d+)"))) | |
99 | MaxItems = MaxItems + 1 | |
100 | else | |
101 | print("Fehlerhafte Zeile in der Datei: " .. zeile) | |
102 | end | |
103 | end | |
104 | until not zeile | |
105 | ||
106 | datei:close() -- Datei schlieå9Fen | |
107 | ||
108 | return items | |
109 | end | |
110 | ||
111 | function RequestPage() | |
112 | local ItemsInPage = ladeItems(Page) -- Lade Items aus der Page | |
113 | for a = 1, MaxItems do | |
114 | ItemID_1 = ItemsInPage.ItemID_1[a] | |
115 | ItemID_2 = ItemsInPage.ItemID_2[a] | |
116 | ItemSize = ItemsInPage.ItemSize[a] | |
117 | ||
118 | io.write(ItemsInPage.ItemName[a] .. " ") | |
119 | io.write(ItemsInPage.ItemID_1[a] .. ":") | |
120 | io.write(ItemsInPage.ItemID_2[a] .. " ") | |
121 | io.write(ItemsInPage.ItemSize[a] .. " ") | |
122 | io.write("\n") | |
123 | ||
124 | REQUEST_IDS = { | |
125 | [tostring(ItemID_1) .. ":" .. tostring(ItemID_2)] = ItemSize,} | |
126 | RequestItems() | |
127 | sleep(sle) | |
128 | end | |
129 | end | |
130 | ||
131 | ------programm start------ | |
132 | sle = 0.1 --Sleep zwischen jeder Request | |
133 | os.loadAPI("ocs/apis/sensor") | |
134 | sen = sensor.wrap("bottom") | |
135 | ||
136 | redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.orange)) --orange an | |
137 | sleep(0.5) | |
138 | redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.blue)) --blau aus | |
139 | ||
140 | while true do | |
141 | s = sen.getTargets() | |
142 | function getS() | |
143 | for v, k in pairs(s) do | |
144 | if k.Name == "ME Wireless Access Point" then | |
145 | target = v | |
146 | end | |
147 | end | |
148 | return target | |
149 | end | |
150 | ||
151 | f = getS() | |
152 | s1 = sen.getTargetDetails(target) | |
153 | ||
154 | local Page1 = 0 | |
155 | local Page2 = 0 | |
156 | local Page3 = 0 | |
157 | local Page4 = 0 | |
158 | local Page5 = 0 | |
159 | local Page6 = 0 | |
160 | local Page7 = 0 | |
161 | local Page8 = 0 | |
162 | local Page9 = 0 | |
163 | ||
164 | for _, item in pairs(s1.Items) do | |
165 | if item.Name == "ME Wireless Access Terminal" then | |
166 | Page1 = item.Size -- Werte ermittels und setzen | |
167 | end | |
168 | if item.Name == "Advanced Solar Panel" then | |
169 | Page2 = item.Size -- Werte ermittels und setzen | |
170 | end | |
171 | if item.Name == "Remote Orderer" then | |
172 | Page3 = item.Size -- Werte ermittels und setzen | |
173 | end | |
174 | if item.Name == "Cobblestone" then | |
175 | Page4 = item.Size -- Werte ermittels und setzen | |
176 | end | |
177 | if item.Name == "tile.machineBlock" then | |
178 | Page5 = item.Size -- Werte ermittels und setzen | |
179 | end | |
180 | if item.Name == "item.PipeItemsDiamond" then | |
181 | Page6 = item.Size -- Werte ermittels und setzen | |
182 | end | |
183 | if item.Name == "Electric Furnace" then | |
184 | Page7 = item.Size -- Werte ermittels und setzen | |
185 | end | |
186 | if item.Name == "Clay Dust" then | |
187 | Page8 = item.Size -- Werte ermittels und setzen | |
188 | end | |
189 | if item.Name == "Wooden Axe" then | |
190 | Page9 = item.Size -- Werte ermittels und setzen | |
191 | end | |
192 | if item.Size < 0 then | |
193 | os.reboot() | |
194 | end | |
195 | end | |
196 | ||
197 | term.setCursorPos(1,1) | |
198 | term.clear() | |
199 | print("1: "..Page1) | |
200 | print("2: "..Page2) | |
201 | print("3: "..Page3) | |
202 | print("4: "..Page4) | |
203 | print("5: "..Page5) | |
204 | print("6: "..Page6) | |
205 | print("7: "..Page7) | |
206 | print("8: "..Page8) | |
207 | print("9: "..Page9) | |
208 | ||
209 | reboot = 1 | |
210 | if Page1 < 1 or Page2 < 1 or Page3 < 1 or Page4 < 1 or Page5 < 1 or Page6 < 1 or Page7 < 1 or Page8 < 1 or Page9 < 1 then | |
211 | ResetSignals() | |
212 | ClearPages() | |
213 | ||
214 | if Page1 < 1 then | |
215 | Page = 1 | |
216 | elseif Page2 < 1 then | |
217 | Page = 2 | |
218 | elseif Page3 < 1 then | |
219 | Page = 3 | |
220 | elseif Page4 < 1 then | |
221 | Page = 4 | |
222 | elseif Page4 < 1 then | |
223 | Page = 5 | |
224 | elseif Page4 < 1 then | |
225 | Page = 6 | |
226 | elseif Page4 < 1 then | |
227 | Page = 7 | |
228 | elseif Page4 < 1 then | |
229 | Page = 8 | |
230 | elseif Page4 < 1 then | |
231 | Page = 9 | |
232 | end | |
233 | ||
234 | if Page1 < 1 or Page2 < 1 or Page3 < 1 or Page4 < 1 or Page5 < 1 or Page6 < 1 or Page7 < 1 or Page8 < 1 or Page9 < 1 then | |
235 | RequestPage() | |
236 | sleep(2) | |
237 | reboot = 0 | |
238 | end | |
239 | end | |
240 | ||
241 | if reboot == 0 then | |
242 | os.reboot() | |
243 | end | |
244 | sleep(1) | |
245 | end |