Add compiler example (#841)

* Initial commit

* require minecraft-data

* use buffer.compare instead of ===

* use .equals

* Fix flipped serializer
This commit is contained in:
u9g 2021-04-06 16:44:17 -04:00 committed by GitHub
parent bfb1472e7e
commit 294e20b54a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,20 @@
const { createSerializer, createDeserializer, states } = require('minecraft-protocol')
const mcPackets = require('minecraft-packets')
const serializer = createSerializer({ state: states.PLAY, version: '1.16.5', isServer: true })
const deserializer = createDeserializer({ state: states.PLAY, version: '1.16.5' })
function convertBufferToObject (buffer) {
return deserializer.parsePacketBuffer(buffer)
}
function convertObjectToBuffer (object) {
return serializer.createPacketBuffer(object)
}
const buffer = mcPackets.pc['1.16.5']['from-server'].abilities[0].raw
const parsed = convertBufferToObject(buffer).data
const parsedBuffer = convertObjectToBuffer(parsed)
console.log(buffer)
console.log(parsedBuffer)
console.log(buffer.equals(parsedBuffer))

View file

@ -0,0 +1,10 @@
{
"name": "node-minecraft-protocol-example",
"version": "0.0.0",
"private": true,
"dependencies": {
"minecraft-packets": "^1.1.5"
},
"description": "A node-minecraft-protocol example"
}