Ender pearls: a server always sends the thrower the teleport

ThrownEnderpearl.onHit teleports the owner to oldPosition() (where the
pearl started its last tick) with ServerPlayer.teleport, which sends the
position packet whatever the distance. A guest's turn sent a teleport only
when the player moved more than 0.01 blocks, and the pearl took the hit
point: a pearl thrown at one's feet often lands within that, and the
dedicated_server harness saw "teleported 0 time(s)" where vanilla's server
sends 1 (about one run in four on the desktop).

The pearl now moves the player to its previous position and marks the
teleport (PlayerMotion.teleported), which the end of the guest's turn
sends even when the player stays put.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-22 09:51:21 +02:00
parent e730dc1426
commit 743cc8e069
3 changed files with 20 additions and 6 deletions
+11 -4
View File
@@ -2107,15 +2107,22 @@ impl Game<'_> {
let from = pl.position;
self.spawn_mob("minecraft:endermite", [from.x, from.y, from.z], false);
}
// To where the pearl started its last tick (oldPosition).
let to = p.previous;
if let Some(pl) = self.player.as_mut() {
pl.position = at;
pl.position = to;
pl.velocity = Vec3::ZERO;
pl.fall_distance = 0.0;
pl.teleported = true;
}
self.previous_position = at;
self.previous_position = to;
self.hurt_player_by("minecraft:ender_pearl", 5.0);
self.audio
.play("minecraft:entity.player.teleport", Some(atp), 1.0, 1.0);
self.audio.play(
"minecraft:entity.player.teleport",
Some([to.x, to.y, to.z]),
1.0,
1.0,
);
}
}
(ProjectileKind::SmallFireball, hit) => match hit {
@@ -532,12 +532,14 @@ impl Game<'_> {
g.health = m.health.health();
g.food = m.health.food.food;
g.saturation = m.health.food.saturation;
// A teleport (commands) moves the guest.
// A teleport (commands, a pearl) moves the guest; a pearl's is
// sent even to where they stand (ServerPlayer.teleport).
let at = [m.position.x, m.position.y, m.position.z];
m.sprinting = false;
let teleported = std::mem::take(&mut m.teleported);
let moved: f64 = (0..3).map(|k| (at[k] - g.position[k]).powi(2)).sum();
g.motion = Some(Box::new(m));
if moved > 0.0001 || turned {
if moved > 0.0001 || turned || teleported {
host.hub.teleport(i, Some(at));
}
}
+5
View File
@@ -262,6 +262,10 @@ pub struct PlayerMotion {
pub steps: MovementDistances,
pub needs_sync: bool,
pub sync_position: bool,
/// Moved by an ender pearl (`ServerPlayer.teleport`): a server sends the
/// position packet even when the player lands where they stood. The
/// server takes it at the end of a guest's turn.
pub teleported: bool,
pub events: Vec<MotionEvent>,
pub attributes: LiveAttributes<Box<dyn FnMut() -> i32>>,
pub impulse: ImpulseContext,
@@ -428,6 +432,7 @@ impl PlayerMotion {
},
needs_sync: false,
sync_position: false,
teleported: false,
events: Vec::new(),
attributes,
fluids: PlayerFluids::default(),