Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ENTER A NAME FOR THIS POWER SITE
- site_name = "quarry1"
- -- ENTER THE SIDE YOU'RE CONNECTING THE MODEM TO
- side = "back"
- -- name of remote methods
- chest = "list"
- -- basic variables
- chest_baseName = "minecraft:ironchest_" --finishes with id
- between_requests= 30 -- waiting 30 seconds to update
- -- DON'T MODIFY THOSE UNLESS YOU'RE SURE OF YOURSELF
- -- URLs
- base = "https://mc-api.rudreais.com"
- api = base.."/api/v1"
- inventory_api = api.."/inventory"
- inventory_set = inventory_api.."/set/"..site_name
- headers = {
- ["Content-Type"] = "application/json"
- }
- chests = peripheral.wrap(side)
- function main()
- while true do
- count = 1
- for i, v in ipairs(chests.getNamesRemote()) do
- if string.match(v, chest_baseName) then
- obj = chests.callRemote(v, chest)
- items = {}
- for k, item in ipairs(obj) do
- tmp_name = item.name.."_"..item.damage
- if items[item.name] then
- items[tmp_name] = items[tmp_name] + item.count
- else
- items[tmp_name] = item.count
- end
- end
- for k, item in pairs(items) do
- table = {title=site_name, name_chest='chest'..count, APIName=k, quantity=item}
- data = textutils.serializeJSON(table)
- http.post(inventory_set, data, headers)
- end
- count = count + 1
- end
- end
- os.sleep(between_requests)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement