Merge pull request #1314 from ludovic111/fix/server-riding

🤖 Agent: merged after verify passed and the local parity run (102 of 102, posted on the PR); lan_e2e riding passes in both modes.
This commit is contained in:
Ludovic Marie
2026-10-23 01:29:03 +02:00
committed by GitHub
8 changed files with 224 additions and 33 deletions
@@ -330,6 +330,10 @@ impl Game<'_> {
"held": m.extra.main_hand.as_deref(),
"mount": m.extra.mount,
"rider": m.extra.rider,
// A player's input this tick, and whether it steers.
"ridden": m.rider.map(|r| r.steer),
"controlled": horizon_client::mobs::equine::controlled(m),
"saddled": m.extra.saddled,
"enchants": horizon_client::mobs::gear::gear(m).map(|g| g.slots.iter().map(|s| s.iter().map(|(e, l)| format!("{e}:{l}")).collect::<Vec<_>>()).collect::<Vec<_>>()),
"ints": m.extra.ints,
"pois": [m.extra.home, m.extra.bed, m.extra.meeting],
+10
View File
@@ -800,6 +800,16 @@ impl Game<'_> {
self.send_admin_feedback(&mut host, None);
}
let state = self.lan_host_state(&host);
// An animal whose rider left the game (or the level) stops taking
// its input.
for m in &mut self.mobs {
if m.rider.is_some()
&& self.riding != Some(m.id)
&& !host.hub.guests.iter().any(|g| g.vehicle == Some(m.id))
{
m.rider = None;
}
}
// A dedicated server runs the hub without a host player.
if state.is_some() || host.hub.config.dedicated {
let has_guests = !host.hub.guests.is_empty();
@@ -49,6 +49,8 @@ pub(super) struct GuestPlay {
/// Swings the guest's actions started this tick, for the players around
/// (`LivingEntity.swing` sends ClientboundSwingAnimationPacket).
swings: u32,
/// The guest's riding jump charge (`LocalPlayer.jumpRidingTicks`).
mount: super::mounts::MountState,
/// The trading screen the guest has open.
pub(super) merchant: Option<super::lan_trading::GuestMerchant>,
/// The inventory menu and the crafting table the guest crafts in.
@@ -289,6 +291,7 @@ impl Game<'_> {
let attack_ticks = std::mem::replace(&mut self.attack_ticks, play.attack_ticks);
let attack_item = std::mem::replace(&mut self.attack_item, play.attack_item.take());
let swing = std::mem::replace(&mut self.swing, play.swing);
std::mem::swap(&mut self.mount, &mut play.mount);
let (left, right) = (self.left, self.right);
self.left = play.digging.is_some();
self.right = play.using.is_some() || self.using.is_some();
@@ -478,6 +481,7 @@ impl Game<'_> {
play.attack_ticks = std::mem::replace(&mut self.attack_ticks, attack_ticks);
play.attack_item = std::mem::replace(&mut self.attack_item, attack_item);
play.swing = std::mem::replace(&mut self.swing, swing);
std::mem::swap(&mut self.mount, &mut play.mount);
self.container = container;
self.screen = screen;
self.sign_edit = host_sign;
+24 -4
View File
@@ -26,6 +26,7 @@ pub(super) fn input_keys(flags: u8) -> Keys {
right: flags & 8 != 0,
jump: flags & 16 != 0,
shift: flags & 32 != 0,
sprint: flags & 64 != 0,
..Keys::default()
}
}
@@ -96,9 +97,10 @@ impl Game<'_> {
let (keys, dead) = (input_keys(g.input), g.dead || g.health <= 0.0);
let boat = self.boats.iter().position(|b| b.id == vehicle);
let cart = self.carts.iter().any(|c| c.id == vehicle);
let mount = self.mobs.iter().any(|m| m.id == vehicle);
// The vehicle is gone (broken, in another level) or the rider died:
// its client drops it with the entity or the death screen.
if dead || (boat.is_none() && !cart) {
if dead || (boat.is_none() && !cart && !mount) {
let g = &mut host.hub.guests[gi];
(g.vehicle, g.vehicle_good) = (None, None);
return;
@@ -122,8 +124,12 @@ impl Game<'_> {
return Some([p.x, p.y + SEAT, p.z]);
}
// The minecart moves with the rider's input, and lets it out when
// it sneaks or the cart breaks.
game.tick_cart_riding(keys);
// it sneaks or the cart breaks. An animal takes the rider's input
// for its own tick (`travelRidden`), or lets it off.
if !game.tick_cart_riding(keys) && game.tick_mount_riding(keys) {
game.riding?;
game.position_rider();
}
game.riding?;
let p = game.player.as_ref()?.position;
Some([p.x, p.y, p.z])
@@ -163,12 +169,26 @@ impl Game<'_> {
.find(|c| c.id == vehicle)
.map(|c| c.position)
});
let g = &mut host.hub.guests[gi];
if let Some(p) = at {
let g = &mut host.hub.guests[gi];
g.vehicle_good = Some([p.x, p.y, p.z]);
g.previous_position = g.position;
g.position = [p.x, p.y + SEAT, p.z];
g.on_ground = false;
return;
}
// An animal: the rider sits where `positionRider` puts it.
let seat = self.as_guest(host, conn, |game| {
game.position_rider();
game.player
.as_ref()
.map(|p| [p.position.x, p.position.y, p.position.z])
});
if let Some(Some(at)) = seat {
let g = &mut host.hub.guests[gi];
g.previous_position = g.position;
g.position = at;
g.on_ground = false;
}
}
+29 -19
View File
@@ -107,6 +107,10 @@ impl Game<'_> {
let held = self.inventory[self.selected].clone();
let m = &self.mobs[index];
let species = m.species();
// A server player rides it already (`isVehicle`: no seat, no feeding).
if self.ridden_by_guest(m.id) {
return false;
}
if matches!(species, Species::Pig | Species::Strider) {
return self.interact_steerable(index, item);
}
@@ -246,24 +250,9 @@ impl Game<'_> {
self.consume_held();
true
}
/// The rider's input for this tick; returns false when not on a mount.
pub(super) fn tick_mount_riding(&mut self, keys: Keys) -> bool {
let Some(i) = self.mount_index() else {
return false;
};
if keys.shift || !self.mobs[i].alive() {
self.dismount_mount();
return true;
}
let strafe = f32::from(u8::from(keys.left)) - f32::from(u8::from(keys.right));
let forward = f32::from(u8::from(keys.forward)) - f32::from(u8::from(keys.backward));
// LocalPlayer.aiStep: the riding jump charges while space is held.
let held = self.held().map(|s| s.item.clone());
let steer = match self.mobs[i].species() {
Species::Pig => held.as_deref() == Some("minecraft:carrot_on_a_stick"),
Species::Strider => held.as_deref() == Some("minecraft:warped_fungus_on_a_stick"),
_ => false,
};
/// `LocalPlayer.aiStep`'s riding jump: the bar charges while jump is
/// held; on release, the jump's strength (0 when there is none).
pub(super) fn charge_mount_jump(&mut self, i: usize, keys: Keys) -> f32 {
// PlayerRideableJumping: horses, camels and nautili (the dash).
let saddled = self.mobs[i].extra.saddled
&& (equine::is_equine(self.mobs[i].species())
@@ -299,6 +288,27 @@ impl Game<'_> {
}
st.was_jumping = keys.jump;
}
jump
}
/// The rider's input for this tick; returns false when not on a mount.
pub(super) fn tick_mount_riding(&mut self, keys: Keys) -> bool {
let Some(i) = self.mount_index() else {
return false;
};
if keys.shift || !self.mobs[i].alive() {
self.dismount_mount();
return true;
}
let strafe = f32::from(u8::from(keys.left)) - f32::from(u8::from(keys.right));
let forward = f32::from(u8::from(keys.forward)) - f32::from(u8::from(keys.backward));
// LocalPlayer.aiStep: the riding jump charges while space is held.
let held = self.held().map(|s| s.item.clone());
let steer = match self.mobs[i].species() {
Species::Pig => held.as_deref() == Some("minecraft:carrot_on_a_stick"),
Species::Strider => held.as_deref() == Some("minecraft:warped_fungus_on_a_stick"),
_ => false,
};
let jump = self.charge_mount_jump(i, keys);
let m = &mut self.mobs[i];
if jump > 0.0 {
// onPlayerJump: rear while jumping (horses).
@@ -324,7 +334,7 @@ impl Game<'_> {
pitch: self.pitch,
jump: if jump > 0.0 { jump } else { pending },
steer,
sprint: self.keys.contains(&winit::keyboard::KeyCode::ControlLeft),
sprint: keys.sprint || self.keys.contains(&winit::keyboard::KeyCode::ControlLeft),
jumping: keys.jump,
});
true
@@ -112,6 +112,14 @@ impl Game<'_> {
let Some(id) = self.riding else {
return false;
};
if let Some(i) = self.mobs.iter().position(|m| m.id == id) {
// An animal moves on the server with the rider's input
// (PlayerInput); here the jump bar charges for the HUD and the
// rider sits where `positionRider` puts it.
self.charge_mount_jump(i, keys);
self.position_rider();
return true;
}
let seat = if let Some(i) = self.boats.iter().position(|b| b.id == id) {
// AbstractBoat.tick on the controlling client: steer and move.
let mut b = self.boats[i].clone();
+14 -8
View File
@@ -338,15 +338,21 @@ pub fn ridden_step(m: &mut Mob) {
// Pig/Strider: always forward along the rider's look, at a fraction
// of the movement speed, boosted by the stick.
m.head_pitch = r.pitch * 0.5;
m.ai.xxa = 0.0;
m.ai.zza = 1.0;
// Strider.getRiddenSpeed: slower while it shivers out of the warmth.
let factor = if m.species() == Species::Pig {
0.225
} else if super::strider::suffocating(m) {
0.35
} else {
0.55
};
let boost = boost_factor(m);
m.set_speed((m.attrs.speed * factor) as f32 * boost);
// travelRidden: setSpeed(getRiddenSpeed), then travel(getRiddenInput);
// the input is set after the speed (Mob.setSpeed also sets zza).
// getAttributeValue(MOVEMENT_SPEED): with the cold strider's modifier.
m.set_speed((m.movement_speed() * factor) as f32 * boost);
m.ai.xxa = 0.0;
m.ai.zza = 1.0;
return;
}
if super::camel::is_camel(m.species()) {
@@ -366,14 +372,14 @@ pub fn ridden_step(m: &mut Mob) {
} else {
r.forward
};
m.ai.xxa = r.strafe * 0.5;
m.ai.zza = forward;
let bonus = if r.sprint && m.extra.anim_ticks == 0 {
0.1
} else {
0.0
};
m.set_speed(m.attrs.speed as f32 + bonus);
m.set_speed(m.movement_speed() as f32 + bonus);
m.ai.xxa = r.strafe * 0.5;
m.ai.zza = forward;
if r.jump > 0.0 {
let mut ev = Vec::new();
super::camel::dash(m, r.jump, &mut ev);
@@ -394,10 +400,10 @@ pub fn ridden_step(m: &mut Mob) {
} else {
r.forward
};
let speed = m.movement_speed() as f32;
m.set_speed(speed);
m.ai.xxa = r.strafe * 0.5;
m.ai.zza = forward;
let speed = m.attrs.speed as f32;
m.set_speed(speed);
if m.on_ground && r.jump > 0.0 {
// executeRidersJump
let impulse = m.extra.vector[0] as f32 * r.jump;
+131 -2
View File
@@ -123,6 +123,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
it (#1222).
- frames: the host and the guest each put a diamond in an item frame and turn it, and put a
helmet on an armor stand and take it back (#1222).
- riding: the host and the guest each saddle and ride a horse (walk, jump), a pig and a strider
(with their sticks), a camel and a donkey, sit on a llama and fly a happy ghast, and
get off by sneaking; the other side sees the animal move.
- lightning: a bolt summoned beside the host, then the guest: both sides get the bolt and flash the
sky (on its server thread the host's window is a client of it too).
- flight: a player in creative double-taps jump and flies, stays up, and stops flying in survival:
@@ -166,7 +169,7 @@ ROOT = Path(__file__).resolve().parents[1]
GUEST_NAME = 'Guest'
# The host plays single player on its server thread (--server-thread).
SERVER_THREAD = False
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning']
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding']
class Game:
@@ -2509,6 +2512,132 @@ def check_frames(host, guest, out):
return result
# Animals a player rides: (kind, summon NBT, what readies it, what is held to ride, the test
# while riding). `move` walks forward, `jump` charges the horse's jump bar, `rise` holds jump on
# a happy ghast, `sit` only rides (a llama goes where it likes).
RIDES = [
('horse', '{Tame:1b}', 'minecraft:saddle', None, 'move jump'),
('pig', '', 'minecraft:saddle', 'minecraft:carrot_on_a_stick', 'move'),
('strider', '', 'minecraft:saddle', 'minecraft:warped_fungus_on_a_stick', 'move'),
('camel', '', 'minecraft:saddle', None, 'move'),
('donkey', '{Tame:1b}', 'minecraft:saddle', None, 'move'),
('llama', '{Tame:1b}', None, None, 'sit'),
('happy_ghast', '', 'minecraft:white_harness', None, 'rise'),
]
HEIGHTS = {'horse': 1.6, 'donkey': 1.5, 'pig': 0.9, 'strider': 1.7, 'camel': 2.375, 'llama': 1.87,
'happy_ghast': 4.0}
def mob_seen(game, mob_id):
found = [m for m in game.raw('mobs', 96).get('near', []) if m['id'] == mob_id]
return found[0] if found else None
def hold(game, key, ticks):
game.raw('key', key, 'down')
game.wait(ticks)
game.raw('key', key, 'up')
def ride(player, other, label, spot, kind, nbt, ready, stick, test):
"""Summon `kind` in front of `player`, ready it (saddle, harness), get on with a right click,
run `test`, and get off by sneaking. The other side sees the animal move."""
x, y, z = spot
# In reach (3 blocks), clear of the player: a happy ghast is 4 blocks wide.
at = (x + 0.5, z + {'happy_ghast': 3.2, 'camel': 3.0}.get(kind, 2.5))
# The first item in hand before it appears: a happy ghast drifts out of reach quickly.
player('command', command=f'item replace entity @s weapon.mainhand with {ready or stick or "minecraft:air"}')
player('command', command=f'summon minecraft:{kind} {at[0]} {y} {at[1]} {nbt}')
player.wait(3)
found = [m for m in player.raw('mobs', 16).get('near', []) if m['kind'].endswith(kind) and m['health'] > 0]
assert found, f'the {label} sees no {kind}'
mob = found[0]
def click(item):
player('command', command=f'item replace entity @s weapon.mainhand with {item or "minecraft:air"}')
player.wait(2)
m = mob_seen(player, mob['id'])
assert m, f'the {label} lost its {kind}'
p = m['pos']
# Back in front of it if it wandered off (a happy ghast drifts away fast).
if abs(p[0] - (x + 0.5)) > 0.5 or abs(p[2] - at[1]) > 0.5:
player('command', command=f'tp @s {p[0]:.2f} {y} {p[2] - (at[1] - z - 0.5):.2f} 0 0')
player.wait(1)
player.raw('look-at', f'{p[0]:.2f}', f'{p[1] + HEIGHTS[kind] / 2:.2f}', f'{p[2]:.2f}')
player.raw('mouse', 'right', 'click')
player.wait(5)
try:
if ready:
click(ready)
click(stick)
riding = player('status').get('riding')
assert riding == mob['id'], f'the {label} right-clicked the {kind} {mob["id"]}: riding {riding}'
result = {'rode': True}
# South, along the cleared floor.
player.raw('look-at', f'{x + 0.5:.2f}', f'{y + 1.6:.2f}', f'{z + 40.5:.2f}')
player.wait(5)
start = mob_seen(player, mob['id'])['pos']
if 'move' in test:
hold(player, 'w', 60)
player.wait(5)
mine = mob_seen(player, mob['id'])['pos']
theirs = mob_seen(other, mob['id'])
moved = math.dist(start, mine)
assert moved > 1.0, f"the {label}'s {kind} moved {moved:.2f} blocks in 3 s of forward"
assert theirs and math.dist(theirs['pos'], mine) < 1.5, \
f"the other side sees the {label}'s {kind} at {theirs and theirs['pos']}, not {mine}"
seated = pos_of(player)
assert math.dist(seated[::2], mine[::2]) < 1.5, f'the {label} sits at {seated}, its {kind} at {mine}'
result['moved'] = round(moved, 2)
if 'jump' in test:
base = mob_seen(player, mob['id'])['pos'][1]
player.raw('key', 'space', 'down')
player.wait(10)
player.raw('key', 'space', 'up')
top = base
for _ in range(10):
player.wait(2)
top = max(top, mob_seen(player, mob['id'])['pos'][1])
assert top - base > 0.4, f"the {label}'s {kind} jumped {top - base:.2f} blocks"
result['jumped'] = round(top - base, 2)
if 'rise' in test:
base = mob_seen(player, mob['id'])['pos'][1]
hold(player, 'space', 40)
player.wait(5)
rose = mob_seen(player, mob['id'])['pos'][1] - base
assert rose > 0.5, f"the {label}'s {kind} rose {rose:.2f} blocks while it held jump"
result['rose'] = round(rose, 2)
hold(player, 'shift', 10)
player.wait(10)
riding = player('status').get('riding')
assert riding is None, f'sneaking off the {kind}: the {label} still rides {riding}'
return result
finally:
player('command', command=f'kill @e[type=minecraft:{kind},x={x},y={y},z={z},distance=..48]')
player('command', command=f'tp @s {x + 0.5} {y} {z + 0.5} 0 0')
player.wait(5)
def check_riding(host, guest, out):
"""The host (single player, on its server thread or not) and the guest each saddle and ride a
horse (walk and jump), a pig and a strider (with their sticks), a camel and a donkey, sit on a
llama, and harness and fly a happy ghast; they get off by sneaking."""
spots = apart(host, guest)
result = {}
for label, player, other in (('host', host, guest), ('guest', guest, host)):
x, y, z = spots[label]
player('command', command='gamemode survival')
player('command', command=f'fill {x - 3} {y - 1} {z - 3} {x + 4} {y - 1} {z + 40} minecraft:stone')
player('command', command=f'fill {x - 3} {y} {z - 3} {x + 4} {y + 12} {z + 40} minecraft:air')
player.wait(10)
result[label] = {}
# LAN_E2E_RIDES=pig,horse picks some of them.
only = [k for k in os.environ.get('LAN_E2E_RIDES', '').split(',') if k]
for kind, nbt, ready, stick, test in (r for r in RIDES if not only or r[0] in only):
result[label][kind] = ride(player, other, label, (x, y, z), kind, nbt, ready, stick, test)
player('command', command='item replace entity @s weapon.mainhand with minecraft:air')
return result
def check_lightning(host, guest, out):
"""A bolt summoned beside each player: both sides get the bolt entity and flash the sky (the
host's window too on its server thread, FEATURES 4z(f))."""
@@ -2848,7 +2977,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
'xp': check_xp, 'objects': check_objects, 'projectiles': check_projectiles, 'blast': check_blast,
'light': check_light, 'plates': check_plates,
'swings': check_swings, 'cracks': check_cracks,
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict, 'ladder': check_ladder, 'boats': check_boats, 'minecarts': check_minecarts, 'frames': check_frames, 'lightning': check_lightning}
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict, 'ladder': check_ladder, 'boats': check_boats, 'minecarts': check_minecarts, 'frames': check_frames, 'lightning': check_lightning, 'riding': check_riding}
def run(ctl, out, resources, checks):