mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-06-29 14:30:22 -04:00
add writers for most data types
This commit is contained in:
parent
10cb3e0100
commit
817fb9b51e
2 changed files with 175 additions and 39 deletions
lib
148
lib/protocol.js
148
lib/protocol.js
|
@ -452,18 +452,146 @@ var types = {
|
|||
'slot': [readSlot, SlotWriter],
|
||||
'long': [readLong, LongWriter],
|
||||
'ascii': [readAscii, AsciiWriter],
|
||||
|
||||
'byteArray32': [readByteArray32],
|
||||
'slotArray': [readSlotArray],
|
||||
'mapChunkBulk': [readMapChunkBulk],
|
||||
'entityMetadata': [readEntityMetadata],
|
||||
'objectData': [readObjectData],
|
||||
'intArray8': [readIntArray8],
|
||||
'intVector': [readIntVector],
|
||||
'byteVector': [readByteVector],
|
||||
'byteVectorArray': [readByteVectorArray],
|
||||
'entityMetadata': [readEntityMetadata, EntityMetadataWriter],
|
||||
'byteArray32': [readByteArray32, ByteArray32Writer],
|
||||
'slotArray': [readSlotArray, SlotArrayWriter],
|
||||
'mapChunkBulk': [readMapChunkBulk, MapChunkBulkWriter],
|
||||
'objectData': [readObjectData, ObjectDataWriter],
|
||||
'intArray8': [readIntArray8, IntArray8Writer],
|
||||
'intVector': [readIntVector, IntVectorWriter],
|
||||
'byteVector': [readByteVector, ByteVectorWriter],
|
||||
'byteVectorArray': [readByteVectorArray, ByteVectorArrayWriter],
|
||||
};
|
||||
|
||||
function ByteArray32Writer(value) {
|
||||
this.value = value;
|
||||
this.size = 4 + value.length;
|
||||
}
|
||||
|
||||
ByteArray32Writer.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt32BE(this.value.length, offset);
|
||||
this.value.copy(buffer, offset + 4);
|
||||
}
|
||||
|
||||
function SlotArrayWriter(value) {
|
||||
this.value = new Array(value.length)
|
||||
this.size = 2;
|
||||
var slotWriter;
|
||||
for (var i = 0; i < value.length; ++i) {
|
||||
this.value[i] = slotWriter = new SlotWriter(value[i]);
|
||||
this.size += slotWriter.size;
|
||||
}
|
||||
}
|
||||
|
||||
SlotArrayWriter.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt16BE(this.value.length, offset);
|
||||
offset += 2;
|
||||
this.value.forEach(function(slotWriter) {
|
||||
slotWriter.write(buffer, offset);
|
||||
offset += slotWriter.size;
|
||||
});
|
||||
}
|
||||
|
||||
function EntityMetadataWriter(value) {
|
||||
}
|
||||
|
||||
EntityMetadataWriter.prototype.write = function() {
|
||||
|
||||
}
|
||||
|
||||
function MapChunkBulkWriter(value) {
|
||||
this.value = value;
|
||||
this.size = 7 + value.compressedChunkData.length + 12 * value.meta.length;
|
||||
}
|
||||
|
||||
MapChunkBulkWriter.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt16BE(this.value.meta.length, offset);
|
||||
offset += 2;
|
||||
buffer.writeInt32BE(this.value.compressedChunkData.length, offset);
|
||||
offset += 4;
|
||||
buffer.writeInt8(+this.value.skyLightSent, offset);
|
||||
offset += 1;
|
||||
|
||||
this.value.compressedChunkData.copy(buffer, offset);
|
||||
offset += this.value.compressedChunkData.length;
|
||||
|
||||
var meta;
|
||||
for (var i = 0; i < this.value.meta.length; ++i) {
|
||||
meta = this.value.meta[i];
|
||||
buffer.writeInt32BE(meta.x, offset);
|
||||
offset += 4;
|
||||
buffer.writeInt32BE(meta.z, offset);
|
||||
offset += 4;
|
||||
buffer.writeUInt16BE(meta.bitMap, offset);
|
||||
offset += 2;
|
||||
buffer.writeUInt16BE(meta.addBitMap, offset);
|
||||
offset += 2;
|
||||
}
|
||||
}
|
||||
|
||||
function ObjectDataWriter(value) {
|
||||
|
||||
}
|
||||
|
||||
ObjectDataWriter.prototype.write = function() {
|
||||
|
||||
}
|
||||
|
||||
function IntArray8Writer(value) {
|
||||
this.value = value;
|
||||
this.size = 1 + 4 * value.length;
|
||||
}
|
||||
|
||||
IntArray8Writer.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt8(this.value.length, offset);
|
||||
offset += 1;
|
||||
|
||||
this.value.forEach(function(item) {
|
||||
buffer.writeInt32BE(item, offset);
|
||||
offset += 4;
|
||||
});
|
||||
}
|
||||
|
||||
function IntVectorWriter(value) {
|
||||
this.value = value;
|
||||
this.size = 12;
|
||||
}
|
||||
|
||||
IntVectorWriter.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt32BE(this.value.x, offset);
|
||||
buffer.writeInt32BE(this.value.y, offset + 4);
|
||||
buffer.writeInt32BE(this.value.z, offset + 8);
|
||||
}
|
||||
|
||||
function ByteVectorWriter(value) {
|
||||
this.value = value;
|
||||
this.size = 3;
|
||||
}
|
||||
|
||||
ByteVectorWriter.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt8(this.value.x, offset);
|
||||
buffer.writeInt8(this.value.y, offset + 1);
|
||||
buffer.writeInt8(this.value.z, offset + 2);
|
||||
}
|
||||
|
||||
function ByteVectorArrayWriter(value) {
|
||||
this.value = value;
|
||||
this.size = 4 + 3 * value.length;
|
||||
}
|
||||
|
||||
ByteVectorArrayWriter.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt32BE(this.value.length, offset);
|
||||
offset += 4;
|
||||
this.value.forEach(function(vec) {
|
||||
buffer.writeInt8(vec.x, offset);
|
||||
offset += 1;
|
||||
buffer.writeInt8(vec.y, offset);
|
||||
offset += 1;
|
||||
buffer.writeInt8(vec.z, offset);
|
||||
offset += 1;
|
||||
});
|
||||
}
|
||||
|
||||
var entityMetadataReaders = {
|
||||
0: readByte,
|
||||
1: readShort,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue