Solved Serializing a nbt tag.

Discussion in 'Plugin Development' started by Lightspeed, Jan 25, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Lightspeed

    I have a system to loop thru blocks in an area and create a new LyghtBlock object which stores a type id the data and nbt(Well suposed to).
    I need a way to serialize this nbt tag. . . I've seen NBTCompressedStreamTools but, don't know how I'd use it to serialze a nbt tag for each block.
     
  2. Offline

    mythbusterma

    @Lightspeed

    Why do you need to serialise this data?
     
  3. Offline

    Lightspeed

    For a schematic like system.
     
  4. Offline

    mythbusterma

    @Lightspeed

    You could use the actual schematics. They work pretty well.
     
  5. Offline

    Lightspeed

    @mythbusterma I would like to use my own code.

    EDIT: Do I have to use a lib?
     
  6. Offline

    mythbusterma

    @Lightspeed

    It's just that writing your own code for schematics is incredibly difficult. I would recommend using someone else's code to do it.

    You don't have to, but I certainly would.
     
  7. Offline

    Lightspeed

    @mythbusterma I already got the code for schematics I just need to be able to serialize nbt data.
     
  8. Offline

    Lightspeed

    Welp I found this one out too so here you go.
    Code:
    //Converting it to a byte array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    NBTCompressedStreamTools.a(ntc, baos);
    baos.toByteArray(); //This is what you want!
    
    //Convert back to nbt!
    ByteArrayInputStream bais = new ByteArrayInputStream(ByteArrayHere);
    NBTTagCompound nbt= NBTCompressedStreamTools.a(bais);
    Just save the converted byte array into a file change location if needed and use it(My system copies entities from one location to another so thats why you might need to change locations a bit)!
     
Thread Status:
Not open for further replies.

Share This Page