[PR #122] [MERGED] Nether portals: vanilla timing and linking; items and mobs travel #2336

Closed
opened 2026-11-02 15:55:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/nether-portals-94


📝 Commits (1)

  • 1f06156 Nether portals: vanilla timing, linking, and items and mobs travel

📊 Changes

18 files changed (+2191 additions, -154 deletions)

View changed files

📝 crates/horizon-client/examples/scene_motion_probe.rs (+32 -0)
📝 crates/horizon-client/src/entity_nbt.rs (+2 -2)
📝 crates/horizon-client/src/game.rs (+16 -138)
📝 crates/horizon-client/src/game/end.rs (+4 -4)
➕ crates/horizon-client/src/game/nether_portal.rs (+722 -0)
📝 crates/horizon-client/src/game/persist.rs (+7 -1)
📝 crates/horizon-client/src/game/render_tick.rs (+1 -1)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/motion.rs (+9 -0)
➕ crates/horizon-client/src/nether_portal.rs (+76 -0)
➕ crates/horizon-world/examples/portal_travel_fixture.rs (+272 -0)
📝 crates/horizon-world/src/level/mod.rs (+1 -0)
➕ crates/horizon-world/src/level/portal_travel.rs (+628 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockUpdateOracle.java (+35 -6)
➕ mods/horizon/src/test/java/dev/horizonlab/parity/VanillaPortalOracle.java (+144 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSceneMotionOracle.java (+18 -0)
📝 tools/test_native_scene_motion.py (+41 -2)
➕ tools/test_nether_portal_parity.py (+182 -0)

📄 Description

What was wrong

#94: "Nether portals do not work in survival mode, nor do items go through them". In a fresh world a survival player standing still did travel. What failed, and failed only in survival:

  • The wait reset to zero on any tick the player's box left the portal. Survival waits 80 ticks, so moving or jumping around in a portal never got through. Creative waits a single tick, so it always worked.
  • The return trip took 15 seconds. Arriving set a 300-tick cooldown that only ran down outside portals. In vanilla, a player's cooldown is 10 ticks: a portal keeps resetting it, so you step out and back in.
  • Return trips built new portals. The overworld exit search looked 32 blocks around, in loaded chunks only. Vanilla looks 128 blocks around, through every saved chunk, so trips usually link back to the portal you came from.
  • Also, nothing but the player could use a portal. Arrivals dropped the player's motion and played block.portal.travel positionally at pitch 1. block.portal.trigger played whenever the timer restarted, and open screens stayed open.

What vanilla does (26.3)

  • NetherPortalBlock.entityInside → Entity.canUsePortal(false) (alive, not a passenger, not asleep; withers never) → setAsInsidePortal:
    • on cooldown, it resets the cooldown to getDimensionChangingDelay(): players 10, others 300;
    • otherwise it starts or refreshes a PortalProcessor.
  • Entity.handlePortal at the start of each tick:
    • counts the cooldown down;
    • processPortalTeleportation decays by 4 when outside, or goes through once portalTime++ >= getPortalTransitionTime;
    • the transition time is 0 for entities and the players_nether_portal_default_delay (80) / _creative_delay (0) gamerule for players by abilities.invulnerable;
    • an expired process is dropped;
    • after going through, the cooldown is set again and isAllowedToEnterPortal checks allow_entering_nether_using_portals.
  • NetherPortalBlock.getPortalDestination builds the arrival:
    • getTeleportationScale (8 / 1/8), clamped to the border;
    • PortalForcer.findClosestPortalPosition searches POIs within 16 blocks going to the Nether, 128 out of it (chunk and section order, nearest then lowest);
    • when nothing is found, createPortal spirals around the target over the MOTION_BLOCKING height, partial and full frame spots, and falls back to a platform clamped to y ≥ 70;
    • BlockUtil.getLargestRectangleAround and PortalShape.getRelativePosition place the entity: LivingEntity, AbstractMinecart and AbstractBoat drop the forward part;
    • createDimensionTransition (0/90° yaw), then findCollisionFreePosition (CollisionGetter.findFreePosition);
    • relative DELTA and ROTATION keep and turn the motion; PLAY_PORTAL_SOUND is level event 1032.
  • LocalPlayer.handlePortalTransitionEffect:
    • closes screens other than chat, death and credits;
    • plays block.portal.trigger as local ambience when the effect starts from 0;
    • the effect grows by 0.0125 a tick inside and shrinks by 0.05 outside.

The fix

  • horizon-world level/portal_travel.rs: PortalForcer (closest portal over POI-ordered candidates, create_portal on Sim), largest_rectangle_around, relative_position, exit_position, find_free_position, collision_free_position, BorderBounds.
  • horizon-client:
    • nether_portal.rs: PortalProcessor and the portal cooldown, as PortalState.

    • game/nether_portal.rs:

      • the player's processor, with the transition delays from the gamerules;
      • arrival at the found or built exit, with the turned yaw and motion and the travel sound;
      • the client effect;
      • items and mobs, swept through portal blocks each tick, going through one tick after entering (300-tick cooldown).

      Only one dimension is loaded at a time, so a travelling entity is saved (with riders, without its leash). It waits in data/horizon_portal_arrivals.dat until the player is in its dimension and its exit area has loaded. Then it gets its exit portal, position, yaw, motion and PortalCooldown, and joins the world.

    • PortalCooldown is read back from saved entities.

    • The exit search reads loaded chunks and, for the rest of the square, saved chunks: POIs exist only in generated chunks, and nether portal blocks are never generated.

    • motion.rs reports InsidePortal from the player's block sweep.

    • end.rs shares the player's cooldown.

Tests

  • New tools/test_nether_portal_parity.py. Each case puts an entity (item, zombie, skeleton, creeper, minecart, arrow, horse, spider, ghast, boat) in a random portal of either dimension. The destination is random:

    • flat, hilly, solid, empty, cave or sea terrain;
    • 0–3 other portals inside and outside the search radius, some without frames;
    • sometimes a tight world border.

    Vanilla runs the real NetherPortalBlock.getPortalDestination over two headless levels of the block update oracle, with real PoiSections holding the destination's portal blocks (VanillaPortalOracle). Horizon runs portal_travel (portal_travel_fixture). Compared: the entry rectangle, offset, approximate exit, found portal, every block the destination changed, and the arrival position (bits) and yaw. 2000/2000 cases match (976 linked, 1024 built), plus 600/600 on another seed.

  • tools/test_native_scene_motion.py gains portal fixtures. Each tick runs portal_tick, the oracle's Entity.handlePortal cooldown and real PortalProcessor without a destination, then the real applyEffectsFromBlocks (NetherPortalBlock.entityInside). The fixtures cover:

    • standing in a portal through the 80-tick wait and the creative delay;
    • the cooldown a portal keeps resetting;
    • walking back and forth;
    • re-entering while the old process decays.

    Client and server: 2,208,881 states match, with 15 passages.

  • The block update oracle's stand-in level gained an optional dimension, border, POIs and heightmap. block_update (40000), dispenser (6000), composter (3000) and level_place (20000) still match.

  • On the Mac mini: cargo clippy --workspace --all-targets -D warnings, cargo fmt --check and cargo test -p horizon-client -p horizon-world (603 passed) pass. tools/check_public_tree.py passes.

  • On a vscreen, in a new survival world:

    • a pig and three diamonds pushed into a lit portal vanished;
    • the player walked in, waited, and arrived in a portal built in the Nether, with the purple overlay while waiting;
    • the pig and the diamonds were waiting there (the player picked the diamonds up);
    • stepping out for a second and back in took the player back to the original overworld portal, at the same relative spot.

Not covered

  • Entities other than items and mobs still don't use nether portals: arrows, other projectiles, minecarts, boats, falling blocks, primed TNT, experience orbs. The destination logic handles them (the harness covers minecarts, boats and arrows); they need their tick paths hooked like items and mobs.
  • A mob carrying the player doesn't travel. Vanilla takes the vehicle with its passengers.
  • An entity in an unloaded dimension doesn't tick until the player gets there. Vanilla ticks it for the 300-tick portal ticket.
  • Ties in the exit search between equally near, equally low portal blocks follow the order Horizon finds them, not a POI section's insertion history.
  • The live PortalCooldown isn't written back when entities are saved; saves keep the value they were loaded with.
  • End portals and gateways keep their own code (not touched here, apart from sharing the cooldown).

Fixes #94

🤖 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/122 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/nether-portals-94` --- ### 📝 Commits (1) - [`1f06156`](https://github.com/horizon-rust/horizon/commit/1f06156649acd14fe4da7e19861fed42c4cd87fb) Nether portals: vanilla timing, linking, and items and mobs travel ### 📊 Changes **18 files changed** (+2191 additions, -154 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/scene_motion_probe.rs` (+32 -0) 📝 `crates/horizon-client/src/entity_nbt.rs` (+2 -2) 📝 `crates/horizon-client/src/game.rs` (+16 -138) 📝 `crates/horizon-client/src/game/end.rs` (+4 -4) ➕ `crates/horizon-client/src/game/nether_portal.rs` (+722 -0) 📝 `crates/horizon-client/src/game/persist.rs` (+7 -1) 📝 `crates/horizon-client/src/game/render_tick.rs` (+1 -1) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/motion.rs` (+9 -0) ➕ `crates/horizon-client/src/nether_portal.rs` (+76 -0) ➕ `crates/horizon-world/examples/portal_travel_fixture.rs` (+272 -0) 📝 `crates/horizon-world/src/level/mod.rs` (+1 -0) ➕ `crates/horizon-world/src/level/portal_travel.rs` (+628 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockUpdateOracle.java` (+35 -6) ➕ `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaPortalOracle.java` (+144 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSceneMotionOracle.java` (+18 -0) 📝 `tools/test_native_scene_motion.py` (+41 -2) ➕ `tools/test_nether_portal_parity.py` (+182 -0) </details> ### 📄 Description ## What was wrong #94: "Nether portals do not work in survival mode, nor do items go through them". In a fresh world a survival player standing still did travel. What failed, and failed only in survival: - **The wait reset to zero** on any tick the player's box left the portal. Survival waits 80 ticks, so moving or jumping around in a portal never got through. Creative waits a single tick, so it always worked. - **The return trip took 15 seconds.** Arriving set a 300-tick cooldown that only ran down outside portals. In vanilla, a player's cooldown is 10 ticks: a portal keeps resetting it, so you step out and back in. - **Return trips built new portals.** The overworld exit search looked 32 blocks around, in loaded chunks only. Vanilla looks 128 blocks around, through every saved chunk, so trips usually link back to the portal you came from. - Also, nothing but the player could use a portal. Arrivals dropped the player's motion and played `block.portal.travel` positionally at pitch 1. `block.portal.trigger` played whenever the timer restarted, and open screens stayed open. ## What vanilla does (26.3) - `NetherPortalBlock.entityInside` → `Entity.canUsePortal(false)` (alive, not a passenger, not asleep; withers never) → `setAsInsidePortal`: - on cooldown, it resets the cooldown to `getDimensionChangingDelay()`: players 10, others 300; - otherwise it starts or refreshes a `PortalProcessor`. - `Entity.handlePortal` at the start of each tick: - counts the cooldown down; - `processPortalTeleportation` decays by 4 when outside, or goes through once `portalTime++ >= getPortalTransitionTime`; - the transition time is 0 for entities and the `players_nether_portal_default_delay` (80) / `_creative_delay` (0) gamerule for players by `abilities.invulnerable`; - an expired process is dropped; - after going through, the cooldown is set again and `isAllowedToEnterPortal` checks `allow_entering_nether_using_portals`. - `NetherPortalBlock.getPortalDestination` builds the arrival: - `getTeleportationScale` (8 / 1/8), clamped to the border; - `PortalForcer.findClosestPortalPosition` searches POIs within 16 blocks going to the Nether, 128 out of it (chunk and section order, nearest then lowest); - when nothing is found, `createPortal` spirals around the target over the `MOTION_BLOCKING` height, partial and full frame spots, and falls back to a platform clamped to y ≥ 70; - `BlockUtil.getLargestRectangleAround` and `PortalShape.getRelativePosition` place the entity: `LivingEntity`, `AbstractMinecart` and `AbstractBoat` drop the forward part; - `createDimensionTransition` (0/90° yaw), then `findCollisionFreePosition` (`CollisionGetter.findFreePosition`); - relative `DELTA` and `ROTATION` keep and turn the motion; `PLAY_PORTAL_SOUND` is level event 1032. - `LocalPlayer.handlePortalTransitionEffect`: - closes screens other than chat, death and credits; - plays `block.portal.trigger` as local ambience when the effect starts from 0; - the effect grows by 0.0125 a tick inside and shrinks by 0.05 outside. ## The fix - `horizon-world` `level/portal_travel.rs`: `PortalForcer` (closest portal over POI-ordered candidates, `create_portal` on `Sim`), `largest_rectangle_around`, `relative_position`, `exit_position`, `find_free_position`, `collision_free_position`, `BorderBounds`. - `horizon-client`: - `nether_portal.rs`: `PortalProcessor` and the portal cooldown, as `PortalState`. - `game/nether_portal.rs`: - the player's processor, with the transition delays from the gamerules; - arrival at the found or built exit, with the turned yaw and motion and the travel sound; - the client effect; - items and mobs, swept through portal blocks each tick, going through one tick after entering (300-tick cooldown). Only one dimension is loaded at a time, so a travelling entity is saved (with riders, without its leash). It waits in `data/horizon_portal_arrivals.dat` until the player is in its dimension and its exit area has loaded. Then it gets its exit portal, position, yaw, motion and `PortalCooldown`, and joins the world. - `PortalCooldown` is read back from saved entities. - The exit search reads loaded chunks and, for the rest of the square, saved chunks: POIs exist only in generated chunks, and nether portal blocks are never generated. - `motion.rs` reports `InsidePortal` from the player's block sweep. - `end.rs` shares the player's cooldown. ## Tests - New `tools/test_nether_portal_parity.py`. Each case puts an entity (item, zombie, skeleton, creeper, minecart, arrow, horse, spider, ghast, boat) in a random portal of either dimension. The destination is random: - flat, hilly, solid, empty, cave or sea terrain; - 0–3 other portals inside and outside the search radius, some without frames; - sometimes a tight world border. Vanilla runs the real `NetherPortalBlock.getPortalDestination` over two headless levels of the block update oracle, with real `PoiSection`s holding the destination's portal blocks (`VanillaPortalOracle`). Horizon runs `portal_travel` (`portal_travel_fixture`). Compared: the entry rectangle, offset, approximate exit, found portal, every block the destination changed, and the arrival position (bits) and yaw. **2000/2000 cases match** (976 linked, 1024 built), plus 600/600 on another seed. - `tools/test_native_scene_motion.py` gains portal fixtures. Each tick runs `portal_tick`, the oracle's `Entity.handlePortal` cooldown and real `PortalProcessor` without a destination, then the real `applyEffectsFromBlocks` (`NetherPortalBlock.entityInside`). The fixtures cover: - standing in a portal through the 80-tick wait and the creative delay; - the cooldown a portal keeps resetting; - walking back and forth; - re-entering while the old process decays. Client and server: 2,208,881 states match, with 15 passages. - The block update oracle's stand-in level gained an optional dimension, border, POIs and heightmap. `block_update` (40000), `dispenser` (6000), `composter` (3000) and `level_place` (20000) still match. - On the Mac mini: `cargo clippy --workspace --all-targets -D warnings`, `cargo fmt --check` and `cargo test -p horizon-client -p horizon-world` (603 passed) pass. `tools/check_public_tree.py` passes. - On a vscreen, in a new survival world: - a pig and three diamonds pushed into a lit portal vanished; - the player walked in, waited, and arrived in a portal built in the Nether, with the purple overlay while waiting; - the pig and the diamonds were waiting there (the player picked the diamonds up); - stepping out for a second and back in took the player back to the original overworld portal, at the same relative spot. ## Not covered - Entities other than items and mobs still don't use nether portals: arrows, other projectiles, minecarts, boats, falling blocks, primed TNT, experience orbs. The destination logic handles them (the harness covers minecarts, boats and arrows); they need their tick paths hooked like items and mobs. - A mob carrying the player doesn't travel. Vanilla takes the vehicle with its passengers. - An entity in an unloaded dimension doesn't tick until the player gets there. Vanilla ticks it for the 300-tick portal ticket. - Ties in the exit search between equally near, equally low portal blocks follow the order Horizon finds them, not a POI section's insertion history. - The live `PortalCooldown` isn't written back when entities are saved; saves keep the value they were loaded with. - End portals and gateways keep their own code (not touched here, apart from sharing the cooldown). Fixes #94 🤖 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-02 15:55:05 +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#2336
No description provided.