node-minecraft-protocol/examples/server_custom_channel/server_custom_channel.js
extremeheat 112926da0c
Pc1.20.2 (#1265)
* Initial changes for 1.20.2

* add NBT serialize tag type handling

* update tests

* Update pnbt and mcdata for nbt change

* lint

* fix wrong param to sizeOfNbt

* fix dupe NBT types

* move nbt logic to prismarine-nbt

* update tests

* update tests

* disable protodef validator in pluginChannel

* Fix state desync

* dump loginPacket.json in test output

* enable validation

* remove testing line in ci.yml

* update pnbt to 2.5.0

* update doc for `playerJoin`

* Update serializer.js

* update examples

* lint

* disable client bundle handling if bundle becomes too big

* Update client.js

* bump mcdata

* add soundSource and packedChunkPos example test values

---------

Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
2023-12-28 00:48:10 +01:00

39 lines
1.1 KiB
JavaScript

const mc = require('minecraft-protocol')
const server = mc.createServer({
'online-mode': false, // optional
encryption: false, // optional
version: '1.18.2'
})
const mcData = require('minecraft-data')(server.version)
const loginPacket = mcData.loginPacket
server.on('playerJoin', function (client) {
client.write('login', {
...loginPacket,
entityId: client.id,
isHardcore: false,
gameMode: 0,
previousGameMode: 1,
worldName: 'minecraft:overworld',
hashedSeed: [0, 0],
maxPlayers: server.maxPlayers,
viewDistance: 10,
reducedDebugInfo: false,
enableRespawnScreen: true,
isDebug: false,
isFlat: false
})
client.registerChannel('node-minecraft-protocol:custom_channel_one', ['string', []], true)
client.registerChannel('node-minecraft-protocol:custom_channel_two', ['string', []], true)
client.write('position', {
x: 0,
y: 1.62,
z: 0,
yaw: 0,
pitch: 0,
flags: 0x00
})
client.writeChannel('node-minecraft-protocol:custom_channel_two', 'hello from the server')
client.on('node-minecraft-protocol:custom_channel_one', console.log)
})