mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-30 11:07:08 -05:00
Fix position andslot
This commit is contained in:
parent
e37a820709
commit
77f702e9cb
1 changed files with 6 additions and 12 deletions
|
@ -1090,8 +1090,8 @@ 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);
|
||||
var z = longVal[1] << 6 >> 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
|
||||
|
@ -1131,7 +1131,7 @@ function readSlot(buffer, offset) {
|
|||
}
|
||||
|
||||
function sizeOfSlot(value) {
|
||||
if (value.id === -1)
|
||||
if (value.blockId === -1)
|
||||
return (2);
|
||||
else if (!value.nbtData) {
|
||||
return (6);
|
||||
|
@ -1142,14 +1142,14 @@ function sizeOfSlot(value) {
|
|||
|
||||
function writePosition(value, buffer, offset) {
|
||||
var longVal = [];
|
||||
longVal[0] = ((value.x & 0x3FFFFFF) << 6) | ((value.y & 0xFC0) >> 6);
|
||||
longVal[0] = ((value.x & 0x3FFFFFF) << 6) | ((value.y & 0xFFF) >> 6);
|
||||
longVal[1] = ((value.y & 0x3F) << 26) | (value.z & 0x3FFFFFF);
|
||||
return writeLong(longVal, buffer, offset);
|
||||
}
|
||||
|
||||
function writeSlot(value, buffer, offset) {
|
||||
buffer.writeInt16BE(value.id, offset);
|
||||
if (value.id === -1) return offset + 2;
|
||||
buffer.writeInt16BE(value.blockId, offset);
|
||||
if (value.blockId === -1) return offset + 2;
|
||||
buffer.writeInt8(value.itemCount, offset + 2);
|
||||
buffer.writeInt16BE(value.itemDamage, offset + 3);
|
||||
var nbtDataLen;
|
||||
|
@ -1409,13 +1409,7 @@ function read(buffer, cursor, fieldInfo, rootNodes) {
|
|||
error: new Error("missing data type: " + fieldInfo.type)
|
||||
};
|
||||
}
|
||||
try {
|
||||
var readResults = type[0](buffer, cursor, fieldInfo.typeArgs, rootNodes);
|
||||
} catch (e) {
|
||||
console.log("fieldInfo : " + JSON.stringify(fieldInfo));
|
||||
console.log("rootNodes : " + JSON.stringify(rootNodes));
|
||||
throw e;
|
||||
}
|
||||
if (readResults == null) {
|
||||
throw new Error("Reader returned null : " + JSON.stringify(fieldInfo));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue