From 092bf87012689b9acab470d06d0a50fa250a8691 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 19 Oct 2026 11:11:44 +0200 Subject: [PATCH 1/2] Server: a guest's projectiles are theirs (ender pearls take them) A projectile a guest shot was recorded as the local player's (Who::Player), which on a server means the host, or nobody on a dedicated server. So a guest's ender pearl teleported the host on a LAN world and did nothing on a dedicated server, what it hit answered to the host, and clients were told the projectile had no owner. Projectiles now remember the guest who shot them (Projectile.guest, set when the guest's turn ends). Clients get the guest as the owner (Projectile.getAddEntityPacket), and the hit runs as that guest: their pearl teleports and hurts them, and the mob hit answers to them. ThrownEnderpearl's endermite also needs monsters to spawn, and comes where the player was. The dedicated-server harness checks that the snowballs' owner is the player and throws an ender pearl at the player's feet: vanilla teleports it and takes 5 health, main did neither. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/creatures.rs | 52 +++++++++++++++++-- crates/horizon-client/src/game/lan_actions.rs | 11 ++++ .../horizon-client/src/game/lan_entities.rs | 6 ++- crates/horizon-client/src/projectiles.rs | 4 ++ .../parity/VanillaProtocolClient.java | 31 ++++++++++- tools/test_dedicated_server_parity.py | 6 ++- 6 files changed, 102 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index d82e8a5aa..db793d993 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -1661,10 +1661,48 @@ impl Game<'_> { } self.creatures.projectiles.append(&mut projectiles); for (p, hit) in hits { - self.projectile_hit(&p, hit)?; + // A guest's projectile lands as theirs: a pearl takes them, what + // it hurts answers to them. One hitting the host (`Who::Player` + // here) stays the host's hit. + match p.guest { + Some(conn) + if !matches!( + hit, + Hit::Entity { + who: Who::Player, + .. + } + ) => + { + self.guest_projectile_hit(conn, &p, hit)?; + } + _ => self.projectile_hit(&p, hit)?, + } } Ok(()) } + /// `projectile_hit` for a projectile the guest `conn` shot, run as them; + /// as the host's when they have left. + fn guest_projectile_hit(&mut self, conn: u32, p: &Projectile, hit: Hit) -> Result<()> { + let Some(mut host) = self.lan.take() else { + return self.projectile_hit(p, hit); + }; + let result = self.as_guest(&mut host, conn, |g| g.projectile_hit(p, hit)); + // The mob hit now answers to the guest (LivingEntity.lastHurtByPlayer). + if result.is_some() + && let Hit::Entity { + who: Who::Mob(id), .. + } = hit + && self.mobs.iter().any(|m| m.id == id) + { + host.mob_players.insert(id, conn); + } + self.lan = Some(host); + match result { + Some(r) => r, + None => self.projectile_hit(p, hit), + } + } /// What an arrow's tick asked for: its particles and sounds. fn arrow_event(&mut self, at: Vec3, event: horizon_client::arrows::ArrowEvent) { use horizon_client::arrows::{ArrowEvent, ArrowParticle, ArrowSound, BlockReaction}; @@ -1968,9 +2006,15 @@ impl Game<'_> { m.damage(0.0, source); } if p.owner == Some(Who::Player) && self.player.is_some() { - // ThrownEnderpearl: 5% endermite, teleport, 5 damage. - if self.world.random.next_float() < 0.05 { - self.spawn_mob("minecraft:endermite", atp, false); + // ThrownEnderpearl: 5% endermite where the player was + // (when monsters spawn), teleport, 5 damage. + if self.world.random.next_float() < 0.05 + && self.ui.rules.bool("spawn_monsters") + && self.ui.difficulty != 0 + && let Some(pl) = self.player.as_ref() + { + let from = pl.position; + self.spawn_mob("minecraft:endermite", [from.x, from.y, from.z], false); } if let Some(pl) = self.player.as_mut() { pl.position = at; diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 5f98a401f..6f1c17c3a 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -125,6 +125,8 @@ pub(super) struct GuestSwap { packets: Vec, /// The host's count of swings started, kept while the guest acts. swings: u32, + /// How many projectiles there were: those added since are the guest's. + projectiles: usize, } impl GuestPlay { @@ -298,6 +300,7 @@ impl Game<'_> { ); let packets = std::mem::take(&mut self.guest_packets); let swings = self.swings_started; + let projectiles = self.creatures.projectiles.len(); Some(GuestSwap { conn, i, @@ -341,6 +344,7 @@ impl Game<'_> { acting, packets, swings, + projectiles, }) } @@ -390,7 +394,14 @@ impl Game<'_> { acting, packets, swings, + projectiles, } = swap; + // What the guest shot is theirs (Projectile.setOwner). + for p in self.creatures.projectiles.iter_mut().skip(projectiles) { + if p.owner == Some(horizon_client::mobs::Who::Player) && p.guest.is_none() { + p.guest = Some(conn); + } + } // The guest's swings are theirs: the host's own count stays the host's. play.swings += self.swings_started.wrapping_sub(swings); self.swings_started = swings; diff --git a/crates/horizon-client/src/game/lan_entities.rs b/crates/horizon-client/src/game/lan_entities.rs index 7a1236e52..020ec6adc 100644 --- a/crates/horizon-client/src/game/lan_entities.rs +++ b/crates/horizon-client/src/game/lan_entities.rs @@ -324,7 +324,11 @@ impl Game<'_> { let mut e = state(p.id, kind, at(p.position), p.yaw, false); e.pitch = p.pitch; e.velocity = at(p.velocity); - e.data = owner(p.owner); + // Projectile.getAddEntityPacket: the owner's id. + e.data = match p.guest.and_then(|conn| hub.guest(conn)) { + Some(g) => g.entity_id, + None => owner(p.owner), + }; match &p.kind { K::Arrow { critical, .. } => { let a = p.arrow.as_deref(); diff --git a/crates/horizon-client/src/projectiles.rs b/crates/horizon-client/src/projectiles.rs index c2d4b4e3a..cc44e7511 100644 --- a/crates/horizon-client/src/projectiles.rs +++ b/crates/horizon-client/src/projectiles.rs @@ -67,6 +67,9 @@ pub struct Projectile { pub id: u32, pub kind: ProjectileKind, pub owner: Option, + /// On a server, the guest (by connection) who shot it: `Who::Player` + /// then means them, not the host. + pub guest: Option, pub position: Vec3, pub previous: Vec3, pub velocity: Vec3, @@ -133,6 +136,7 @@ impl Projectile { id: 0, kind, owner, + guest: None, position, previous: position, velocity: Vec3::ZERO, diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java index bd450e965..3ed121fe9 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java @@ -464,6 +464,11 @@ public final class VanillaProtocolClient { int furnaceState = 0; // Snowballs the server spawned since the last right click. int snowballs = 0; + // The player's own id, and what the ender pearl it throws does to it. + int playerId = -1; + boolean pearl = false; + int pearlTeleports = 0; + float pearlHealth = -1; // The villager the server's console summoned beside the spawn. int villager = -1; net.minecraft.world.phys.Vec3 villagerAt = null; @@ -496,13 +501,20 @@ public final class VanillaProtocolClient { loadStart = true; } } + if (packet instanceof net.minecraft.network.protocol.game.ClientboundLoginPacket p) playerId = p.playerId(); + // The first health after the pearl: the hurt (regeneration follows each server's ticks). + if (pearl && pearlHealth < 0 && packet instanceof net.minecraft.network.protocol.game.ClientboundSetHealthPacket p) { + pearlHealth = p.getHealth(); + } if (packet instanceof ClientboundKeepAlivePacket p) { send(new ServerboundKeepAlivePacket(p.getId())); } else if (packet instanceof ClientboundPingPacket p) { send(new ServerboundPongPacket(p.getId())); } else if (packet instanceof ClientboundPlayerPositionPacket p) { position = PositionMoveRotation.calculateAbsolute(position, p.change(), p.relatives()); - record("play-move", text(position.position()) + " " + position.yRot() + " " + position.xRot()); + // Where a pearl lands follows its random inaccuracy: only counted. + if (pearl) pearlTeleports++; + else record("play-move", text(position.position()) + " " + position.yRot() + " " + position.xRot()); if (respawning) respawnAt = position; send(new ServerboundAcceptTeleportationPacket(p.id(), position.position().x, position.position().y, position.position().z, position.yRot(), position.xRot())); @@ -560,6 +572,8 @@ public final class VanillaProtocolClient { } else if (packet instanceof net.minecraft.network.protocol.game.ClientboundAddEntityPacket p && p.getType() == net.minecraft.world.entity.EntityTypes.SNOWBALL) { snowballs++; + // Projectile.getAddEntityPacket: its owner's id. + record("play-use", "snowball owner is the player: " + (p.getData() == playerId)); } else if (packet instanceof net.minecraft.network.protocol.game.ClientboundAddEntityPacket p && p.getType() == net.minecraft.world.entity.EntityTypes.VILLAGER) { villager = p.getId(); @@ -736,6 +750,21 @@ public final class VanillaProtocolClient { stepAt = now; } else if (step == 16 + REPLIES.length && now - stepAt > 2000) { record("play-use", "off hand on a block: " + snowballs + " snowball(s)"); + // An ender pearl thrown at its feet (no endermite: ThrownEnderpearl spawns one 5% of the time). + send(new ServerboundChatCommandPacket("gamerule spawn_monsters false")); + send(new ServerboundChatCommandPacket("item replace entity @s weapon.offhand with minecraft:air")); + send(new ServerboundChatCommandPacket("item replace entity @s weapon.mainhand with minecraft:ender_pearl")); + step++; + stepAt = now; + } else if (step == 17 + REPLIES.length && now - stepAt > 1500) { + pearl = true; + send(new net.minecraft.network.protocol.game.ServerboundUseItemPacket(net.minecraft.world.InteractionHand.MAIN_HAND, 7, + position.yRot(), 90.0F)); + step++; + stepAt = now; + } else if (step == 18 + REPLIES.length && now - stepAt > 2500) { + // ThrownEnderpearl.onHit: the thrower is teleported and takes 5 damage. + record("play-pearl", "teleported " + pearlTeleports + " time(s), health " + pearlHealth); return; } } diff --git a/tools/test_dedicated_server_parity.py b/tools/test_dedicated_server_parity.py index e23891fa7..83feb250f 100644 --- a/tools/test_dedicated_server_parity.py +++ b/tools/test_dedicated_server_parity.py @@ -16,7 +16,8 @@ chunks load start" event and the chunk under the player), sets a furnace beside itself, gives itself raw iron and coal, sets and asks its own score (`@s`), opens the furnace, shift-clicks the ore and the coal in and the ingot out, right-clicks the ground with a -snowball in the main hand, then in the off hand, and leaves. The +snowball in the main hand, then in the off hand, throws an ender pearl at +its feet, and leaves. The console then runs `list` and `say` and `stop`. Compared, all of them exactly: @@ -37,7 +38,8 @@ exactly: shift-click changes and its lit and cooking totals; - the snowballs each right click throws: one, though the client sends the block's part and the item's of each hand as separate packets - (handleUseItemOn, handleUseItem); + (handleUseItemOn, handleUseItem), and that the player is their owner; +- the ender pearl's teleport of the player who threw it, and the 5 damage; - the console lines about the player (an operator's command feedback, which vanilla broadcasts to the console, included), the chat, `list`, `say` and `stop`; From a480d101577e6b7ce1f6aa7245712501e121dd7b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 19 Oct 2026 11:12:42 +0200 Subject: [PATCH 2/2] docs/server.md: what remote players get right on a dedicated server now (#484) Co-Authored-By: Claude Opus 5.5 --- docs/server.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/server.md b/docs/server.md index e296b66ee..272148d49 100644 --- a/docs/server.md +++ b/docs/server.md @@ -92,7 +92,7 @@ not tick cost, so it is in scope here (see section 9). | Secure chat | **Works** (`SignedMessageChain`, `LastSeenMessagesValidator`, `MessageSignatureCache`): the chat session update and its profile key, checked against the services' `playerCertificateKeys`; signed chat, `say`, `me` and `msg`, relayed with their signatures and last-seen lists; `enforce-secure-profile` (with `online-mode`) refuses unsigned chat; and vanilla's log lines (`[Not Secure]`, the decoder's warnings, the kicks). Offline servers and players without a chat session chat unsigned, as on vanilla. `test_secure_chat_parity.py` runs the same signed and unsigned players against vanilla's server and Horizon's, with test keys and a mock services server. | | Nether and End | **Players can't change dimension.** The engine keeps one dimension loaded (`Game::enter_dimension` moves only the local single-player player), and the hub serves one `dimension` to everyone. | | Refused logins | Logged as vanilla does: `Disconnecting (/address): `, then ` (/address) lost connection: `, and the session errors (`Username '' tried to join with an invalid session`, `Couldn't verify username because servers are unavailable`). | -| Gameplay for remote players | The LAN guest leftovers apply: an item used on a block is used twice, the recipe book doesn't work, status effects don't apply to guests, arrows don't record their owner, team friendly fire is ignored (#484). Block desync and short freezes are reported on a same-machine server (#500). | +| Gameplay for remote players | Checked against vanilla's server with a vanilla-codec client (#484, `tools/test_dedicated_server_parity.py`): a right click with an item on a block uses it once, a dead player's commands run, players on a team without friendly fire don't hurt each other, and a player's projectiles are theirs (their ender pearl takes them). The recipe book, status effects and block sync while digging (#500) work. Left: a player's projectiles don't hit other players (no bow PvP between guests), and a mob a guest kills counts in the host's statistics and advancements, not the guest's (`mob_died` runs as the host). | | Defaults that surprise owners | `white-list=true` is vanilla 26.3's default, so a fresh server refuses everyone until they are added. That matches vanilla, so the first-run flow (section 3) asks about the whitelist up front. | | Management | Only stdin. There is no service, no backups, no status beyond `list`, no restart after a crash, and a server can't be managed while it runs in the background. | | Packaging | The server is the full game client. Resources come from `horizon-prepare`, which needs a JDK and the official launcher's client install, both awkward on a headless VPS. |