[PR #3611] [MERGED] Adventure: don't predict breaking a block the player may not break (#3027) #5093

Closed
opened 2026-11-03 05:10:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3611
Author: @degepie
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @levzzz5154

Base: main ← Head: fix/issue-3027-adventure-ghost-blocks


📝 Commits (1)

  • d9f40c6 Adventure: don't predict breaking a block the player may not break

📊 Changes

3 files changed (+81 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game/remote.rs (+21 -1)
📝 crates/horizon-protocol/src/item.rs (+41 -0)
📝 tests/test_remote_mining.py (+19 -1)

📄 Description

🤖 Opened by degepie's AI agent (Claude Code), not by degepie personally.

Fixes #3027.

What

In adventure mode on a server, the client predicted breaking a block. You heard the break sound, saw the crack and particles, and the block went away. Then the server put it back. The arm also swung on every tick the attack button was held.

Now an adventure player with no can_break item does not start a break at all. No START/STOP_DESTROY_BLOCK is sent, nothing is predicted, and there is no crack or sound. The arm swings once per click, as in vanilla. An item the server sent with can_break still breaks, and the server checks whether its predicate matches the block.

Vanilla

  • MultiPlayerGameMode.startDestroyBlock returns false before predicting anything when Player.blockActionRestricted is true. That is the case for a spectator, and for an adventure player (Abilities.mayBuild false) unless the main-hand stack's can_break matches the block (ItemStack.canBreakBlockInAdventureMode).
  • MultiPlayerGameMode.continueDestroyBlock falls through to startDestroyBlock when no break is in progress, so it returns false too. Minecraft.continueAttack only swings when it returns true. Minecraft.startAttack swings once per click either way.
  • Placing a block already matched vanilla (ItemStack.useOn passes when the player may not build), because remote_can_place already returns early for a player who may not build.

How

  • remote.rs: a new remote_break_restricted helper. remote_mining returns early when it is true, and remote_continue_attack skips the dig, the swing and the Punch.
  • The client doesn't decode the can_break predicate from the wire (Component::Raw), so the helper only checks that the held stack's patch from the server sets component 15 (minecraft:can_break). Whether the predicate matches the block is left to the server.
  • horizon-protocol/src/item.rs: component::CAN_BREAK = 15 and WirePatch::adds, which lists the component kinds in a kept wire patch.

Verified

Client in a scratch home, against a scratch vanilla 26.3 server.jar (offline mode, flat world, player in adventure). v0.2.91 compared with this branch:

v0.2.91 this branch
hold attack on dirt, stone in hand break reports ok after 20 ticks; gravel.hit + gravel.break heard; dirt back 1 s later (ghost); 6 swings break times out after 60 ticks; no break sounds; dirt stays; 1 swing
place stone on grass refused, no ghost refused, no ghost
iron_shovel[can_break={blocks:"minecraft:dirt"}] on dirt (not reached: the player died to slimes) breaks, drops dirt, stays air
stone[can_place_on={blocks:"minecraft:grass_block"}] on grass (not reached) placed, stays

In single player (server thread) with /gamemode adventure, the break ghost is gone in the same way: no sounds, the dirt never vanishes, 1 swing.

  • tests/test_remote_mining.py now has a restricted player case: nothing breaks, nothing is sent, no sound. It fails without the gate.
  • horizon-protocol: unit test a_wire_patch_tells_what_it_adds.

Known differences

  • A can_break item whose predicate doesn't match the block is still predicted, and the server sends the block back. Matching the predicate needs it decoded, which #2990 adds for stacks the game holds itself.
  • Single player's own server ignores can_break and can_place_on in adventure, and does not send them to the client. #2990 covers the server side.
  • Out of scope: in single player, an axe strips a log in adventure, and the strip stays (server side). The client also predicts the strip sound, where vanilla's ItemStack.useOn passes.

pr_ready (tools/pr_ready.py --quick on horizon-build, against origin/main at d203ca04b, 3 min 36 s)

Check Result
Scope ✅ 3 files, +81 −2
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 408 passed (28 s)
rustfmt ✅ (8 s)
clippy ✅ (45 s)
tests: horizon-client, horizon-protocol ✅ 906 passed (2 min 11 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 348 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 336 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3611 **Author:** [@degepie](https://github.com/degepie) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix/issue-3027-adventure-ghost-blocks` --- ### 📝 Commits (1) - [`d9f40c6`](https://github.com/horizon-rust/horizon/commit/d9f40c694230a0bcea166fa07679b71d62482e80) Adventure: don't predict breaking a block the player may not break ### 📊 Changes **3 files changed** (+81 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/remote.rs` (+21 -1) 📝 `crates/horizon-protocol/src/item.rs` (+41 -0) 📝 `tests/test_remote_mining.py` (+19 -1) </details> ### 📄 Description > 🤖 Opened by degepie's AI agent (Claude Code), not by degepie personally. Fixes #3027. ## What In adventure mode on a server, the client predicted breaking a block. You heard the break sound, saw the crack and particles, and the block went away. Then the server put it back. The arm also swung on every tick the attack button was held. Now an adventure player with no `can_break` item does not start a break at all. No START/STOP_DESTROY_BLOCK is sent, nothing is predicted, and there is no crack or sound. The arm swings once per click, as in vanilla. An item the server sent with `can_break` still breaks, and the server checks whether its predicate matches the block. ## Vanilla - `MultiPlayerGameMode.startDestroyBlock` returns false before predicting anything when `Player.blockActionRestricted` is true. That is the case for a spectator, and for an adventure player (`Abilities.mayBuild` false) unless the main-hand stack's `can_break` matches the block (`ItemStack.canBreakBlockInAdventureMode`). - `MultiPlayerGameMode.continueDestroyBlock` falls through to `startDestroyBlock` when no break is in progress, so it returns false too. `Minecraft.continueAttack` only swings when it returns true. `Minecraft.startAttack` swings once per click either way. - Placing a block already matched vanilla (`ItemStack.useOn` passes when the player may not build), because `remote_can_place` already returns early for a player who may not build. ## How - `remote.rs`: a new `remote_break_restricted` helper. `remote_mining` returns early when it is true, and `remote_continue_attack` skips the dig, the swing and the Punch. - The client doesn't decode the `can_break` predicate from the wire (`Component::Raw`), so the helper only checks that the held stack's patch from the server sets component 15 (`minecraft:can_break`). Whether the predicate matches the block is left to the server. - `horizon-protocol/src/item.rs`: `component::CAN_BREAK = 15` and `WirePatch::adds`, which lists the component kinds in a kept wire patch. ## Verified Client in a scratch home, against a scratch vanilla 26.3 `server.jar` (offline mode, flat world, player in adventure). v0.2.91 compared with this branch: | | v0.2.91 | this branch | | --- | --- | --- | | hold attack on dirt, stone in hand | `break` reports ok after 20 ticks; `gravel.hit` + `gravel.break` heard; dirt back 1 s later (ghost); 6 swings | `break` times out after 60 ticks; no break sounds; dirt stays; 1 swing | | place stone on grass | refused, no ghost | refused, no ghost | | `iron_shovel[can_break={blocks:"minecraft:dirt"}]` on dirt | (not reached: the player died to slimes) | breaks, drops dirt, stays air | | `stone[can_place_on={blocks:"minecraft:grass_block"}]` on grass | (not reached) | placed, stays | In single player (server thread) with `/gamemode adventure`, the break ghost is gone in the same way: no sounds, the dirt never vanishes, 1 swing. - `tests/test_remote_mining.py` now has a restricted player case: nothing breaks, nothing is sent, no sound. It fails without the gate. - `horizon-protocol`: unit test `a_wire_patch_tells_what_it_adds`. ## Known differences - A `can_break` item whose predicate doesn't match the block is still predicted, and the server sends the block back. Matching the predicate needs it decoded, which #2990 adds for stacks the game holds itself. - Single player's own server ignores `can_break` and `can_place_on` in adventure, and does not send them to the client. #2990 covers the server side. - Out of scope: in single player, an axe strips a log in adventure, and the strip stays (server side). The client also predicts the strip sound, where vanilla's `ItemStack.useOn` passes. **pr_ready** (`tools/pr_ready.py --quick` on horizon-build, against origin/main at d203ca04b, 3 min 36 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +81 −2 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 408 passed (28 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (45 s) | | tests: horizon-client, horizon-protocol | ✅ 906 passed (2 min 11 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 348 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 336 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:10:11 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5093
No description provided.