Skip to content

fix: send the action ids a protocol maps to names - #4077

Closed
u9g wants to merge 2 commits into
PrismarineJS:masterfrom
u9g:fix/26-1-string-mapped-action-ids
Closed

fix: send the action ids a protocol maps to names#4077
u9g wants to merge 2 commits into
PrismarineJS:masterfrom
u9g:fix/26-1-string-mapped-action-ids

Conversation

@u9g

@u9g u9g commented Sep 7, 2026

Copy link
Copy Markdown
Member

On 26.1 client_command.actionId and use_entity.hand are mapper fields:

"packet_client_command": ["container", [{"name": "actionId", "type": ["mapper", {"type": "varint", "mappings": {"0": "perform_respawn", "1": "request_stats", "2": "request_gamerule_values"}}]}]]
"packet_use_entity":     ["container", [{"name": "target", ...}, {"name": "hand", "type": ["mapper", {"type": "varint", "mappings": {"0": "main_hand", "1": "off_hand"}}]}, ...]]

Writing the numeric id there throws inside the serializer:

Error: SizeOf error for undefined : 0 is not in the mappings value
    at Object.packet_use_entity ...

The packet is dropped on the floor, so on 26.1 the bot cannot respawn (bot.respawn(), the death handler, the win_game handler), cannot request stats, and bot.activateEntity() does nothing at all — right-clicking an NPC on a 26.1 server looked like the server ignoring us. entity_action has been string-mapped since 1.21.6 and physics.js already handles it, but bed.js's wake() still wrote actionId: 2, which both fails to serialize there and means stop_sprinting under the new mapping.

game.js also wrote { action: 0 }, a field name that does not exist in any protocol version, so the win_game respawn never serialized anywhere.

lib/protocol_ids.js asks the schema whether the field is a mapper rather than going through a feature, so this is right whether minecraft-data keeps 26.1's mappers (PrismarineJS/minecraft-data#1279) or drops them (PrismarineJS/minecraft-data#1278), and it needs no unreleased data. bed.js keeps supportFeature('entityActionUsesStringMapper') to match physics.js, which already uses it for the same packet.

Verified live: with this change bot.activateEntity() on a 26.1 server's NPC produces use_entity {target, hand: 'main_hand', location, sneaking} and the server answers, where before nothing went out.

Tests: three cases in test/internalTest.js covering every tested version. They resolve the packet out of the server's read path before asserting — an assertion thrown inside the packet listener wedges the connection and shows up as an afterEach timeout — and on 1.8-1.11, whose use_entity has no hand field at all, the assertion is just that the packet arrives.

26.1's protocol maps client_command's actionId and use_entity's hand to strings, so writing the numeric id throws "SizeOf error ... is not in the mappings value" and the packet never leaves the client: the bot cannot respawn or right-click an entity there. entity_action has been mapped since 1.21.6, which bed.js's wake() still missed.

Needs the two features added in PrismarineJS/minecraft-data#1279.
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Tests more than 1.5x slower than master (durations are noisy, so this is informational):

   8648ms ->   15657ms  mineflayer_external 1.10.2v fishing
   2950ms ->   18392ms  mineflayer_external 1.9.4v fishing

@u9g

u9g commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

#4079 is the same fix. If PrismarineJS/minecraft-data#1278 lands, use_entity.hand needs no feature check, but client_command.actionId (26.1) and entity_action.actionId (1.21.6+) still do.

… from the schema

Replaces the supportFeature checks with a lib/protocol_ids.js helper that asks the schema whether the field is a protodef mapper, so the fix is right whether minecraft-data keeps 26.1's mappers or drops them, and needs no unreleased data.

The three tests now resolve the packet out of the server's read path before asserting: throwing inside the packet listener wedged the connection and surfaced as an afterEach timeout on versions whose use_entity carries no hand at all (1.8-1.11), and those versions now only assert that the packet arrives.
@u9g u9g changed the title fix: send the action ids 26.1 maps to strings fix: send the action ids a protocol maps to names Sep 7, 2026
@u9g

u9g commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

#4076 (opened first) covers client_command and entity_action with the same schema-introspection approach under a different helper name. What is only here: use_entity.hand in inventory.js, which is the one that actually breaks a bot — on 26.1 bot.activateEntity() serializes nothing at all, so right-clicking an NPC looks like the server ignoring you. If these are consolidated into #4076, that hunk and its test need to come along.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant