Advertisement
dreais

API_chests

Jun 29th, 2020
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. -- ENTER A NAME FOR THIS POWER SITE
  2. site_name       =   "quarry1"
  3. -- ENTER THE SIDE YOU'RE CONNECTING THE MODEM TO
  4. side            =   "back"
  5. -- name of remote methods
  6. chest           =   "list"
  7. -- basic variables
  8. chest_baseName   =   "minecraft:ironchest_" --finishes with id
  9. between_requests=   30 -- waiting 30 seconds to update
  10. -- DON'T MODIFY THOSE UNLESS YOU'RE SURE OF YOURSELF
  11. -- URLs
  12. base            =   "https://mc-api.rudreais.com"
  13. api             =   base.."/api/v1"
  14. inventory_api   =   api.."/inventory"
  15. inventory_set       =   inventory_api.."/set/"..site_name
  16. headers = {
  17.     ["Content-Type"] = "application/json"
  18. }
  19. chests = peripheral.wrap(side)
  20.  
  21. function main()
  22.     while true do
  23.         count = 1
  24.         for i, v in ipairs(chests.getNamesRemote()) do
  25.             if string.match(v, chest_baseName) then
  26.                 obj = chests.callRemote(v, chest)
  27.                 items = {}
  28.                 for k, item in ipairs(obj) do
  29.                     tmp_name = item.name.."_"..item.damage
  30.                     if items[item.name] then
  31.                         items[tmp_name] = items[tmp_name] + item.count
  32.                     else
  33.                         items[tmp_name] = item.count
  34.                     end
  35.                 end
  36.                 for k, item in pairs(items) do
  37.                     table = {title=site_name, name_chest='chest'..count, APIName=k, quantity=item}
  38.                     data = textutils.serializeJSON(table)
  39.                     http.post(inventory_set, data, headers)
  40.                 end
  41.                 count = count + 1
  42.             end
  43.         end
  44.         os.sleep(between_requests)
  45.     end
  46. end
  47.  
  48. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement