Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONSTANTS
- local INTERVAL = 120
- local PIPE_SIDE = "bottom"
- local REQUEST_IDS = {
- -- Beispiel für IDs mit Varianten
- [183] = {
- ["183:1"] = 5, -- Beispiel-Menge: 5 für ID 183:1
- ["183:2"] = 3, -- Beispiel-Menge: 3 für ID 183:2
- },
- -- ... andere IDs ...
- [267] = 10, -- Iron (Beispiel-Menge: 10)
- }
- -- IMPLEMENTATION
- function convertNBT(nbt)
- local conv = {}
- if (nbt == nil) then
- return nil
- elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
- for key, value in pairs(nbt["value"]) do
- conv[key] = convertNBT(value)
- end
- else
- conv = nbt["value"]
- end
- return conv
- end
- function getItems(pipe)
- pipe.getAvailableItems()
- local event, result = os.pullEvent("available_items_return")
- return result
- end
- function inList(item)
- local id = item.id
- local dmg = item.dmg
- local idKey = tostring(id)
- local exists, requestAmount = false, 0
- if REQUEST_IDS[id] then
- if type(REQUEST_IDS[id]) == "table" then
- local variantKey = idKey .. ":" .. tostring(dmg)
- if REQUEST_IDS[id][variantKey] then
- exists = true
- requestAmount = REQUEST_IDS[id][variantKey]
- end
- else
- exists = true
- requestAmount = REQUEST_IDS[id]
- end
- end
- return exists, requestAmount
- end
- -- MAIN
- local pipe = peripheral.wrap(PIPE_SIDE)
- while true do
- for i, result in pairs(getItems(pipe)) do
- local iid, amount = unpack(result)
- local item = {
- id = pipe.getItemID(iid),
- dmg = pipe.getItemDamage(iid),
- nbt = convertNBT(pipe.getNBTTagCompound(iid))
- }
- local exists, requestAmount = inList(item)
- if exists then
- pipe.makeRequest(iid, requestAmount)
- sleep(2)
- end
- end
- sleep(INTERVAL)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement