From b860063e3654b249d632d6976181a0bb1a48224b Mon Sep 17 00:00:00 2001 From: Keegan Date: Sun, 6 Mar 2016 11:11:14 -0500 Subject: [PATCH] added nbt --- data/protocol.json | 2 +- package.json | 1 + src/datatypes.js | 24 +++++++++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/data/protocol.json b/data/protocol.json index 9e964a2..bce8fb7 100644 --- a/data/protocol.json +++ b/data/protocol.json @@ -35,7 +35,7 @@ }, { "name": "nbtData", - "type": "optionalNbt" + "type": "nbt" } ] ] diff --git a/package.json b/package.json index 35f2902..897b7fe 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ ], "license": "MIT", "dependencies": { + "prismarine-nbt": "^0.2.1", "protodef": "^1.1.2", "raknet": "^1.1.0" }, diff --git a/src/datatypes.js b/src/datatypes.js index 561013d..39f7b1f 100644 --- a/src/datatypes.js +++ b/src/datatypes.js @@ -1,3 +1,5 @@ +var nbt = require('prismarine-nbt'); + function readUUID(buffer, offset) { if(offset+16>buffer.length) throw new PartialReadError(); @@ -13,15 +15,19 @@ function writeUUID(value, buffer, offset) { return offset + 16; } +function readNbt(buffer, offset) { + return nbt.proto.read(buffer,offset,"nbt"); +} + +function writeNbt(value, buffer, offset) { + return nbt.proto.write(value,buffer,offset,"nbt"); +} + +function sizeOfNbt(value) { + return nbt.proto.sizeOf(value,"nbt"); +} + module.exports = { 'uuid': [readUUID, writeUUID, 16], - - 'metadatadictionary': [readLTriad, writeLTriad, 3], - 'skin': [readIpAddress, writeIpAddress, 4], - 'entitylocations': [readRestBuffer, writeRestBuffer, sizeOfRestBuffer], - 'blockrecords':[readEndOfArray,writeEndOfArray,sizeOfEndOfArray], - 'records':[readToByte,writeToByte,sizeOfToByte], - 'playerattributes': [], - 'item': [], - 'blockcoordinates': [] + 'nbt': [readNbt, writeNbt, sizeOfNbt] };