Crash in physics.js when explosion occurs (Mineflayer 4.27.0, MC 1.21.4)
- [✅] The FAQ doesn't contain a resolution to my issue
Environment
- Minecraft Version: 1.21.x (confirmed on 1.21.4)
- Server Type: PaperMC, running on LAN (also tested on Vanilla & Spigot)
- Mineflayer Version: 4.27.0
- Node.js Version: v22.14.0
- OS: Pop!_OS (Linux)
Problem
The bot crashes whenever an explosion happens nearby (e.g., TNT or Creeper).
It crashes inside mineflayer/lib/plugins/physics.js at line 299 whenever it tries to process explosion
I think it has something to do with insanely large vector in player knockback.
What did you try yet?
At first, I thought it was caused by my own bot code (~1000+ lines), but I reproduced the bug using a minimal Mineflayer bot that just connects and spawns. I tested this on:
- PaperMC, Vanilla, and Spigot servers
- LAN setup
- Fresh installs of Mineflayer and Node.js
All setups crash instantly on any explosion.
Minimal Reproduction code
import mineflayer from 'mineflayer';
const bot = mineflayer.createBot({
host: 'localhost',
port: 25565,
username: 'TestBot',
});
bot.on('spawn', () => {
console.log('Bot spawned and ready');
});
Expected behavior
The bot shouldn't crash when an explosion occurs nearby.
Instead, it throws a TypeError trying to access property which is undefined ;-;
##Error
Chunk size is 53 but only 29 was read ; partial packet : {"name":"explosion","params":{"center":{"x":-2.5531342029571533,"y":1.4030810953376417e-36,"z":-3.218271255493164},"playerKnockback":{"x":-2.0000457763671875,"y":3.550067870195207e-28,"z":-1.3349637409800994e+30},"explosionParticle":{"type":"sweep_attack"},"soundId":16151}}; buffer :21c023668d03eeb8cdc04df828f5c00000c011e10325f186cc013f977eba590495aa3fc6db0ab35ed7abbfdd8c259c914fec15db04
/home/hatadi_v/Desktop/Ply/node_modules/vec3/index.js:82
this.x += other.x
^
TypeError: Cannot read properties of undefined (reading 'x')
at Vec3.add (/home/hatadi_v/Desktop/Ply/node_modules/vec3/index.js:82:21)
at Client.<anonymous> (/home/hatadi_v/Desktop/Ply/node_modules/mineflayer/lib/plugins/physics.js:299:29)
at Client.emit (node:events:530:35)
at emitPacket (/home/hatadi_v/Desktop/Ply/node_modules/minecraft-protocol/src/client.js:84:12)
at FullPacketParser.<anonymous> (/home/hatadi_v/Desktop/Ply/node_modules/minecraft-protocol/src/client.js:113:9)
at FullPacketParser.emit (node:events:518:28)
at addChunk (/home/hatadi_v/Desktop/Ply/node_modules/readable-stream/lib/internal/streams/readable.js:323:12)
at readableAddChunk (/home/hatadi_v/Desktop/Ply/node_modules/readable-stream/lib/internal/streams/readable.js:300:9)
at Readable.push (/home/hatadi_v/Desktop/Ply/node_modules/readable-stream/lib/internal/streams/readable.js:246:10)
at FullPacketParser._transform (/home/hatadi_v/Desktop/Ply/node_modules/protodef/src/serializer.js:89:10)
Node.js v22.14.0
Additional context
I am a beginner to both GitHub and JavaScript . Sorry if i misunderstood something. I tried to include every relevant information!
did you ever find a workaround for this bug? it seems to be the case in purpur with wind charges and tnt as well.
did you ever find a workaround for this bug? it seems to be the case in purpur with wind charges and tnt as well.
Well yes but its more a rough patch i had to modify the physics.js file to kinda just ignore tnt stuff ;-; not a good fix btw
did you ever find a workaround for this bug? it seems to be the case in purpur with wind charges and tnt as well.
Well yes but its more a rough patch i had to modify the physics.js file to kinda just ignore tnt stuff ;-; not a good fix btw
if you could share that that'd be awesome, it'd be useful for me
I had the same problem using tree farms with mineflayer on 1.21.4 paper server. So I did a quick patch to stop the judgment code that was causing the error. This worked for me for the time being, but I'm not sure if it will have any other effects.
This fix worked for me: physics.js:298
if (explosion.playerKnockback) { // 1.21.3+
// Fixes issue #3635
bot.entity.velocity.x += explosion.playerKnockback.x
bot.entity.velocity.y += explosion.playerKnockback.y
bot.entity.velocity.z += explosion.playerKnockback.z
}
Havent tested this more than throwing a wind charge at the bot and seeing that it doesnt crash. I might make a PR idk