Add createClient (#61)
* Initial commit * remove comment * export obj * fix export * add to api.md * fix old refs to nmp
This commit is contained in:
parent
0bf6b8bded
commit
d8ff48258c
4 changed files with 72 additions and 1 deletions
45
src/createClient.js
Normal file
45
src/createClient.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
const { Client } = require('./client')
|
||||
const assert = require('assert')
|
||||
|
||||
module.exports = { createClient }
|
||||
|
||||
/** @param {{ version?: number, hostname: string, port?: number }} options */
|
||||
function createClient (options) {
|
||||
assert(options && options.hostname)
|
||||
const client = new Client({ port: 19132, ...options })
|
||||
|
||||
client.once('resource_packs_info', (packet) => {
|
||||
handleResourcePackInfo(client)
|
||||
disableClientCache(client)
|
||||
handleRenderDistance(client)
|
||||
handleTickSync(client)
|
||||
})
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
function handleResourcePackInfo (client) {
|
||||
client.write('resource_pack_client_response', {
|
||||
response_status: 'completed',
|
||||
resourcepackids: []
|
||||
})
|
||||
|
||||
client.once('resource_pack_stack', (stack) => {
|
||||
client.write('resource_pack_client_response', {
|
||||
response_status: 'completed',
|
||||
resourcepackids: []
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function handleRenderDistance (client) {
|
||||
client.queue('request_chunk_radius', { chunk_radius: 1 })
|
||||
}
|
||||
|
||||
function disableClientCache (client) {
|
||||
client.queue('client_cache_status', { enabled: false })
|
||||
}
|
||||
|
||||
function handleTickSync (client) {
|
||||
client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: 0n })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue