2018-05-13 16:50:16 -04:00
|
|
|
const mc = require('minecraft-protocol')
|
2016-08-10 13:27:50 -04:00
|
|
|
|
2017-07-13 08:03:52 -04:00
|
|
|
const server = mc.createServer({
|
2018-05-13 16:50:16 -04:00
|
|
|
'online-mode': false, // optional
|
|
|
|
encryption: false, // optional
|
2023-05-20 08:44:03 -04:00
|
|
|
version: '1.18.2'
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|
2020-10-06 16:46:53 -04:00
|
|
|
const mcData = require('minecraft-data')(server.version)
|
|
|
|
const loginPacket = mcData.loginPacket
|
2016-08-10 13:27:50 -04:00
|
|
|
|
2023-12-27 18:48:10 -05:00
|
|
|
server.on('playerJoin', function (client) {
|
2016-08-10 13:27:50 -04:00
|
|
|
client.write('login', {
|
2023-12-27 18:48:10 -05:00
|
|
|
...loginPacket,
|
2024-10-12 17:55:36 -04:00
|
|
|
enforceSecureChat: false,
|
2016-08-10 13:27:50 -04:00
|
|
|
entityId: client.id,
|
2020-10-06 16:46:53 -04:00
|
|
|
isHardcore: false,
|
2016-08-10 13:27:50 -04:00
|
|
|
gameMode: 0,
|
2021-09-03 12:52:47 -04:00
|
|
|
previousGameMode: 1,
|
2020-06-23 10:52:18 -04:00
|
|
|
worldName: 'minecraft:overworld',
|
2020-10-06 16:46:53 -04:00
|
|
|
hashedSeed: [0, 0],
|
2016-08-10 13:27:50 -04:00
|
|
|
maxPlayers: server.maxPlayers,
|
2020-10-06 16:46:53 -04:00
|
|
|
viewDistance: 10,
|
2019-12-29 17:27:04 -05:00
|
|
|
reducedDebugInfo: false,
|
|
|
|
enableRespawnScreen: true,
|
2020-10-06 16:46:53 -04:00
|
|
|
isDebug: false,
|
|
|
|
isFlat: false
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|
2023-05-20 08:44:03 -04:00
|
|
|
client.registerChannel('node-minecraft-protocol:custom_channel_one', ['string', []], true)
|
|
|
|
client.registerChannel('node-minecraft-protocol:custom_channel_two', ['string', []], true)
|
2016-08-10 13:27:50 -04:00
|
|
|
client.write('position', {
|
|
|
|
x: 0,
|
|
|
|
y: 1.62,
|
|
|
|
z: 0,
|
|
|
|
yaw: 0,
|
|
|
|
pitch: 0,
|
|
|
|
flags: 0x00
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|
2023-05-20 08:44:03 -04:00
|
|
|
client.writeChannel('node-minecraft-protocol:custom_channel_two', 'hello from the server')
|
|
|
|
client.on('node-minecraft-protocol:custom_channel_one', console.log)
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|