Advertisement
Ahlforn

item

Jun 17th, 2021
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. local deflate = require "deflate"
  2. local nbt = require "nbt"
  3. local item = {}
  4.  
  5. function item.hasTag(itemstack)
  6.     return itemstack.hasTag
  7. end
  8.  
  9. function item.readTagRaw(itemstack)
  10.     if not item.hasTag(itemstack) then
  11.         error("Item has no NBT tag")
  12.     end
  13.     local out = {}
  14.     deflate.gunzip({input = itemstack.tag,
  15.         output = function(byte)out[#out+1]=string.char(byte)end})
  16.    
  17.     return out
  18. end
  19.  
  20. function item.readTag(itemstack)
  21.     return nbt.readFromNBT(item.readTagRaw(itemstack))
  22. end
  23.  
  24. return item
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement