Merge pull request #2150 from kacpherek/fix/villager-bed-search-radius

🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `VillagerMakeLove.takeVacantBed` asks the POI manager for a free home within 48 blocks (a sphere, closest first) and keeps only a bed a path reaches. Gate: this wave's 55 PRs merged on main in one tree: clippy `-D warnings` clean, 1186 horizon-client and 163 horizon-world tests pass, and of the 101 harnesses `parity.py --changed-files` picked, 100 pass (`block_removal` failed on one spawner case from #2199's orb merging, fixed there). `lan_e2e.py` passes 24 checks with the host on its server thread and in-frame (chest, xp, pvp, doors, villagers, beds, frames, projectiles, arrows, fishing, damage, mobs, blast, drops, elytra, breath, predict, cracks, barter, kills, hurt, contacts, underwater, plates), plus forced-levels on the server thread. Thanks @kacpherek!
This commit is contained in:
Ludovic Marie
2026-10-26 19:36:14 +01:00
committed by GitHub
2 changed files with 18 additions and 30 deletions
@@ -772,30 +772,6 @@ pub fn finalize_summoned_golem(m: &mut Mob, random: &mut impl RandomSource) {
}
m.extra.left_handed = random.next_float() < 0.05;
}
/// `PoiManager.take(HOME, ..., 48)`: the nearest bed head not `claimed`
/// (`free_head`: a bed head that is not occupied).
pub fn take_vacant_bed(
claimed: &[[i32; 3]],
from: [i32; 3],
mut free_head: impl FnMut(i32, i32, i32) -> bool,
) -> Option<[i32; 3]> {
let mut best: Option<(i32, [i32; 3])> = None;
for y in from[1] - 8..=from[1] + 8 {
for z in from[2] - 48..=from[2] + 48 {
for x in from[0] - 48..=from[0] + 48 {
let d = (x - from[0]).pow(2) + (y - from[1]).pow(2) + (z - from[2]).pow(2);
if d <= 48 * 48
&& best.is_none_or(|(b, _)| d < b)
&& free_head(x, y, z)
&& !claimed.contains(&[x, y, z])
{
best = Some((d, [x, y, z]));
}
}
}
}
best.map(|(_, p)| p)
}
/// `Villager.canBreed`: enough food, awake and an adult.
pub fn can_breed(m: &Mob) -> bool {
m.species() == Species::Villager
@@ -3409,8 +3409,10 @@ fn breeding_possible(m: &mut Mob, w: &MobWorld) -> bool {
&& super::villager::can_breed(m)
&& w.seen(id).is_some_and(|s| s.in_love)
}
/// `VillagerMakeLove.takeVacantBed`: a bed head no villager has claimed.
fn take_bed_for_child(m: &Mob, w: &MobWorld) -> Option<[i32; 3]> {
/// `VillagerMakeLove.takeVacantBed`: `PoiManager.take(HOME, ..., 48)` over a
/// sphere of 48 blocks, the nearest bed head no villager has claimed that the
/// villager can walk to (`canReach`: a path that gets there).
fn take_bed_for_child(m: &mut Mob, w: &MobWorld) -> Option<[i32; 3]> {
let claimed: Vec<[i32; 3]> = w
.others
.iter()
@@ -3418,10 +3420,20 @@ fn take_bed_for_child(m: &Mob, w: &MobWorld) -> Option<[i32; 3]> {
.filter_map(|s| s.bed)
.chain(m.extra.bed)
.collect();
let p = m.position;
let from = [p.x.floor() as i32, p.y.floor() as i32, p.z.floor() as i32];
super::villager::take_vacant_bed(&claimed, from, |x, y, z| {
w.prop(x, y, z, "part") == Some("head") && w.prop(x, y, z, "occupied") != Some("true")
let from = block_of(m.position);
let mut beds: Vec<[i32; 3]> = homes_in_range(m, w, 48)
.into_iter()
.filter(|p| {
w.prop(p[0], p[1], p[2], "part") == Some("head")
&& w.prop(p[0], p[1], p[2], "occupied") != Some("true")
&& !claimed.contains(p)
})
.collect();
// Nearest first; equally near beds stay in scan order.
beds.sort_by_key(|p| dist_sqr(*p, from));
beds.into_iter().find(|&p| {
m.create_path_to(w, p, Poi::Home.valid_range())
.is_some_and(|path| path.reached)
})
}
/// `BehaviorUtils.lockGazeAndWalkToEachOther`: this villager's half, and