SHARE
TWEET

API_chests

dreais Jun 29th, 2020 (edited) 894 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. chests_baseName =   {"minecraft:ironchest_", "yabba:item_barrel_"}
  9. chest_baseName  =   "minecraft:ironchest_" --finishes with id
  10. between_requests=   30 -- waiting 30 seconds to update
  11. -- DON'T MODIFY THOSE UNLESS YOU'RE SURE OF YOURSELF
  12. -- URLs
  13. base            =   "https://mc-api.rudreais.com"
  14. api             =   base.."/api/v1"
  15. inventory_api   =   api.."/inventory"
  16. inventory_del   =   inventory_api.."/drop/"..site_name
  17. inventory_set   =   inventory_api.."/set/"..site_name
  18. headers = {
  19.     ["Content-Type"] = "application/json"
  20. }
  21. chests = peripheral.wrap(side)
  22.  
  23. function main()
  24.     while true do
  25.         count = 1
  26.         for i, v in ipairs(chests.getNamesRemote()) do
  27.             for c, type in ipairs(chests_baseName) do
  28.                 if string.match(v, type) then
  29.                     print("Found "..type)
  30.                     obj = chests.callRemote(v, chest)
  31.                     table = {title=site_name, name_chest='chest'..count}
  32.                     data = textutils.serializeJSON(table)
  33.                     url_drop = inventory_del.."/".."chest"..count
  34.                     http.post(url_drop, data, headers)
  35.                     items = {}
  36.                     for k, item in pairs(obj) do
  37.                         tmp_name = item.name.."_"..item.damage
  38.                         if items[item.name] then
  39.                             items[tmp_name] = items[tmp_name] + item.count
  40.                         else
  41.                             items[tmp_name] = item.count
  42.                         end
  43.                     end
  44.                     for k, item in pairs(items) do
  45.                         table = {title=site_name, name_chest='chest'..count, APIName=k, quantity=item}
  46.                         data = textutils.serializeJSON(table)
  47.                         http.post(inventory_set, data, headers)
  48.                     end
  49.                     count = count + 1
  50.                     print(obj)
  51.                 end
  52.             end
  53.         end
  54.         os.sleep(between_requests)
  55.     end
  56. end
  57.  
  58. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top