bed: wake() sends the right entity_action on 1.21.11+ (leave_bed renumbered; 2 is stop_sprinting there) - #4047
Open
cleverark wants to merge 1 commit into
Open
Conversation
…fted; 2 is stop_sprinting there) 1.21.11 moved start/stop sneaking out of entity_action, so the remaining actions renumbered and the field became a named mapping: leave_bed is 0, where it used to be 2. wake() still sent 2, which those servers read as stop_sprinting — the bot slept on until the server itself woke it. Read the protocol definition and send the name when it's mapped, the number otherwise. The bed external test didn't catch this because a lone sleeper on the test server skips the night, and the server wakes the bot at dawn. It now checks the clock is still night after wake() resolves. Found on a Paper 26.1.2 server where another player was online (so no night skip): bot.sleep() worked, bot.wake() resolved, bot.isSleeping stayed true. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On 1.21.11 and later,
bot.wake()does nothing: the bot stays in bed until the server wakes it.1.21.11 moved start/stop sneaking out of
entity_action(they went toplayer_input), so the remaining actions renumbered and the field became a named mapping.leave_bedis 0 there; it was 2 before.wake()still sends2, which those servers read asstop_sprinting.Seen live on a Paper 26.1.2 server with a second player online:
bot.sleep()worked (advancement "Sweet Dreams" logged),bot.wake()resolved,bot.isSleepingstayedtrue, and the bot lay there until it was disconnected.Fix
Read the protocol definition once at inject time: when
actionIdis a mapper, send'leave_bed'by name; otherwise send the bare2as before. No version table to maintain, and older servers are unchanged.Why the external test didn't catch it
test/externalTests/bed.jssleeps and then awaitswake. On the test server the bot is the only player, so ~100 ticks after it lies down the night is skipped and the server wakes it, whether or notwake()worked. The test now checks that the clock is still night afterwake()resolves — a real wake leaves the clock alone, a night skip resets it to morning.Notes
entity_action.actionIdis a bare varint on 1.8–1.21.10 and a mapper (0: leave_bed, 1: start_sprinting, 2: stop_sprinting, …) on 1.21.11 and 26.1.features.jsonflag in minecraft-data than on the protocol shape, happy to change it — the protocol read seemed the least surprising since it's the packet itself that changed.🤖 Generated with Claude Code