From 456331b952f4e0d60eef8f5b36c69dcfbb71ae2c Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 25 Mar 2015 04:09:36 +0100 Subject: [PATCH 1/2] fix readPosition (see http://wiki.vg/index.php?title=Data_Types&diff=6529&oldid=6491) thanks Fenhl --- src/protocol.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index 48c2c0c..5d14349 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -1095,14 +1095,17 @@ function readBool(buffer, offset) { } function readPosition(buffer, offset) { - var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... - var x = longVal[0] >> 6; - var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); - var z = longVal[1] & 0x3FFFFFF; - return { - value: { x: x, y: y, z: z }, - size: 8 - }; + var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... + var x = longVal[0] >> 6; + if(x>33554432) x-=67108864; + var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); + if(y>2048) y-=4096; + var z = longVal[1] & 0x3FFFFFF; + if(z>33554432) z-=67108864; + return { + value: { x: x, y: y, z: z }, + size: 8 + }; } function readSlot(buffer, offset) { From 88b8653b4d6354b543b9b3ab00356b3c28b00736 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 25 Mar 2015 04:12:58 +0100 Subject: [PATCH 2/2] fix indentation --- src/protocol.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index 5d14349..2729ecc 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -1095,17 +1095,17 @@ function readBool(buffer, offset) { } function readPosition(buffer, offset) { - var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... - var x = longVal[0] >> 6; - if(x>33554432) x-=67108864; - var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); - if(y>2048) y-=4096; - var z = longVal[1] & 0x3FFFFFF; - if(z>33554432) z-=67108864; - return { - value: { x: x, y: y, z: z }, - size: 8 - }; + var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... + var x = longVal[0] >> 6; + if(x>33554432) x-=67108864; + var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); + if(y>2048) y-=4096; + var z = longVal[1] & 0x3FFFFFF; + if(z>33554432) z-=67108864; + return { + value: { x: x, y: y, z: z }, + size: 8 + }; } function readSlot(buffer, offset) {