Advertisement
MagmaLP

Logistic entleerung

Oct 31st, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- CONSTANTS
  2. local INTERVAL = 120
  3. local PIPE_SIDE = "bottom"
  4. local REQUEST_IDS = {
  5.  
  6. --Swords      
  7. 267,   --Iron
  8. 268,   --Wood
  9. 272,   --Stone
  10. 276,   --Diamond
  11. 283,   --Gold
  12. 4369,  --Quarz
  13. 5648,  --Green Sapphire
  14. 5649,  --Ruby
  15. 5650,  --Blue Sapphire
  16. 30198, --Bronze
  17.  
  18. }
  19. -- IMPLEMENTATION
  20. function convertNBT(nbt)
  21.     local conv = {}
  22.     if (nbt == nil) then
  23.         return nil
  24.     elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  25.         for key, value in pairs(nbt["value"]) do
  26.             conv[key] = convertNBT(value)
  27.         end
  28.     else
  29.         conv = nbt["value"]
  30.     end
  31.     return conv
  32. end
  33.  
  34. function getItems(pipe)
  35.     pipe.getAvailableItems()
  36.     local event, result = os.pullEvent("available_items_return")
  37.     return result
  38. end
  39.  
  40. function inList(item)
  41.     for _, id in pairs(REQUEST_IDS) do
  42.         if item.id == id then
  43.             return true
  44.         end
  45.     end
  46.     return false
  47. end
  48.  
  49.  
  50. -- MAIN
  51. local pipe = peripheral.wrap(PIPE_SIDE)
  52. while true do
  53.     for i, result in pairs(getItems(pipe)) do
  54.         local iid, amount = unpack(result)
  55.         local item = {
  56.             id = pipe.getItemID(iid),
  57.             dmg = pipe.getItemDamage(iid),
  58.             nbt = convertNBT(pipe.getNBTTagCompound(iid))
  59.         }
  60.         if inList(item) then
  61.             pipe.makeRequest(iid, amount)
  62.             sleep(2)
  63.         end
  64.     end
  65.     sleep(INTERVAL)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement