Advertisement
systox

new nbt reader

Oct 18th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. output = {}
  2.  
  3. function convertNBT(nbt)
  4.     local conv = {}
  5.     if (nbt == nil) then
  6.         return nil
  7.     elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  8.         for key, value in pairs(nbt["value"]) do
  9.             conv[key] = convertNBT(value)
  10.         end
  11.     else
  12.         conv = nbt["value"]
  13.     end
  14.     return conv
  15. end
  16.  
  17.  
  18. function getNBT(side)
  19.     local pipe = peripheral.wrap(side)
  20.     pipe.getAvailableItems()
  21.     local event, items = os.pullEvent("available_items_return")
  22.     for k,v in pairs(items) do
  23.         iid = v
  24.         nbt = convertNBT(pipe.getNBTTagCompound(iid))
  25.         id = pipe.getItemID(iid)
  26.         dmg = pipe.getItemDamage(iid)
  27.         pkg = {}
  28.         table.insert(pkg,id)
  29.         table.insert(pkg,dmg)
  30.         table.insert(pkg,nbt)
  31.        
  32.         table.insert(output,pkg)
  33.         print("found item "..id..":"..dmg)
  34.     end
  35.     return output
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement