mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-19 03:52:34 -05:00
1d9a38253a
* Inital 1.20.3 update, bring in minecraft-data with 1.20.3 support and add it to the versions * Add data for packetTest for explosion packet. * Add 1.20.4 to version list. * Add fix for 1.20.3+ NBT isntead of strings for chat. Not happy with this but it does work. * Fix linting * Update version.js Remove 1.20.3 since its the same as 1.20.4. (As suggested) * Comment how handleNBTStrings works. * Removed debug console.log * Update README.md * chat packet nbt handling fix, use feature * big endian UUID, add back `text` wrapper * use prismarine-chat in client test * expose _handleNbtComponent * use prismarine-chat exposed processNbtMessage * fix pre-1.20.4 * Update package.json * Update server.js * Update server.js add missing import * update server hello world --------- Co-authored-by: Romain Beaumont <romain.rom1@gmail.com> Co-authored-by: extremeheat <extreme@protonmail.ch>
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const Registry = require('prismarine-registry')
|
|
module.exports = client => {
|
|
client.nextMessage = (containing) => {
|
|
return new Promise((resolve) => {
|
|
function onChat (packet) {
|
|
const m = packet.formattedMessage || packet.unsignedChatContent || JSON.stringify({ text: packet.plainMessage })
|
|
if (containing) {
|
|
if (m.includes(containing)) return finish(m)
|
|
else return
|
|
}
|
|
return finish(m)
|
|
}
|
|
client.on('playerChat', onChat)
|
|
client.on('systemChat', onChat) // For 1.7.10
|
|
|
|
function finish (m) {
|
|
client.off('playerChat', onChat)
|
|
client.off('systemChat', onChat)
|
|
resolve(m)
|
|
}
|
|
})
|
|
}
|
|
|
|
client.on('login', (packet) => {
|
|
client.registry ??= Registry(client.version)
|
|
if (packet.dimensionCodec) {
|
|
client.registry.loadDimensionCodec(packet.dimensionCodec)
|
|
}
|
|
})
|
|
client.on('registry_data', (data) => {
|
|
client.registry ??= Registry(client.version)
|
|
client.registry.loadDimensionCodec(data.codec)
|
|
})
|
|
|
|
client.on('playerJoin', () => {
|
|
const ChatMessage = require('prismarine-chat')(client.registry || client.version)
|
|
client.parseMessage = (comp) => {
|
|
return new ChatMessage(comp)
|
|
}
|
|
})
|
|
|
|
return client
|
|
}
|