mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-19 03:52:34 -05:00
9b029e8b6f
* 1.20.5 * update examples * Update for 1.20.5 chat_command_signed with seperateSignedChatCommandPacket feature * updates * update java * re-enable packet tests * Update client.js add debug code after decompress * Update client.js * Update ci.yml * Add `arrayWithLengthOffset` type to interpeter * Update minecraft.js * Update compiler-minecraft.js * Update minecraft.js * lint * remote custom ci install * Update package.json * Update packetTest.js add Slot, SlotComponent * Update packetTest.js * Update packetTest.js * Fix lint. * Fix declare_recipes, Slot * Update package.json --------- Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
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 || data)
|
|
})
|
|
|
|
client.on('playerJoin', () => {
|
|
const ChatMessage = require('prismarine-chat')(client.registry || client.version)
|
|
client.parseMessage = (comp) => {
|
|
return new ChatMessage(comp)
|
|
}
|
|
})
|
|
|
|
return client
|
|
}
|