The Three-Step Portal Search Algorithm

Portals in Minecraft do not store persistent “paired links” in chunk NBT data. Every single time an entity finishes its portal transition timer (80 gt for survival players on Java, 1 gt in Creative or for non-player entities once their 300 gt portal cooldown equals zero), PortalForcer.findClosestPortalPosition() executes a fresh stateless spatial query in the destination dimension.

Exact Game Formula
Target_Nether = (floor(X_ow / 8), Y_ow, floor(Z_ow / 8)) | d = √((X_p - X_t)² + (Y_p - Y_t)² + (Z_p - Z_t)²)

Horizontal coordinates scale by 1 / 8 (Overworld → Nether) or × 8 (Nether → Overworld), while Y is transferred 1 : 1 without scaling. Inside a horizontal square of ±16 blocks in the Nether (±128 blocks in the Overworld), the active portal block with minimum 3D Euclidean distance d wins; ties break to the lowest Y block.

Notice the critical geometric asymmetry between candidate filtering and candidate ranking:

  1. Coordinate Translation: Stepping into an Overworld portal block at (X_ow, Y_ow, Z_ow) computes an ideal Nether target (X_t, Y_t, Z_t) = (floor(X_ow / 8), Y_ow, floor(Z_ow / 8)). Returning from the Nether at (X_n, Y_n, Z_n) computes an Overworld target (floor(X_n × 8), Y_n, floor(Z_n × 8)), clamped horizontally to the World Border.
  2. Horizontal Chebyshev Square Filter: The Point-of-Interest (PoiManager) registry collects every active purple minecraft:nether_portal block satisfying max(|X_p - X_t|, |Z_p - Z_t|) ≤ R across the entire vertical build height of the destination dimension, where R = 16 blocks in the Nether (a 33 × 33 block column footprint) and R = 128 blocks in the Overworld (a 257 × 257 block column footprint).
  3. 3D Euclidean Minimum Selection: Every candidate portal block inside that square is ranked by full 3D squared distance d² = ΔX² + ΔY² + ΔZ². Only if zero portal blocks exist inside the ±R horizontal square does the game generate a brand-new obsidian frame.
Y=129 Y=70 Y=65 Nether Search Square: X = 100 ± 16 (84..116) Target (100, 70) Roof Portal (100, 129) d = 59.00m (LOSES) Tunnel B (106, 65) d = 7.81m (WINS!) 3D Distance Comparison Roof A: ΔX=0, ΔY=+59 d² = 0² + 59² = 3,481 Tunnel B: ΔX=6, ΔY=-5 d² = 6² + (-5)² = 61 Fix Roof Hub Link: Raise OW A to Y=129 OR move B >16m in X/Z
Figure 2: Even when Roof Portal A shares exact horizontal (100, 100) coordinates with Overworld Portal A, its 59-block vertical gap loses overwhelmingly to Tunnel Portal B (d = 7.81 vs. 59.00).

Numeric Proof: How ΔY² Hijacks Perfect X/8 Portals

Let us walk through two classic survival failures caused by unscaled ΔY².

Case 1: Nether Roof Hub vs. Sub-Roof Tunnel Hijack

Suppose your main Overworld base portal sits at Surface Portal A (800, 70, 800), and 48 blocks east you dig down to a Deepslate slime chunk with Cave Portal B (848, -40, 800). You build Surface A’s Nether hub portal cleanly above bedrock on the Nether roof at (100, 129, 100), and you link Cave B to a sub-roof Nether tunnel at (106, 65, 100).

Now step into Surface Portal A (800, 70, 800):

  • Translated Nether target = (floor(800 / 8), 70, floor(800 / 8)) = (100, 70, 100).
  • Both (100, 129, 100) and (106, 65, 100) fall inside the ±16 horizontal search square (|106 - 100| = 6 ≤ 16).
  • Distance to Roof Portal A (100, 129, 100): d_A = √((100 - 100)² + (129 - 70)² + 0²) = √3,481 = 59.00 blocks.
  • Distance to Tunnel Portal B (106, 65, 100): d_B = √((106 - 100)² + (65 - 70)² + 0²) = √(36 + 25) = √61 = 7.81 blocks.

Because 7.81 < 59.00, Surface Portal A completely ignores its own (100, 129, 100) roof portal and dumps you into Tunnel B! Worse yet, stepping back into Roof Portal A at (100, 129, 100) targets Overworld (800, 129, 800), where Surface A is 59.00 blocks away and Cave B at (848, -40, 800) is √(48² + (-169)²) = 175.68 blocks away—creating an asymmetric one-way trap.

Case 2: Deep Cave Return Hijacked by Surface Portal

Even without the Nether roof, natural portal generation cannot place frames below Y = 32 safely in lava oceans or below Y = 0 in the Nether (where bedrock starts at Y = 0). If Cave Portal B sits at Overworld (848, -44, 800) and its Nether portal sits at (106, 36, 100), returning from (106, 36, 100) targets Overworld (848, 36, 800):

  • Distance to Cave Portal B (848, -44, 800): ΔX = 0, ΔY = -80 → d_B = 80.00 blocks (d² = 6,400).
  • Distance to Surface Portal A (800, 70, 800): ΔX = -48, ΔY = +34 → d_A = √(2,304 + 1,156) = √3,460 = 58.82 blocks!

Despite being 48 blocks off horizontally and aligned to a totally different Nether coordinate, Surface Portal A wins (58.82 < 80.00) because ΔY = -80 penalized the deep-deepslate cave portal by 6,400 squared units! Moving Cave B’s Nether portal down to (106, 10, 100) changes the Overworld target to (848, 10, 800), shrinking d_B to 54.00 while pushing d_A to √(2,304 + 3,600) = 76.84, permanently restoring two-way isolation.

Travel Direction Coordinate Scale Horizontal Search Box Vertical POI Scan Range Max Safe Horizontal Offset When ΔY = 60
Overworld → Nether (Java) floor(X/8), Y, floor(Z/8) ±16 blocks (33×33) Y = 0 .. 255 (includes Nether Roof!) Rival portal must have d > 60 (impossible inside ±16 if rival ΔY < 57.8!)
Nether → Overworld (Java) floor(X×8), Y, floor(Z×8) ±128 blocks (257×257) Y = -64 .. 319 (full build height) Rival at ΔY = 0 hijacks anywhere within |ΔX| < 60 Overworld blocks!
Overworld → Nether (Bedrock) floor(X/8), Y, floor(Z/8) ±16 blocks (33×33) Y = 0 .. 127 (Roof build blocked) Same 3D Euclidean priority inside 0..127 ceiling
Nether → Overworld (Bedrock) floor(X×8), Y, floor(Z×8) ±128 blocks (257×257) Y = -64 .. 319 Same 3D Euclidean priority; entity entry block determines origin

Solving Multi-Portal & Stacked Farm Separation

Two mathematical rules guarantee 100% deterministic two-way portal isolation—even when stacking four portals inside a single 16×16 chunk for two-dimensional guardian, gold, or shulker farms:

  1. Match Exact Y-Elevations Whenever 0 ≤ Y ≤ 127 (or 255 on Java): If Overworld Portal 1 has its lowest obsidian-air block at (800, 64, 800) and Overworld Portal 2 sits directly above it at (800, 92, 800), building their Nether portals at (100, 64, 100) and (100, 92, 100) produces d = 0.00 for each intended mate versus d = 28.00 for the sibling portal. Zero cross-linking can ever occur.
  2. Enforce the Perpendicular Bisector Midpoint for Nether Roof Hubs: If Portal A must sit on the Java Nether roof at Y = 129 while Base Portal A sits at Y = 70 (d_A = 59.0), any nearby sub-roof farm portal B inside the ±16 Nether square must either be placed outside |ΔX| > 16 or |ΔZ| > 16 in the Nether (> 128 blocks away in the Overworld), or you must build a secondary sky/attic return portal for the roof hub at Overworld Y = 120..129 so d_A drops below 9.0 blocks. You can test exact 3D bisector margins instantly in our 3D Nether Portal Linker Calculator.

Java 1.21.4 vs. Bedrock 1.21.50 Portal Parity

Java Edition (1.21.4)

  • Nether build limit is Y = 255, and PoiManager indexes lit portal blocks above Y = 128. Nether-roof portals work two-way once manually constructed (auto-generation still caps below Y = 128).
  • Wide portals evaluate entry from the entity’s exact continuous position (entity.getX(), entity.getY(), entity.getZ()) (preserving relative offset inside wide frames via PortalShape).
  • Entities exiting a portal receive a 300 gt (15.0 s) portal cooldown that only ticks down once they step completely out of portal blocks.

Bedrock Edition (1.21.50)

  • Hard Nether build limit at Y = 128 prevents placing obsidian on the Nether roof entirely; Nether highways must run through upper Netherrack at Y = 115–121.
  • When walking into a wide 21-block gold-farm portal, Bedrock scales the coordinates of the specific portal block touched, so walking into the left vs. right corner shifts the Nether search center by up to 2–3 blocks!
  • Breaking and relighting fast-ticking gold farm portals spawns Zombified Piglins directly without relying on sub-chunk random ticks.
In-Game Verification Test: Verified in Java 1.21.4 at Overworld (800, 70, 800) and (848, -40, 800) using F3+G chunk borders and /data get entity @s Pos upon dimension arrival. With Nether portals lit at (100, 129, 100) and (106, 65, 100), entering (800, 70, 800) routed 10 out of 10 trials to (106, 65, 100). Raising a roof-access portal at Overworld (800, 124, 800) lowered d_roof from 59.00 to 5.00 blocks, immediately separating both two-way portal pairs across 20 consecutive transitions.