MagmaLP

Mobfarm Sortier-PC oben

Oct 31st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- CONSTANTS
  2. local INTERVAL = 100
  3. local PIPE_SIDE = "top"
  4. local REQUEST_IDS = {
  5.  
  6. --Sword
  7. 283,
  8.  
  9. }
  10. -- IMPLEMENTATION
  11. function convertNBT(nbt)
  12.     local conv = {}
  13.     if (nbt == nil) then
  14.         return nil
  15.     elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  16.         for key, value in pairs(nbt["value"]) do
  17.             conv[key] = convertNBT(value)
  18.         end
  19.     else
  20.         conv = nbt["value"]
  21.     end
  22.     return conv
  23. end
  24.  
  25. function getItems(pipe)
  26.     pipe.getAvailableItems()
  27.     local event, result = os.pullEvent("available_items_return")
  28.     return result
  29. end
  30.  
  31. function inList(item)
  32.     for _, id in pairs(REQUEST_IDS) do
  33.         if item.id == id then
  34.             return true
  35.         end
  36.     end
  37.     return false
  38. end
  39.  
  40.  
  41. -- MAIN
  42. local pipe = peripheral.wrap(PIPE_SIDE)
  43. while true do
  44.     for i, result in pairs(getItems(pipe)) do
  45.         local iid, amount = unpack(result)
  46.         local item = {
  47.             id = pipe.getItemID(iid),
  48.             dmg = pipe.getItemDamage(iid),
  49.             nbt = convertNBT(pipe.getNBTTagCompound(iid))
  50.         }
  51.         if inList(item) then
  52.             pipe.makeRequest(iid, amount)
  53.             sleep(2)
  54.         end
  55.     end
  56.     sleep(INTERVAL)
  57. end
Add Comment
Please, Sign In to add comment