Mob goals: read nearby mobs from the tick's grid in four more places

FollowParentGoal (every baby, every tick), the pufferfish's puff check,
the enderman's block placing and the iron golem's DefendVillage scanned
every mob. They now read candidates from the position grid around the
area they test (one block wider where they test positions, as a box
whose bottom face holds the position meets it), in snapshot order, and
test exactly as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UxXpf7d4RgpespL2G2UsGE
This commit is contained in:
Claude
2026-10-22 01:01:03 +00:00
parent 6216b84669
commit 3b21a975bb
4 changed files with 21 additions and 10 deletions
+1 -1
View File
@@ -438,7 +438,7 @@ impl Goal for PufferfishPuff {
.as_ref()
.is_some_and(|p| p.alive && !p.creative && area.intersects(p.bounds));
// TARGETING_CONDITIONS: not other fish (not_scary_for_pufferfish) and alive.
let mob = cx.w.others.iter().any(|s| {
let mob = cx.w.others_near(area).any(|s| {
s.id != m.id
&& s.alive
&& !matches!(
+5 -6
View File
@@ -391,12 +391,11 @@ impl Goal for LeaveBlock {
let target = cx.w.world.block(x, y, z);
let below = cx.w.world.block(x, y - 1, z);
let bf = cx.w.facts.get(below);
let free = !cx.w.others.iter().any(|s| {
s.bounds.intersects(Aabb::new(
Vec3::new(f64::from(x), f64::from(y), f64::from(z)),
Vec3::new(f64::from(x + 1), f64::from(y + 1), f64::from(z + 1)),
))
});
let block = Aabb::new(
Vec3::new(f64::from(x), f64::from(y), f64::from(z)),
Vec3::new(f64::from(x + 1), f64::from(y + 1), f64::from(z + 1)),
);
let free = !cx.w.others_near(block).any(|s| s.bounds.intersects(block));
if cx.w.facts.is_air(target)
&& !cx.w.facts.is_air(below)
&& &*bf.name != "minecraft:bedrock"
+11 -2
View File
@@ -1,7 +1,11 @@
//! Vanilla's `GoalSelector` (priorities, MOVE/LOOK/JUMP/TARGET control flags,
//! interruption) and the shared goals of `net.minecraft.world.entity.ai.goal`.
use super::{Mob, MobEvent, MobWorld, Seen, Species, Who, world::TargetInfo};
use horizon_core::{geometry::Vec3, jmath, random::RandomSource};
use horizon_core::{
geometry::{Aabb, Vec3},
jmath,
random::RandomSource,
};
use std::sync::Arc;
pub const MOVE: u8 = 1;
@@ -1901,7 +1905,12 @@ impl Goal for FollowParent {
let species = m.species();
let pos = m.position;
let mut best: Option<(u32, f64)> = None;
for s in cx.w.others.iter().filter(|s| {
// Every position in range puts the box's bottom face in this area.
let area = Aabb::new(
Vec3::new(pos.x - 9.0, pos.y - 5.0, pos.z - 9.0),
Vec3::new(pos.x + 9.0, pos.y + 5.0, pos.z + 9.0),
);
for s in cx.w.others_near(area).filter(|s| {
s.alive
&& s.species == species
&& !s.baby
+4 -1
View File
@@ -68,7 +68,10 @@ impl Goal for DefendVillage {
if !b.intersects(p.bounds) || m.position.distance_squared(p.position) > 64.0 * 64.0 {
return false;
}
let bad = cx.w.others.iter().any(|s| {
// A position inside `b` puts the box's bottom face there (one block
// wider, as the box test is strict).
let near = b.inflate(Vec3::new(1.0, 1.0, 1.0));
let bad = cx.w.others_near(near).any(|s| {
s.species == Species::Villager
&& s.alive
&& s.player_rep <= -100