Server players go through End gateways

handle_server_portal ignored End gateways, so on a server (dedicated, or
single player's server thread) no player could use one: the in-frame game's
gateway code moved only its own player.

A gateway that is not cooling down now takes a server player at once
(EndGatewayBlock.entityInside, triggerCooldown, setAsInsidePortal), within
the End, keeping its motion and look (Relative.DELTA and ROTATION). An exact
exit is reached straight away; otherwise the player waits at the destination
while it loads, and the exit is found or built there (the in-frame
resolve_gateway, shared through gateway_job).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-22 12:51:16 +02:00
parent 9fe228cd1e
commit 86fdc72069
5 changed files with 117 additions and 22 deletions
+17 -9
View File
@@ -23,7 +23,7 @@ const GATEWAY_FILE: &str = "horizon-end-gateways.json";
/// A gateway teleport waiting for its destination chunks.
#[derive(Clone, Copy, Debug)]
enum GatewayJob {
pub(super) enum GatewayJob {
/// TheEndGatewayBlockEntity.findOrCreateValidTeleportPos from this gateway.
Find { gateway: [i32; 3] },
/// A known exit (exact, or findExitPosition around it).
@@ -735,6 +735,20 @@ impl Game<'_> {
fn enter_gateway(&mut self, gateway: [i32; 3]) -> Result<()> {
// TheEndGatewayBlockEntity.triggerCooldown: 40 ticks.
self.end.gateway_cooldown = 40;
let (job, destination) = self.gateway_job(gateway);
let Some(player) = self.player.take() else {
return Ok(());
};
self.end.job = Some(job);
self.end_travel = true;
self.travelling = Some((player, destination));
Ok(())
}
/// Where `gateway` leads (TheEndGatewayBlockEntity.getPortalPosition):
/// its exit, or the search for one, and the spot to load before either
/// is resolved ([`Game::resolve_gateway`]).
pub(super) fn gateway_job(&mut self, gateway: [i32; 3]) -> (GatewayJob, Vec3) {
let known = self.gateway_exits().get(&gateway).copied();
let job = match known {
Some((exit, exact)) => GatewayJob::Known { exit, exact },
@@ -760,13 +774,7 @@ impl Game<'_> {
Vec3::new(d.x, 75.0, d.y)
}
};
let Some(player) = self.player.take() else {
return Ok(());
};
self.end.job = Some(job);
self.end_travel = true;
self.travelling = Some((player, destination));
Ok(())
(job, destination)
}
fn chunk_empty(&self, x: f64, z: f64) -> Option<bool> {
@@ -803,7 +811,7 @@ impl Game<'_> {
/// The teleport position of a gateway job, creating the exit gateway (and
/// an island when the chunk has no landing spot) for new destinations.
fn resolve_gateway(&mut self, job: GatewayJob, target: Vec3) -> Result<Vec3> {
pub(super) fn resolve_gateway(&mut self, job: GatewayJob, target: Vec3) -> Result<Vec3> {
let bottom_center = |p: [i32; 3]| {
Vec3::new(
f64::from(p[0]) + 0.5,
@@ -7,6 +7,7 @@
//! another level: a Respawn packet keeping all data, then a teleport to the
//! exit once the destination has loaded around them.
use super::end::GatewayJob;
use super::nether_portal::{PLAYER_DELAY, Plan};
use super::{Dim, Game, lan::LanHost};
use horizon_client::lan::hub::TickCtx;
@@ -22,6 +23,9 @@ pub(super) struct Trip {
end: bool,
/// The Nether portal plan, whose exit is found or built on arrival.
plan: Option<Plan>,
/// Through an End gateway, within the level: its exit, found or built
/// on arrival.
gateway: Option<GatewayJob>,
/// Sent by a command: the player is already where it goes.
placed: bool,
}
@@ -95,7 +99,7 @@ impl Game<'_> {
if let Some(pos) = self.nether_portal_inside(at) {
self.portals.player.set_inside(pos, PLAYER_DELAY);
}
let (end_portal, _) = self.inside_end_portals(at, WIDTH, HEIGHT);
let (end_portal, gateway) = self.inside_end_portals(at, WIDTH, HEIGHT);
if end_portal {
if self.portals.player.cooldown == 0 {
let target = if self.dim == Dim::End {
@@ -109,6 +113,19 @@ impl Game<'_> {
self.portals.player.cooldown = 10;
return;
}
// EndGatewayBlock.entityInside: a gateway that is not cooling down
// takes the player at once (no transition time) and cools down
// (triggerCooldown), even for a player still on its own cooldown.
if let Some(g) = gateway
&& self.gateway_enter(g)
{
if self.portals.player.cooldown == 0 {
self.start_gateway_trip(host, conn, g);
}
// setPortalCooldown: after the trip, or again while cooling down.
self.portals.player.cooldown = 10;
return;
}
let rule = if invulnerable {
"players_nether_portal_creative_delay"
} else {
@@ -197,6 +214,7 @@ impl Game<'_> {
target: destination,
end,
plan,
gateway: None,
placed: false,
});
if let Err(e) = self.enter_level(Some(host), source) {
@@ -204,6 +222,32 @@ impl Game<'_> {
}
}
/// `TheEndGatewayBlockEntity.getPortalPosition` and the teleport within
/// the End (keeping the player's motion and look): straight to an exact
/// exit, else once the destination has loaded around the player, who
/// waits there (its exit is found among those blocks, or built).
fn start_gateway_trip(&mut self, host: &mut LanHost, conn: u32, gateway: [i32; 3]) {
let Some(i) = host.hub.guests.iter().position(|g| g.conn == conn) else {
return;
};
let (job, destination) = self.gateway_job(gateway);
let at = [destination.x, destination.y, destination.z];
// Relative.union(DELTA, ROTATION).
host.hub.teleport_keeping_motion(i, at);
if let GatewayJob::Known { exact: true, .. } = job {
return;
}
self.server_trips.push(Trip {
conn,
dim: self.dim,
target: destination,
end: false,
plan: None,
gateway: Some(job),
placed: false,
});
}
/// The trips into the level in place whose destination has loaded
/// around their target: the exit (the Nether portal found or built, the
/// End platform, the Overworld's spawn column) and the teleport there.
@@ -232,7 +276,15 @@ impl Game<'_> {
}
self.resolve_arrivals();
let yaw = host.hub.guests[i].yaw;
let (position, yaw) = if trip.end {
let (position, yaw) = if let Some(job) = trip.gateway {
match self.resolve_gateway(job, trip.target) {
Ok(at) => (at, yaw),
Err(e) => {
log::error!("End gateway exit: {e}");
(trip.target, yaw)
}
}
} else if trip.end {
match self.end_arrival(trip.target) {
Ok((at, turned)) => (at, turned.unwrap_or(yaw)),
Err(e) => {
@@ -293,6 +345,7 @@ impl Game<'_> {
target: Vec3::new(t.at[0], t.at[1], t.at[2]),
end: false,
plan: None,
gateway: None,
placed: true,
});
if let Err(e) = self.enter_level(Some(host), source) {
+18 -3
View File
@@ -818,6 +818,20 @@ impl Hub {
/// ServerGamePacketListenerImpl.teleport: move the client and wait for its confirmation.
pub fn teleport(&mut self, i: usize, position: Option<[f64; 3]>) {
self.teleport_relative(i, position, 0);
}
/// A teleport to `position` that keeps the player's motion and look
/// (`Relative.DELTA` and `Relative.ROTATION`: an End gateway's).
pub fn teleport_keeping_motion(&mut self, i: usize, position: [f64; 3]) {
use play::relative::{DELTA_X, DELTA_Y, DELTA_Z, ROTATE_DELTA, X_ROT, Y_ROT};
let relatives = Y_ROT | X_ROT | DELTA_X | DELTA_Y | DELTA_Z | ROTATE_DELTA;
self.teleport_relative(i, Some(position), relatives);
}
/// ServerGamePacketListenerImpl.teleport with `relatives`: the rotation
/// and motion they name are sent as zero changes.
fn teleport_relative(&mut self, i: usize, position: Option<[f64; 3]>, relatives: i32) {
let ticks = self.ticks;
let g = &mut self.guests[i];
g.teleport_tick = ticks;
@@ -828,13 +842,14 @@ impl Hub {
g.teleport_counter = (g.teleport_counter + 1) & 0x7FFF_FFFF;
let id = g.teleport_counter;
g.awaiting_teleport = Some((id, g.position));
let turn = relatives & (play::relative::Y_ROT | play::relative::X_ROT) != 0;
g.send(&C::PlayerPosition(play::PlayerPosition {
teleport: id,
position: g.position,
delta: [0.0; 3],
yaw: g.yaw,
pitch: g.pitch,
relatives: 0,
yaw: if turn { 0.0 } else { g.yaw },
pitch: if turn { 0.0 } else { g.pitch },
relatives,
}));
}
+2 -2
View File
@@ -17,7 +17,7 @@ the other dimensions' levels as `Parked` values and swaps one into place (`enter
| `MinecraftServer.levels` | the level in place plus `Levels::parked` |
| `MinecraftServer.tickChildren`, every level | `tick_server`: each level with a player in it, in Overworld, Nether, End order. The first pass reads the network and runs the shared parts (clock, weather, functions, autosave). |
| `ServerLevel.players` | `Hub::here`: the guests whose `dimension` is the level in place |
| `ServerPlayer.teleport` into another level | `server_travel.rs`: a Respawn packet, then the teleport once the destination has loaded (portals and `execute in … tp`) |
| `ServerPlayer.teleport` into another level | `server_travel.rs`: a Respawn packet, then the teleport once the destination has loaded (portals and `execute in … tp`). An End gateway teleports within the End. |
| `PlayerList.respawn` | `guest_respawn`: back into the Overworld's level |
| `ServerLevel.noPlayersEmptyTime`, chunk unloading | `close_idle_levels`: a level other than the Overworld with nobody in it for 300 ticks is saved and closed |
| `CommandSourceStack.getLevel` | `with_source` puts the source's level in place for a command (`execute in`, `execute at` a player in another level) |
@@ -78,7 +78,7 @@ the Nether, or whose host saves and quits, joins again in the Nether where it wa
- The guest leaves in the Nether and joins again there.
- The guest dies in the Nether and respawns in the Overworld.
- The host takes a Nether portal alone.
- The guest takes an End portal and then the exit portal alone.
- The guest takes an End portal, an End gateway and then the exit portal alone.
- The host saves, quits and opens the world again with the guest in the Nether, and the guest
joins again there.
+25 -6
View File
@@ -71,8 +71,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
teleports into another level, and `execute in` and `at` change and test blocks there;
mobs fall in two levels at once, with ids unique across them; the guest rejoins in the
Nether, dies there and respawns in the Overworld; the host takes a Nether portal alone;
the guest takes an End portal and the exit portal alone; and the host saves, quits and
reopens with the guest in the Nether.
the guest takes an End portal, an End gateway and the exit portal alone; and the host
saves, quits and reopens with the guest in the Nether.
- commands: the guest's chat completes commands and their arguments over the server's command
tree (Tab), and runs what it completed;
- recipes: the guest's recipe book lists the planks recipe the logs unlock, and clicking it
@@ -699,8 +699,8 @@ def level_host_nether(host, guest, out):
def level_guest_end(host, guest, out):
"""The guest steps into an End portal alone and lands on the obsidian platform; an exit portal
takes it back to the Overworld."""
"""The guest steps into an End portal alone and lands on the obsidian platform, an End gateway
takes it across the End, and an exit portal takes it back to the Overworld."""
x, y, z = (int(v // 1) for v in pos_of(guest))
guest('command', command=f'setblock {x + 2} {y} {z} minecraft:end_portal')
try:
@@ -714,13 +714,32 @@ def level_guest_end(host, guest, out):
assert [int(v // 1) for v in landed] == [100, 49, 0], f'the guest landed at {landed}'
finally:
guest('command', command=f'execute in {OVERWORLD} run setblock {x + 2} {y} {z} minecraft:air')
ex, ey, ez = (int(v // 1) for v in landed)
# A gateway far out with an exact exit at the End spawn, as end_gateway_return's
# (TheEndGatewayBlockEntity.getPortalPosition), takes the guest back there within the End.
guest('command', command='tp @s 700.5 80 0.5')
guest.wait(60)
level_floor(guest, 700, 80, 0)
guest('command', command='tp @s 700.5 80 0.5')
guest.wait(20)
guest('command', command='setblock 702 80 0 minecraft:end_gateway{exit_portal:[I;100,50,0],exact_teleport:1b}')
guest('command', command='tp @s 702.5 80 0.5')
gateway = None
for _ in range(20):
guest.wait(10)
gateway = pos_of(guest)
if abs(gateway[0] - 702.5) > 50:
break
assert dims(host, guest) == (OVERWORLD, END), f'host, guest in {dims(host, guest)}'
assert abs(gateway[0] - 100.5) < 1 and abs(gateway[2] - 0.5) < 1 and 49 <= gateway[1] <= 50, \
f'the gateway left the guest at {gateway}'
guest.wait(40)
ex, ey, ez = (int(v // 1) for v in pos_of(guest))
guest('command', command=f'setblock {ex + 2} {ey} {ez} minecraft:end_portal')
guest('command', command=f'tp @s {ex + 2.5} {ey} {ez + 0.5}')
home = wait_dimension(guest, OVERWORLD, 600)
guest.wait(20)
assert dims(host, guest) == (OVERWORLD, OVERWORLD), f'host, guest in {dims(host, guest)}'
return {'landed': landed, 'home': home['player']['position']}
return {'landed': landed, 'gateway': gateway, 'home': home['player']['position']}
def level_reload(host, guest, out):