Fix position andslot

This commit is contained in:
roblabla 2015-03-03 12:36:26 +00:00
parent e37a820709
commit 77f702e9cb

View file

@ -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));
}