Versions
node-minecraft-protocol: 1.66.0
mineflayer: 4.37.0
- Minecraft server: 1.21.11 (vanilla single-player, opened to LAN)
- Node: 22
What happens
When the bot attempts to send any slash command whose packet goes through chat_command_signed (e.g. /say hello, /tell target msg), it crashes with:
RangeError [ERR_OUT_OF_RANGE]: Write error for undefined :
The value of "value" is out of range. It must be >= -128 and <= 127. Received 143
at writeU_Int8 (node:internal/buffer:740:11)
at Buffer.writeInt8 (node:internal/buffer:871:10)
at Object.writer [as i8] (.../protodef/src/datatypes/numeric.js:97:25)
at Object.packet_chat_command_signed ...
code: 'ERR_OUT_OF_RANGE',
field: 'play.toServer'
The value received varies (143, 212, ...) — it's the chat checksum.
Root cause
In src/datatypes/checksums.js:
function computeChatChecksum (lastSeenMessages) {
// ...
const result = checksum & 0xff // <-- returns 0..255 (unsigned)
return result === 0 ? 1 : result
}
The function returns an unsigned byte (& 0xff → 0..255).
The schema for packet_chat_command_signed (and packet_chat_message) in 1.21.5+ defines this field as a signed i8 (-128..127):
{ "name": "checksum", "type": "i8" }
Whenever the hash happens to have its top bit set (~50% of the time), the resulting unsigned byte is ≥ 128, and writeInt8 throws.
Suggested fix
const unsigned = checksum & 0xff
const signed = unsigned > 127 ? unsigned - 256 : unsigned
return signed === 0 ? 1 : signed
or equivalently new Int8Array([checksum & 0xff])[0].
Applied this as a local monkey-patch against node_modules/minecraft-protocol/src/datatypes/checksums.js and the bot can now reliably send slash commands to 1.21.11 without the ERR_OUT_OF_RANGE crash.
Happy to open a PR if that would help.
Versions
node-minecraft-protocol: 1.66.0mineflayer: 4.37.0What happens
When the bot attempts to send any slash command whose packet goes through
chat_command_signed(e.g./say hello,/tell target msg), it crashes with:The value received varies (143, 212, ...) — it's the chat checksum.
Root cause
In
src/datatypes/checksums.js:The function returns an unsigned byte (
& 0xff→0..255).The schema for
packet_chat_command_signed(andpacket_chat_message) in 1.21.5+ defines this field as a signedi8(-128..127):{ "name": "checksum", "type": "i8" }Whenever the hash happens to have its top bit set (~50% of the time), the resulting unsigned byte is ≥ 128, and
writeInt8throws.Suggested fix
or equivalently
new Int8Array([checksum & 0xff])[0].Applied this as a local monkey-patch against
node_modules/minecraft-protocol/src/datatypes/checksums.jsand the bot can now reliably send slash commands to 1.21.11 without theERR_OUT_OF_RANGEcrash.Happy to open a PR if that would help.