Detach entity passengers when their vehicle is removed

Clear remote passenger mount and pose flags when a vehicle disappears, matching Entity.setRemoved. Add a two-passenger boat destruction check for both single-player paths and LAN observers.

Co-Authored-By: Codex (GPT-6) <noreply@openai.com>
This commit is contained in:
levzzz
2026-10-25 16:15:35 +05:00
parent 7d0ae56589
commit 1ec6d6d734
3 changed files with 58 additions and 6 deletions
+4 -2
View File
@@ -321,7 +321,7 @@ impl Game<'_> {
.iter()
.filter(|m| m.distance_sqr(center) <= radius * radius)
.map(|m| {
serde_json::json!({
let mut state = serde_json::json!({
"id": m.id,
"kind": m.kind.id,
"pos": [m.position.x, m.position.y, m.position.z],
@@ -370,7 +370,9 @@ impl Game<'_> {
"patrol_target": s.patrol_target,
"vehicle": m.extra.mount,
})),
})
});
state["passenger"] = serde_json::json!(m.extra.passenger);
state
})
.collect();
serde_json::json!({ "count": self.mobs.len(), "near": list, "projectiles": self.creatures.projectiles.len() })
+4 -4
View File
@@ -1515,10 +1515,10 @@ impl Game<'_> {
self.turn_remote_projectile(id, rotation);
}
fn remove_entity(&mut self, id: i32) {
// The vehicle the player rode is gone (Entity.removeVehicle).
if self.riding == Some(id as u32) {
self.riding = None;
}
// Entity.setRemoved detaches every passenger, even when no empty
// SetPassengers packet preceded the vehicle's removal. Otherwise
// mobs and other players keep their passenger pose after it is gone.
self.remote_set_passengers(id, &[]);
self.mobs.retain(|m| m.id != id as u32);
self.orbs.retain(|o| o.id != id as u32);
self.dropped.retain(|d| d.id != id as u32);
+50
View File
@@ -6162,5 +6162,55 @@ CHECKS += ['falling']
CHECK_FNS.update(falling=check_falling)
def check_boat_dismount_pose(host, guest, out):
"""Removing a boat detaches its mobs on the server and every observing client."""
x, y, z = map(math.floor, pos_of(host))
bx, bz = x + 3.5, z + 3.5
tag = 'boat_dismount_pose'
host('command', command='gamemode creative')
host('command', command=f'fill {x - 2} {y - 1} {z - 2} {x + 8} {y - 1} {z + 8} minecraft:stone')
host('command', command=f'fill {x - 2} {y} {z - 2} {x + 8} {y + 4} {z + 8} minecraft:air')
host('command', command=f'summon minecraft:oak_boat {bx} {y} {bz} {{Tags:["{tag}"]}}')
for _ in range(2):
host('command', command=f'summon minecraft:husk {bx} {y} {bz} {{NoAI:1b,Tags:["{tag}"]}}')
host.wait(5)
try:
host.wait(20)
boat = next(o for o in host('status')['objects']
if o['kind'].endswith('oak_boat') and math.dist(o['position'], [bx, y, bz]) < 2)
riders = [m['id'] for m in host.raw('mobs', 64)['near']
if m['kind'] == 'minecraft:husk' and m['mount'] == boat['id']]
assert len(riders) == 2, f'the boat did not collect both husks: {riders}'
for game in (host, guest):
game.wait(10)
for rider in riders:
m = mob_seen(game, rider)
assert m and m['mount'] == boat['id'] and m['passenger'], f'{game.name} did not see seated husk {rider}: {m}'
game.raw('look-at', bx, y + 1, bz)
game.shot(out, 'boat-passengers-seated')
host('command', command=f'tp @s {bx - 3} {y} {bz} 0 0')
host.wait(5)
# Aim at the near rim, below the riders, so their boxes cannot
# intercept the creative player's one hit that destroys the boat.
host.raw('look-at', bx - 0.55, y + 0.1, bz)
host.raw('mouse', 'left', 'click')
seen = {}
for game in (host, guest):
game.wait(20)
assert all(o['id'] != boat['id'] for o in game('status')['objects']), f'{game.name} still sees the boat'
seen[game.name] = [mob_seen(game, rider) for rider in riders]
game.raw('look-at', bx, y + 1, bz)
game.shot(out, 'boat-passengers-dismounted')
for m in seen[game.name]:
assert m and m['mount'] is None and not m['passenger'], f'{game.name} still draws a removed boat\'s passenger: {m}'
return {name: [{k: m[k] for k in ('id', 'mount', 'passenger')} for m in mobs] for name, mobs in seen.items()}
finally:
host('command', command=f'kill @e[tag={tag}]')
CHECKS += ['boat-dismount-pose']
CHECK_FNS['boat-dismount-pose'] = check_boat_dismount_pose
if __name__ == '__main__':
main()