mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Added byte array serialization/deserialization for PersistentDataContainers
This commit is contained in:
parent
b24b187864
commit
476de68a14
@ -184,4 +184,27 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
this.customDataTags.clear();
|
||||
}
|
||||
// Paper end
|
||||
|
||||
// Paper start - byte array serialization
|
||||
@Override
|
||||
public byte[] serializeToBytes() throws java.io.IOException {
|
||||
final net.minecraft.nbt.CompoundTag root = this.toTagCompound();
|
||||
final java.io.ByteArrayOutputStream byteArrayOutput = new java.io.ByteArrayOutputStream();
|
||||
try (final java.io.DataOutputStream dataOutput = new java.io.DataOutputStream(byteArrayOutput)) {
|
||||
net.minecraft.nbt.NbtIo.write(root, dataOutput);
|
||||
return byteArrayOutput.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromBytes(final byte[] bytes, final boolean clear) throws java.io.IOException {
|
||||
if (clear) {
|
||||
this.clear();
|
||||
}
|
||||
try (final java.io.DataInputStream dataInput = new java.io.DataInputStream(new java.io.ByteArrayInputStream(bytes))) {
|
||||
final net.minecraft.nbt.CompoundTag compound = net.minecraft.nbt.NbtIo.read(dataInput);
|
||||
this.putAll(compound);
|
||||
}
|
||||
}
|
||||
// Paper end - byte array serialization
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user