mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 21:52:17 -04:00
Change to compressedNbt, and add zlib gunzip decompression
This commit is contained in:
parent
a929294177
commit
b25ac14a13
@ -1,11 +1,12 @@
|
|||||||
const nbt = require('prismarine-nbt');
|
const nbt = require('prismarine-nbt');
|
||||||
const UUID = require('uuid-1345');
|
const UUID = require('uuid-1345');
|
||||||
|
const zlib = require('zlib');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'UUID': [readUUID, writeUUID, 16],
|
'UUID': [readUUID, writeUUID, 16],
|
||||||
'nbt': [readNbt, writeNbt, sizeOfNbt],
|
'nbt': [readNbt, writeNbt, sizeOfNbt],
|
||||||
'optionalNbt':[readOptionalNbt,writeOptionalNbt,sizeOfOptionalNbt],
|
'optionalNbt':[readOptionalNbt,writeOptionalNbt,sizeOfOptionalNbt],
|
||||||
'optionalLengthPrefixedNbt':[readOptionalLengthPrefixedNbt,writeOptionalLengthPrefixedNbt,sizeOfOptionalLengthPrefixedNbt],
|
'compressedNbt':[readCompressedNbt,writeCompressedNbt,sizeOfCompressedNbt],
|
||||||
'restBuffer': [readRestBuffer, writeRestBuffer, sizeOfRestBuffer],
|
'restBuffer': [readRestBuffer, writeRestBuffer, sizeOfRestBuffer],
|
||||||
'entityMetadataLoop': [readEntityMetadata, writeEntityMetadata, sizeOfEntityMetadata]
|
'entityMetadataLoop': [readEntityMetadata, writeEntityMetadata, sizeOfEntityMetadata]
|
||||||
};
|
};
|
||||||
@ -55,13 +56,19 @@ function sizeOfOptionalNbt(value) {
|
|||||||
return nbt.proto.sizeOf(value,"nbt");
|
return nbt.proto.sizeOf(value,"nbt");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length-prefixed optional NBT, short instead of null byte: http://wiki.vg/index.php?title=Slot_Data&diff=6056&oldid=4753
|
// Length-prefixed compressed NBT, see differences: http://wiki.vg/index.php?title=Slot_Data&diff=6056&oldid=4753
|
||||||
function readOptionalLengthPrefixedNbt(buffer, offset) {
|
function readCompressedNbt(buffer, offset) {
|
||||||
if(buffer.readInt16BE(offset) == -1) return {size:2};
|
const length = buffer.readInt16BE(offset);
|
||||||
return nbt.proto.read(buffer,offset+2,"nbt");
|
if(length == -1) return {size:2};
|
||||||
|
|
||||||
|
const compressedNbt = buffer.slice(offset+2, offset+2+length);
|
||||||
|
|
||||||
|
const nbtBuffer = zlib.gunzipSync(compressedNbt); // TODO: async
|
||||||
|
|
||||||
|
return nbt.proto.read(nbtBuffer,0,"nbt");
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeOptionalLengthPrefixedNbt(value, buffer, offset) {
|
function writeCompressedNbt(value, buffer, offset) {
|
||||||
if(value==undefined) {
|
if(value==undefined) {
|
||||||
buffer.writeInt16BE(-1,offset);
|
buffer.writeInt16BE(-1,offset);
|
||||||
return offset+2;
|
return offset+2;
|
||||||
@ -70,7 +77,7 @@ function writeOptionalLengthPrefixedNbt(value, buffer, offset) {
|
|||||||
return nbt.proto.write(value,buffer,offset+2,"nbt");
|
return nbt.proto.write(value,buffer,offset+2,"nbt");
|
||||||
}
|
}
|
||||||
|
|
||||||
function sizeOfOptionalLengthPrefixedNbt(value) {
|
function sizeOfCompressedNbt(value) {
|
||||||
if(value==undefined)
|
if(value==undefined)
|
||||||
return 2;
|
return 2;
|
||||||
return 2+nbt.proto.sizeOf(value,"nbt");
|
return 2+nbt.proto.sizeOf(value,"nbt");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user