Ahlforn

item

Jun 17th, 2021
501
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data