Add Velocity proxy support for Minecraft 1.20.2+ configuration phase #3786
+318
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Velocity Proxy Support for Minecraft 1.20.2+ Configuration Phase
Summary
This PR fixes bot disconnections when connecting through Velocity proxy servers with Minecraft 1.20.2+ versions. The issue occurred during server transfers when the bot sent gameplay packets (movement, physics) during the configuration phase, causing the server to kick the bot with error: "Disconnected, while in configuration phase".
Fixes #3764
Problem Description
Background
Minecraft 1.20.2 introduced a new "configuration phase" that occurs:
During this phase:
What Was Broken
Mineflayer was sending physics/movement packets during the configuration phase, causing:
Solution
1. New Velocity Plugin (
lib/plugins/velocity.js)A new plugin that:
bot.inConfigurationPhaseflagstart_configuration(1.20.2+)select_known_packs(1.21+)registry_data(1.20.2+)transfer(1.20.5+)bot.on('configurationPhase', (phase) => {})2. Physics Plugin Modification (
lib/plugins/physics.js)Added checks to prevent sending movement packets during configuration:
sendPacketPosition()- Returns early ifbot.inConfigurationPhasesendPacketLook()- Returns early ifbot.inConfigurationPhasesendPacketPositionAndLook()- Returns early ifbot.inConfigurationPhaseupdatePosition()- Returns early ifbot.inConfigurationPhase3. Loader Update (
lib/loader.js)Added velocity plugin to internal plugins list, loaded before physics plugin (order matters).
4. Example (
examples/velocity_transfer.js)New example demonstrating Velocity proxy connection and server transfer handling.
Technical Details
Configuration Phase Flow
Resource Pack Handling
The plugin uses
prependListenerto intercept resource pack events before the resource_pack plugin processes them. This ensures:Why Automatic Resource Pack Acceptance?
During Velocity transfers, resource packs must be accepted immediately or the configuration phase hangs indefinitely. The server waits for
SUCCESSFULLY_LOADEDbefore sendingfinish_configuration. Users can still manually handle resource packs outside of configuration phase.Testing
Tested Scenarios
✅ Velocity proxy connection (1.21.8)
✅ Server transfers between backend servers
✅ Resource pack acceptance during transfers
✅ Multiple consecutive transfers
✅ Physics re-enabling after transfer
✅ Fallback to spawn/login events if finish_configuration doesn't fire
Test Servers
How to Test
Breaking Changes
None. This is a purely additive change:
plugins: { velocity: false }Backward Compatibility
bot.acceptResourcePack()for normal gameplayAdditional Notes
Why a New Plugin?
The configuration phase handling requires:
A dedicated plugin is cleaner than modifying multiple existing plugins.
Plugin Load Order
The velocity plugin must load before physics plugin because:
bot.inConfigurationPhaseflagloader.jsensures correct initializationFiles Changed
lib/plugins/velocity.js- New plugin (180 lines)lib/plugins/physics.js- Added configuration phase checks (4 locations)lib/loader.js- Added velocity to plugins list (1 line)examples/velocity_transfer.js- New example (55 lines)Credits
Based on investigation of issue #3764 and testing with Velocity proxy servers.