Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

Only the controlling rider's paddle packets move a boat

MSedgeMCfb37d6424f93
diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs
index d86e16ee1..76a859045 100644
--- a/crates/horizon-client/src/game/lan.rs
+++ b/crates/horizon-client/src/game/lan.rs
@@ -1563,11 +1563,14 @@ impl Game<'_> {
let Some(id) = self.restore_saved_vehicle(uuid, raw.as_ref()) else {
continue;
};
+ host.hub.seat_order += 1;
+ let order = host.hub.seat_order;
let g = &mut host.hub.guests[i];
if let Some(horizon_world::nbt::Tag::Compound(p)) = &mut g.saved {
p.remove(&"RootVehicle".into());
}
g.vehicle = Some(id);
+ g.vehicle_order = order;
g.saved_vehicle = None;
// Pair the stationary restored entities before their passenger packet.
g.moved = true;
diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs
index ad3477478..34187566b 100644
--- a/crates/horizon-client/src/game/lan_actions.rs
+++ b/crates/horizon-client/src/game/lan_actions.rs
@@ -817,12 +817,23 @@ impl Game<'_> {
// inventory key while riding).
let guest_mount = std::mem::replace(&mut self.mount_menu, host_mount_menu).opened_mob();
self.keys = host_keys;
+ // `Entity.addPassenger`: a rider that gets in now sits behind the
+ // players already in the vehicle, which is what tells its
+ // `getControllingPassenger` apart from this one's.
+ let seat_order = (guest_vehicle.is_some() && host.hub.guests[i].vehicle != guest_vehicle)
+ .then(|| {
+ host.hub.seat_order += 1;
+ host.hub.seat_order
+ });
let g = &mut host.hub.guests[i];
let left_vehicle = g.vehicle.filter(|_| guest_vehicle.is_none());
if guest_vehicle.is_none() {
g.vehicle_good = None;
}
g.vehicle = guest_vehicle;
+ if let Some(order) = seat_order {
+ g.vehicle_order = order;
+ }
let fell_asleep = bed.is_some() && g.bed.is_none();
(g.bed, g.sleep_timer, g.spawn) = (bed, guest_sleep_timer, guest_spawn);
g.respawn_elsewhere = guest_respawn.map(|c| c.saved());
diff --git a/crates/horizon-client/src/game/lan_vehicles.rs b/crates/horizon-client/src/game/lan_vehicles.rs
index f67223b98..80ba017da 100644
--- a/crates/horizon-client/src/game/lan_vehicles.rs
+++ b/crates/horizon-client/src/game/lan_vehicles.rs
@@ -419,7 +419,25 @@ impl Game<'_> {
g.position = [seat.x, seat.y, seat.z];
}
- /// `handlePaddleBoat`: the paddles of the boat the player drives.
+ /// `Entity.getControllingPassenger` of a vehicle a server player rides: a
+ /// boat has two seats, and only its first player passenger drives it. The
+ /// window player sits first when it rides; of the server's players it is
+ /// the one that got in first.
+ pub(super) fn guest_controls_vehicle(&self, host: &LanHost, conn: u32, vehicle: u32) -> bool {
+ if self.riding == Some(vehicle) {
+ return false;
+ }
+ host.hub
+ .guests
+ .iter()
+ .filter(|g| g.vehicle == Some(vehicle))
+ .min_by_key(|g| g.vehicle_order)
+ .is_some_and(|g| g.conn == conn)
+ }
+
+ /// `handlePaddleBoat`: the paddles of the boat the player controls
+ /// (`player.getControlledVehicle()`); a passenger in the second seat moves
+ /// no paddle.
pub(super) fn guest_paddle_boat(&mut self, host: &LanHost, conn: u32, paddles: [bool; 2]) {
let vehicle = host
.hub
@@ -427,7 +445,10 @@ impl Game<'_> {
.iter()
.find(|g| g.conn == conn)
.and_then(|g| g.vehicle);
- if let Some(b) = self.boats.iter_mut().find(|b| Some(b.id) == vehicle) {
+ let Some(vehicle) = vehicle.filter(|&v| self.guest_controls_vehicle(host, conn, v)) else {
+ return;
+ };
+ if let Some(b) = self.boats.iter_mut().find(|b| b.id == vehicle) {
b.paddling = paddles;
}
}
diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs
index 250759000..5055fffe8 100644
--- a/crates/horizon-client/src/lan/guest.rs
+++ b/crates/horizon-client/src/lan/guest.rs
@@ -108,6 +108,11 @@ pub struct Guest {
pub input: u8,
/// The boat or minecart the player rides (`Entity.getVehicle`).
pub vehicle: Option<u32>,
+ /// When the player last got into its vehicle, from `Hub.seat_order`:
+ /// `Entity.addPassenger` seats a rider behind the players already in the
+ /// vehicle, so the smallest order on a boat is its controlling rider
+ /// (`getControllingPassenger`).
+ pub vehicle_order: u64,
/// `ServerGamePacketListenerImpl.lastGoodX/Y/Z` of the vehicle it controls.
pub vehicle_good: Option<[f64; 3]>,
pub sprinting: bool,
@@ -354,6 +359,7 @@ impl Guest {
sneaking: false,
input: 0,
vehicle: None,
+ vehicle_order: 0,
vehicle_good: None,
sprinting: false,
fall_flying: false,
diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs
index 5c6c361f3..98d31a772 100644
--- a/crates/horizon-client/src/lan/hub.rs
+++ b/crates/horizon-client/src/lan/hub.rs
@@ -236,6 +236,8 @@ pub struct Hub {
pub guests: Vec<Guest>,
pub(super) sync: Arc<SyncData>,
pub ticks: u64,
+ /// The next `Guest.vehicle_order`: a rider that boards later sits behind.
+ pub seat_order: u64,
/// `Level.soundSeedGenerator`: a fresh `nextLong` per `playSound`.
pub(super) sound_seeds: Mutex<LegacyRandom>,
/// The `player_movement_check` and `elytra_movement_check` game rules,
@@ -536,6 +538,7 @@ impl Hub {
guests: Vec::new(),
sync,
ticks: 0,
+ seat_order: 0,
sound_seeds: Mutex::new(LegacyRandom::new(crate::sound_engine::unique_seed())),
immediate_respawn: false,
movement_checks: (true, true),
diff --git a/tools/test_boat_paddle_reset_parity.py b/tools/test_boat_paddle_reset_parity.py
index 4bd7e17bd..f7751b410 100644
--- a/tools/test_boat_paddle_reset_parity.py
+++ b/tools/test_boat_paddle_reset_parity.py
@@ -3,6 +3,8 @@
Drive both paddles, stop one, stop both, resume one, then dismount without
sending a final paddle packet. Clients must receive the false transitions.
+A boat with two players is driven by its first rider only: the second rider's
+paddle packets leave the metadata alone.
"""
try:
from . import test_locator_bar_parity as net
@@ -32,6 +34,36 @@ for kind in ['oak_boat', 'birch_chest_boat', 'bamboo_raft']:
EXPECTED += [f'{label} {index} {str(value).lower()}' for index, value in changes]
+# Two players in one boat: `ServerGamePacketListenerImpl.handlePaddleBoat`
+# applies a packet only when the sender is the boat's controlling passenger
+# (`player.getControlledVehicle()`), and `Entity.addPassenger` seats the first
+# player in front, so the second rider's paddle packet changes no metadata.
+SCRIPT.append(('two-riders-setup', [
+ 'join Bob',
+ 'cmd Alice kill @e[type=!player]',
+ 'cmd Alice fill -5 79 -5 5 79 5 minecraft:stone',
+ 'cmd Alice fill -5 80 -5 5 80 5 minecraft:water',
+ 'cmd Alice tp @s 0.5 81 0.5',
+ 'cmd Alice summon minecraft:oak_boat 0.5 81 0.5',
+ 'cmd Alice ride @s mount @e[type=minecraft:oak_boat,limit=1]',
+ 'cmd Bob ride @s mount @e[type=minecraft:oak_boat,limit=1]',
+]))
+SCRIPT.append(('two-riders-both', ['paddle Alice true true']))
+SCRIPT.append(('two-riders-second-left', ['paddle Bob true false']))
+SCRIPT.append(('two-riders-second-stop', ['paddle Bob false false']))
+SCRIPT.append(('two-riders-first-right', ['paddle Alice true false']))
+# The first rider gets out, leaving the second alone in the boat: the seat it
+# took over is the one the boat's paddles follow now.
+SCRIPT.append(('two-riders-first-out', ['cmd Alice ride @s dismount']))
+SCRIPT.append(('two-riders-second-alone', ['paddle Bob true true']))
+# Each client that tracks the boat records the same metadata transition, and
+# the transcript groups a player's lines together (Alice joined first).
+EXPECTED += [f'{label} {index} {value}' for _ in ('Alice', 'Bob')
+ for label, index, value in [('two-riders-both', 11, 'true'), ('two-riders-both', 12, 'true'),
+ ('two-riders-first-right', 12, 'false'),
+ ('two-riders-second-alone', 12, 'true')]]
+
+
def shown(lines):
return [f'{p[1].removeprefix("step=")} {p[3]} {p[4]}'
for line in lines if len(p := line.split()) == 5 and p[2] == 'paddle'