[PR #2581] [MERGED] commands: an unbounded selector reaches the other loaded levels #4444

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

📋 Pull Request Information

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

Base: main ← Head: fix/selector-cross-level


📝 Commits (5)

  • 8909e05 commands: selectors find the End crystals and the Ender Dragon
  • fa4f38f commands: an unbounded selector reaches the other loaded levels
  • 04672c9 Merge remote-tracking branch 'upstream/main' into fix/selector-end-crystals
  • ddfa71a Merge the End crystal and dragon selectors into the cross-level selectors
  • 30027e3 Merge main (selectors: the level candidates keep main's is_arrow; /execute on origin and score holders know the crystals and the dragon)

📊 Changes

15 files changed (+368 additions, -101 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -1)
📝 crates/horizon-client/src/game/commands.rs (+231 -77)
📝 crates/horizon-client/src/game/commands/data.rs (+34 -4)
📝 crates/horizon-client/src/game/commands/execute.rs (+3 -2)
📝 crates/horizon-client/src/game/creatures.rs (+12 -3)
📝 crates/horizon-client/src/game/crossbow.rs (+1 -1)
📝 crates/horizon-client/src/game/dispenser.rs (+1 -1)
📝 crates/horizon-client/src/game/dragon.rs (+22 -2)
📝 crates/horizon-client/src/game/levels.rs (+4 -0)
📝 crates/horizon-client/src/game/persist.rs (+20 -4)
📝 crates/horizon-client/src/game/remote_projectiles.rs (+1 -1)
📝 crates/horizon-client/src/game/scoreboard.rs (+8 -2)
📝 crates/horizon-client/src/game/wind.rs (+1 -1)
📝 crates/horizon-command/src/args.rs (+8 -0)
📝 tools/command_exec_corpus.py (+21 -2)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself.

What and why

Game::select gathered the candidates of a selector from the level in place
only, so an unbounded selector never reached an entity in another dimension
the server still holds: /data get entity @e[tag=remote_cow,limit=1] Pos in
the Overworld answered "No entity was found" for a cow that was in the
Nether, and the same held for /kill and /tp. Vanilla's
EntitySelector.findEntities searches every level the server has, unless the
selector carries a spatial constraint.

The selector now searches each loaded level in turn (the level in place and
the ones the server keeps loaded beside it), and the commands that act on the
entity it found (/data get entity, /data set entity, /kill, /tp) act
on it in the level that holds it. A selector with a spatial constraint
(distance=, x=, y=, z=, dx=, dy=, dz=) still reaches the level
the command runs in only, as vanilla's EntitySelectorParser.setWorldLimited
has it.

The experience orbs and the projectiles are named by their entity id now,
like the other entities (the orbs already had one; the projectiles get one
from the entity counter when they are created), so the entity a command acts
on is the entity the selector found, whichever level it is in.

Fixes #1524

This branch also carries the change from #2559 ("commands: selectors find the End crystals and the Ender Dragon"): the End crystals and the dragon are entities of their own, so they take an entity id and @e[type=end_crystal] and @e[type=ender_dragon] find them. Both pull requests reshape Game::select in game/commands.rs, so they are stacked here: this pull request contains both and can be merged on its own, and #2559 can be closed or merged first.

Vanilla reference

  • net.minecraft.commands.arguments.selector.EntitySelector.findEntities —
    if (this.isWorldLimited()) { this.addEntities(result, sender.getLevel(), ...) } else { for (ServerLevel level : sender.getServer().getAllLevels()) { this.addEntities(result, level, ...) } }:
    an unbounded selector reaches every loaded level, a world-limited one only
    the level the command runs in. The result limit is shared by the levels
    (addEntities stops once result.size() >= limit), and the sort and the
    limit are applied to the combined result (sortAndLimit).
  • net.minecraft.commands.arguments.selector.EntitySelectorParser.setWorldLimited
    and net.minecraft.commands.arguments.selector.options.EntitySelectorOptions
    — distance (line 110), x (126), y (130), z (134), dx (138), dy
    (142) and dz (146) are the options that limit the selector to the
    command's level; tag= and type= do not.
  • net.minecraft.commands.arguments.selector.EntitySelector.getPredicate —
    the distance and the box checks are only added when the selector carries
    them, so an unbounded selector has no spatial filter at all.
  • net.minecraft.server.commands.KillCommand and
    net.minecraft.world.entity.Entity.kill(ServerLevel) — the entity is
    killed in the level it is in (entity.kill(source.getLevel()) reads the
    entity's own level through Entity.level).

Self-check

python3 tools/test_command_exec_parity.py (the vanilla differential
harness, with a new case in the levels group of
tools/command_exec_corpus.py: a cow tagged remote_cow is left in the
Overworld in a force-loaded chunk, the player goes through the nether portal
and asks for the cow from there):

levels: 8/8 commands match
total: 872/872 commands match

The new cases, identical in vanilla and in Horizon:

/data get entity @e[tag=remote_cow,limit=1] Pos
  Cow has the following entity data: [10.5d, 210.0d, 4.5d]
/data get entity @e[tag=remote_cow,distance=..128,limit=1] Pos
  No entity was found

The first is the unbounded selector: it finds the cow in the Overworld from
the Nether. The second carries a distance, so it only reaches the level the
command runs in, and the cow is not there.

Before the fix, the same harness reproduced the report (levels: 7/8):

/data get entity @e[tag=remote_cow,limit=1] Pos
  vanilla  Cow has the following entity data: [10.5d, 210.0d, 4.5d]
  rust     No entity was found

cargo fmt -p horizon-client (clean) and
cargo build -p horizon-client --bin horizon-client (clean).

🤖 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/2581 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/selector-cross-level` --- ### 📝 Commits (5) - [`8909e05`](https://github.com/horizon-rust/horizon/commit/8909e0510c4700295514c83c5f61cbd5695d9db7) commands: selectors find the End crystals and the Ender Dragon - [`fa4f38f`](https://github.com/horizon-rust/horizon/commit/fa4f38f824dd4f5536eb62d221ce8835c53db3cf) commands: an unbounded selector reaches the other loaded levels - [`04672c9`](https://github.com/horizon-rust/horizon/commit/04672c9613918ba128625d4d72163b36ca62ff6e) Merge remote-tracking branch 'upstream/main' into fix/selector-end-crystals - [`ddfa71a`](https://github.com/horizon-rust/horizon/commit/ddfa71a46f4bc29cd3f9f4b1f6bab3a159d80e04) Merge the End crystal and dragon selectors into the cross-level selectors - [`30027e3`](https://github.com/horizon-rust/horizon/commit/30027e32a63eb4747549b9f6a214f97b0e80f443) Merge main (selectors: the level candidates keep main's is_arrow; /execute on origin and score holders know the crystals and the dragon) ### 📊 Changes **15 files changed** (+368 additions, -101 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -1) 📝 `crates/horizon-client/src/game/commands.rs` (+231 -77) 📝 `crates/horizon-client/src/game/commands/data.rs` (+34 -4) 📝 `crates/horizon-client/src/game/commands/execute.rs` (+3 -2) 📝 `crates/horizon-client/src/game/creatures.rs` (+12 -3) 📝 `crates/horizon-client/src/game/crossbow.rs` (+1 -1) 📝 `crates/horizon-client/src/game/dispenser.rs` (+1 -1) 📝 `crates/horizon-client/src/game/dragon.rs` (+22 -2) 📝 `crates/horizon-client/src/game/levels.rs` (+4 -0) 📝 `crates/horizon-client/src/game/persist.rs` (+20 -4) 📝 `crates/horizon-client/src/game/remote_projectiles.rs` (+1 -1) 📝 `crates/horizon-client/src/game/scoreboard.rs` (+8 -2) 📝 `crates/horizon-client/src/game/wind.rs` (+1 -1) 📝 `crates/horizon-command/src/args.rs` (+8 -0) 📝 `tools/command_exec_corpus.py` (+21 -2) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself. ## What and why `Game::select` gathered the candidates of a selector from the level in place only, so an unbounded selector never reached an entity in another dimension the server still holds: `/data get entity @e[tag=remote_cow,limit=1] Pos` in the Overworld answered "No entity was found" for a cow that was in the Nether, and the same held for `/kill` and `/tp`. Vanilla's `EntitySelector.findEntities` searches every level the server has, unless the selector carries a spatial constraint. The selector now searches each loaded level in turn (the level in place and the ones the server keeps loaded beside it), and the commands that act on the entity it found (`/data get entity`, `/data set entity`, `/kill`, `/tp`) act on it in the level that holds it. A selector with a spatial constraint (`distance=`, `x=`, `y=`, `z=`, `dx=`, `dy=`, `dz=`) still reaches the level the command runs in only, as vanilla's `EntitySelectorParser.setWorldLimited` has it. The experience orbs and the projectiles are named by their entity id now, like the other entities (the orbs already had one; the projectiles get one from the entity counter when they are created), so the entity a command acts on is the entity the selector found, whichever level it is in. Fixes #1524 This branch also carries the change from #2559 ("commands: selectors find the End crystals and the Ender Dragon"): the End crystals and the dragon are entities of their own, so they take an entity id and `@e[type=end_crystal]` and `@e[type=ender_dragon]` find them. Both pull requests reshape `Game::select` in `game/commands.rs`, so they are stacked here: this pull request contains both and can be merged on its own, and #2559 can be closed or merged first. ## Vanilla reference - `net.minecraft.commands.arguments.selector.EntitySelector.findEntities` — `if (this.isWorldLimited()) { this.addEntities(result, sender.getLevel(), ...) } else { for (ServerLevel level : sender.getServer().getAllLevels()) { this.addEntities(result, level, ...) } }`: an unbounded selector reaches every loaded level, a world-limited one only the level the command runs in. The result limit is shared by the levels (`addEntities` stops once `result.size() >= limit`), and the sort and the limit are applied to the combined result (`sortAndLimit`). - `net.minecraft.commands.arguments.selector.EntitySelectorParser.setWorldLimited` and `net.minecraft.commands.arguments.selector.options.EntitySelectorOptions` — `distance` (line 110), `x` (126), `y` (130), `z` (134), `dx` (138), `dy` (142) and `dz` (146) are the options that limit the selector to the command's level; `tag=` and `type=` do not. - `net.minecraft.commands.arguments.selector.EntitySelector.getPredicate` — the distance and the box checks are only added when the selector carries them, so an unbounded selector has no spatial filter at all. - `net.minecraft.server.commands.KillCommand` and `net.minecraft.world.entity.Entity.kill(ServerLevel)` — the entity is killed in the level it is in (`entity.kill(source.getLevel())` reads the entity's own level through `Entity.level`). ## Self-check `python3 tools/test_command_exec_parity.py` (the vanilla differential harness, with a new case in the `levels` group of `tools/command_exec_corpus.py`: a cow tagged `remote_cow` is left in the Overworld in a force-loaded chunk, the player goes through the nether portal and asks for the cow from there): ``` levels: 8/8 commands match total: 872/872 commands match ``` The new cases, identical in vanilla and in Horizon: ``` /data get entity @e[tag=remote_cow,limit=1] Pos Cow has the following entity data: [10.5d, 210.0d, 4.5d] /data get entity @e[tag=remote_cow,distance=..128,limit=1] Pos No entity was found ``` The first is the unbounded selector: it finds the cow in the Overworld from the Nether. The second carries a distance, so it only reaches the level the command runs in, and the cow is not there. Before the fix, the same harness reproduced the report (`levels: 7/8`): ``` /data get entity @e[tag=remote_cow,limit=1] Pos vanilla Cow has the following entity data: [10.5d, 210.0d, 4.5d] rust No entity was found ``` `cargo fmt -p horizon-client` (clean) and `cargo build -p horizon-client --bin horizon-client` (clean). 🤖 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 04:17: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#4444
No description provided.