[PR #2813] [MERGED] Server: refuse block actions out of reach or outside the world border #4630

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2813
Author: @sirrayi
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/28/2026
Merged by: @ludovic111

Base: main ← Head: fix/guest-block-reach


📝 Commits (3)

  • 9bbc54b Server: refuse block actions out of a player's reach
  • 0580626 Server: refuse digging and using blocks outside the world border
  • 3be828d Merge main into #2813: reach first, then spawn protection, then the border

📊 Changes

2 files changed (+89 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game/lan_actions.rs (+34 -1)
📝 crates/horizon-client/src/lan/guest.rs (+55 -0)

📄 Description

🤖 Opened by sirrayi's AI agent (Devin), not by sirrayi themselves.

What and why

A server never checked that a player's block actions were within reach. In game/lan_actions.rs, PlayerAction START_DESTROY_BLOCK stored the position whatever it was, and the per-tick digging (forced_hit + tick_mining) then broke it. UseItemOn set forced_hit and ran use_item for any position. So a modified client could break or place blocks anywhere in the loaded chunks of a LAN world, a dedicated server or the single-player server thread.

Now:

  • START_DESTROY_BLOCK out of reach does nothing (vanilla: "too far").
  • STOP_DESTROY_BLOCK out of reach drops the dig without breaking anything. The block-change ack that is already sent makes the client undo its predicted break.
  • UseItemOn needs the block within reach and the hit point inside the block (each axis of location - atCenterOf(pos) under 1.0000001). Otherwise nothing is used and no block updates are sent; the ack is still sent.
  • World border (second commit, part of #2743): ServerLevel.mayInteract also needs WorldBorder.isWithinBounds(pos). START_DESTROY_BLOCK outside the border starts no dig, and UseItemOn uses nothing there; the two block updates are still sent back, as in vanilla.

The new check is Guest::may_reach_block: the eyes of the guest's body in its pose (crouching, swimming, gliding; the sneak flag before the first body), and 4.5 + 1 blocks, or 5 + 1 in creative. It uses the same hard-coded ranges as Guest::within_block_range and Game::reach. A block_interaction_range changed with /attribute is not read here, as elsewhere in the hub.

Vanilla reference

  • ServerPlayerGameMode.handleBlockBreakAction: !player.isWithinBlockInteractionRange(pos, 1.0) → "too far".
  • ServerGamePacketListenerImpl.handleUseItemOn: isWithinBlockInteractionRange(pos, 1.0), then Math.abs(location - Vec3.atCenterOf(pos)) < 1.0000001 on each axis.
  • Player.isWithinBlockInteractionRange (AABB.distanceToSqr from the eyes).
  • ServerLevel.mayInteract → WorldBorder.isWithinBounds(BlockPos).

Harness: none yet. lan_e2e / server_* cover the paths, but they need .local/ data, which this machine doesn't have.

Self-check

python3 tools/pr_ready.py --quick --base origin/main ran here: rustfmt ✅, clippy (-D warnings) ✅, horizon-client tests (1338) ✅. Its Python tests failed only because this machine has Python 3.9; the repo needs 3.11+ (tomllib, hashlib.file_digest). The diff touches no Python.

  • New unit test lan::guest::tests::a_block_action_must_be_within_reach.
  • cargo check -p horizon-client --bins ✅; after the border commit, cargo clippy -p horizon-client --bins -- -D warnings ✅ and rustfmt ✅.

Generated with Devin


🔄 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/2813 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/guest-block-reach` --- ### 📝 Commits (3) - [`9bbc54b`](https://github.com/horizon-rust/horizon/commit/9bbc54bd4c850e00c0525893a2b06d2443209482) Server: refuse block actions out of a player's reach - [`0580626`](https://github.com/horizon-rust/horizon/commit/05806267847f1db90f836e8b821ff44f10c37209) Server: refuse digging and using blocks outside the world border - [`3be828d`](https://github.com/horizon-rust/horizon/commit/3be828d012e0e1904213d00539fe126c607762b4) Merge main into #2813: reach first, then spawn protection, then the border ### 📊 Changes **2 files changed** (+89 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/lan_actions.rs` (+34 -1) 📝 `crates/horizon-client/src/lan/guest.rs` (+55 -0) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (Devin), not by sirrayi themselves. ## What and why A server never checked that a player's block actions were within reach. In `game/lan_actions.rs`, `PlayerAction` START_DESTROY_BLOCK stored the position whatever it was, and the per-tick digging (`forced_hit` + `tick_mining`) then broke it. `UseItemOn` set `forced_hit` and ran `use_item` for any position. So a modified client could break or place blocks anywhere in the loaded chunks of a LAN world, a dedicated server or the single-player server thread. Now: - START_DESTROY_BLOCK out of reach does nothing (vanilla: "too far"). - STOP_DESTROY_BLOCK out of reach drops the dig without breaking anything. The block-change ack that is already sent makes the client undo its predicted break. - `UseItemOn` needs the block within reach and the hit point inside the block (each axis of `location - atCenterOf(pos)` under 1.0000001). Otherwise nothing is used and no block updates are sent; the ack is still sent. - **World border** (second commit, part of #2743): `ServerLevel.mayInteract` also needs `WorldBorder.isWithinBounds(pos)`. START_DESTROY_BLOCK outside the border starts no dig, and `UseItemOn` uses nothing there; the two block updates are still sent back, as in vanilla. The new check is `Guest::may_reach_block`: the eyes of the guest's body in its pose (crouching, swimming, gliding; the sneak flag before the first body), and 4.5 + 1 blocks, or 5 + 1 in creative. It uses the same hard-coded ranges as `Guest::within_block_range` and `Game::reach`. A `block_interaction_range` changed with `/attribute` is not read here, as elsewhere in the hub. ## Vanilla reference - `ServerPlayerGameMode.handleBlockBreakAction`: `!player.isWithinBlockInteractionRange(pos, 1.0)` → "too far". - `ServerGamePacketListenerImpl.handleUseItemOn`: `isWithinBlockInteractionRange(pos, 1.0)`, then `Math.abs(location - Vec3.atCenterOf(pos)) < 1.0000001` on each axis. - `Player.isWithinBlockInteractionRange` (`AABB.distanceToSqr` from the eyes). - `ServerLevel.mayInteract` → `WorldBorder.isWithinBounds(BlockPos)`. Harness: none yet. `lan_e2e` / `server_*` cover the paths, but they need `.local/` data, which this machine doesn't have. ## Self-check `python3 tools/pr_ready.py --quick --base origin/main` ran here: rustfmt ✅, clippy (`-D warnings`) ✅, horizon-client tests (1338) ✅. Its Python tests failed only because this machine has Python 3.9; the repo needs 3.11+ (`tomllib`, `hashlib.file_digest`). The diff touches no Python. - New unit test `lan::guest::tests::a_block_action_must_be_within_reach`. - `cargo check -p horizon-client --bins` ✅; after the border commit, `cargo clippy -p horizon-client --bins -- -D warnings` ✅ and rustfmt ✅. Generated with [Devin](https://devin.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:06:48 +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#4630
No description provided.