[PR #2493] [MERGED] Read an End gateway's exit from its block entity #4365

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

📋 Pull Request Information

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

Base: main ← Head: fix/end-gateway-exit


📝 Commits (3)

  • 951b88a Read an End gateway's exit from its block entity
  • b90f9ec Make an End gateway's block entity the source of its exit
  • 475f64b Merge main into fix/end-gateway-exit

📊 Changes

7 files changed (+360 additions, -30 deletions)

View changed files

📝 crates/horizon-client-core/src/block_entity_nbt.rs (+11 -4)
📝 crates/horizon-client/src/containers.rs (+16 -0)
📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/commands.rs (+1 -2)
📝 crates/horizon-client/src/game/end.rs (+216 -24)
📝 crates/horizon-client/src/save.rs (+97 -0)
📝 crates/horizon-client/src/structure_blocks.rs (+17 -0)

📄 Description

🤖 Opened by Carlos Nunez's AI agent (Claude Code), not by Carlos Nunez himself. The first implementation was written by Codex (GPT-6.1 Sol) from a brief by this agent; this agent reviewed it, fixed what it found, and ran the checks below.

What and why

Fixes #1517. An End gateway ignored its configured exit: /setblock 702 100 0 end_gateway{Age:201L,exit_portal:[I;8,100,0],ExactTeleport:1b} sent the player to block (100, 49, 0) instead of (8.5, 100, 0.5), and /data get block said the block was not a block entity.

Horizon had no End gateway block entity. game/end.rs kept each gateway's exit in its own side file (horizon-end-gateways.json) and gateway_job only looked there, then used a "farther than 512 blocks leads to the End spawn" rule. /setblock NBT was dropped, and the exit_portal/ExactTeleport that worldgen writes for generated gateways was kept in the chunk but never read.

  • BlockEntity::EndGateway { age, exit_portal, exact_teleport }, made for minecraft:end_gateway, saved and loaded with vanilla's NBT: Age, exit_portal as an int array, ExactTeleport only when true. The exit is accepted only inside spawnable bounds, shared with block_entity_nbt.rs. Generated gateways keep their worldgen exit.
  • gateway_job takes the block entity's exit first (GatewayJob::for_gateway, a pure function); the side file and the 512-block rule stay as fallbacks, so older saves and gateways without data behave as before. The host and server guests both go through gateway_job, so server_travel.rs is unchanged.
  • The block entity is the source of truth once the gateway's chunk is loaded. The exits Horizon creates (set_gateway_exit) are stored in the block entity; the side file only keeps an entry when the chunk is already unloaded, and gateway_job moves such an entry into the block entity on the gateway's next use and drops it. So /data remove block ... exit_portal is not undone by an old entry. A new exit keeps the gateway's own ExactTeleport (setExitPosition); it is read when the trip starts (GatewayJob::Find { exact }), because the gateway's chunk may be unloaded by the time the exit exists.
  • load_block_entity_nbt (/setblock, /data on a block entity) re-set the same block state, which World::set ignores, so an NBT-only edit never marked its chunk modified and could revert after unload. It now marks the chunk. This applies to every block entity, not only gateways.

Vanilla reference

TheEndGatewayBlockEntity (26.3 server sources): saveAdditional/loadAdditional (Age, exit_portal filtered by Level.isInSpawnableBounds, ExactTeleport), getPortalPosition (a set exit is used exactly when exactTeleport, else findExitPosition; only an unset exit in the End is searched for or created), setExitPosition.

How I checked it

Headless game in throwaway HORIZON_HOME/launcher/XDG folders, driven with horizon-ctl, in both --server-thread and --in-frame, on macOS (build of this branch):

  • The issue's commands: the player arrives at exactly (8.5, 100, 0.5); on main it arrived at (100, 49, 0). /data get block now shows exit_portal and ExactTeleport.
  • Without ExactTeleport and an obsidian pillar at (9, 110, 10) near the exit (8, 100, 10): the player arrives at (9.5, 111, 10.5), vanilla's findExitPosition (tallest block near the exit, plus one).
  • ExactTeleport and no exit, gateway at (300, 100, 0): the exit gateway is created and the side file records [300,100,0] -> [1028,80,-7] with exact kept as true (the new exit gateway's own entry is false), in both modes.
  • After a trip that created an exit with the gateway's chunk loaded (forceload), the side file has no entry for it; /data remove block 300 100 0 exit_portal removes the exit and the next trip searches again (a new exit at (1028, 92, -7), the old one was (1028, 80, -7)), in both modes.
  • Unit tests: NBT round trip and the bounds check (save.rs), a generated gateway keeps its worldgen exit (structure_blocks.rs), the exit decision, including the fallbacks and the exact flag, and a saved exit moving into a gateway without one (game/end.rs).

Not covered: the parity harnesses (--quick); CI picks them. A gateway whose chunk is already unloaded when its exit is created keeps that exit in the side file until it is used again; if that gateway is replaced with a new one before then, the new one inherits the old entry (not tracked: there is no hook for a gateway block being replaced, and this is how every old save behaves). An exact teleport that lands inside the exit gateway block is entered again at once, because Horizon has no portal cooldown for gateway travel; that is the same before and after this change and not touched here.

Self-check

python3 tools/pr_ready.py --quick --base upstream/main on macOS (Python 3.13):

Check Result
Scope ✅ 7 files, +363 −30
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (7 s)
clippy ✅ (1 s)
tests: horizon-client ✅ 1341 passed (4 min 35 s)
doc tests ✅ 0 passed (6 s)
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses

Label: a fix, none.

🤖 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/2493 **Author:** [@carlosnunez09](https://github.com/carlosnunez09) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/end-gateway-exit` --- ### 📝 Commits (3) - [`951b88a`](https://github.com/horizon-rust/horizon/commit/951b88a3c299c1221cbd317481e6bbf1c9d1b8f1) Read an End gateway's exit from its block entity - [`b90f9ec`](https://github.com/horizon-rust/horizon/commit/b90f9ec1efc6ed34d815ad8652c5accab5600c73) Make an End gateway's block entity the source of its exit - [`475f64b`](https://github.com/horizon-rust/horizon/commit/475f64b79d1bbb9baa53da4f25b49d304b6f3ccf) Merge main into fix/end-gateway-exit ### 📊 Changes **7 files changed** (+360 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-core/src/block_entity_nbt.rs` (+11 -4) 📝 `crates/horizon-client/src/containers.rs` (+16 -0) 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/commands.rs` (+1 -2) 📝 `crates/horizon-client/src/game/end.rs` (+216 -24) 📝 `crates/horizon-client/src/save.rs` (+97 -0) 📝 `crates/horizon-client/src/structure_blocks.rs` (+17 -0) </details> ### 📄 Description > 🤖 Opened by Carlos Nunez's AI agent (Claude Code), not by Carlos Nunez himself. The first implementation was written by Codex (GPT-6.1 Sol) from a brief by this agent; this agent reviewed it, fixed what it found, and ran the checks below. ## What and why Fixes #1517. An End gateway ignored its configured exit: `/setblock 702 100 0 end_gateway{Age:201L,exit_portal:[I;8,100,0],ExactTeleport:1b}` sent the player to block (100, 49, 0) instead of (8.5, 100, 0.5), and `/data get block` said the block was not a block entity. Horizon had no End gateway block entity. `game/end.rs` kept each gateway's exit in its own side file (`horizon-end-gateways.json`) and `gateway_job` only looked there, then used a "farther than 512 blocks leads to the End spawn" rule. `/setblock` NBT was dropped, and the `exit_portal`/`ExactTeleport` that worldgen writes for generated gateways was kept in the chunk but never read. - `BlockEntity::EndGateway { age, exit_portal, exact_teleport }`, made for `minecraft:end_gateway`, saved and loaded with vanilla's NBT: `Age`, `exit_portal` as an int array, `ExactTeleport` only when true. The exit is accepted only inside spawnable bounds, shared with `block_entity_nbt.rs`. Generated gateways keep their worldgen exit. - `gateway_job` takes the block entity's exit first (`GatewayJob::for_gateway`, a pure function); the side file and the 512-block rule stay as fallbacks, so older saves and gateways without data behave as before. The host and server guests both go through `gateway_job`, so `server_travel.rs` is unchanged. - The block entity is the source of truth once the gateway's chunk is loaded. The exits Horizon creates (`set_gateway_exit`) are stored in the block entity; the side file only keeps an entry when the chunk is already unloaded, and `gateway_job` moves such an entry into the block entity on the gateway's next use and drops it. So `/data remove block ... exit_portal` is not undone by an old entry. A new exit keeps the gateway's own `ExactTeleport` (`setExitPosition`); it is read when the trip starts (`GatewayJob::Find { exact }`), because the gateway's chunk may be unloaded by the time the exit exists. - `load_block_entity_nbt` (`/setblock`, `/data` on a block entity) re-set the same block state, which `World::set` ignores, so an NBT-only edit never marked its chunk modified and could revert after unload. It now marks the chunk. This applies to every block entity, not only gateways. ## Vanilla reference `TheEndGatewayBlockEntity` (26.3 server sources): `saveAdditional`/`loadAdditional` (`Age`, `exit_portal` filtered by `Level.isInSpawnableBounds`, `ExactTeleport`), `getPortalPosition` (a set exit is used exactly when `exactTeleport`, else `findExitPosition`; only an unset exit in the End is searched for or created), `setExitPosition`. ## How I checked it Headless game in throwaway `HORIZON_HOME`/launcher/XDG folders, driven with `horizon-ctl`, in both `--server-thread` and `--in-frame`, on macOS (build of this branch): - The issue's commands: the player arrives at exactly (8.5, 100, 0.5); on main it arrived at (100, 49, 0). `/data get block` now shows `exit_portal` and `ExactTeleport`. - Without `ExactTeleport` and an obsidian pillar at (9, 110, 10) near the exit (8, 100, 10): the player arrives at (9.5, 111, 10.5), vanilla's `findExitPosition` (tallest block near the exit, plus one). - `ExactTeleport` and no exit, gateway at (300, 100, 0): the exit gateway is created and the side file records `[300,100,0] -> [1028,80,-7]` with exact kept as `true` (the new exit gateway's own entry is `false`), in both modes. - After a trip that created an exit with the gateway's chunk loaded (`forceload`), the side file has no entry for it; `/data remove block 300 100 0 exit_portal` removes the exit and the next trip searches again (a new exit at (1028, 92, -7), the old one was (1028, 80, -7)), in both modes. - Unit tests: NBT round trip and the bounds check (`save.rs`), a generated gateway keeps its worldgen exit (`structure_blocks.rs`), the exit decision, including the fallbacks and the exact flag, and a saved exit moving into a gateway without one (`game/end.rs`). Not covered: the parity harnesses (`--quick`); CI picks them. A gateway whose chunk is already unloaded when its exit is created keeps that exit in the side file until it is used again; if that gateway is replaced with a new one before then, the new one inherits the old entry (not tracked: there is no hook for a gateway block being replaced, and this is how every old save behaves). An exact teleport that lands inside the exit gateway block is entered again at once, because Horizon has no portal cooldown for gateway travel; that is the same before and after this change and not touched here. ## Self-check `python3 tools/pr_ready.py --quick --base upstream/main` on macOS (Python 3.13): | Check | Result | | --- | --- | | Scope | ✅ 7 files, +363 −30 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 s) | | tests: horizon-client | ✅ 1341 passed (4 min 35 s) | | doc tests | ✅ 0 passed (6 s) | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | Label: a fix, none. 🤖 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:16:38 +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#4365
No description provided.