Merge pull request #1200 from pirut/claude/upstream-mob-world
🤖 Agent: merged after verify passed and the integration run on the desktop (main 34c3c1cf + the 14 contributor PRs: workspace tests 1,869/0, launcher 113, parity --changed 320/0).
This commit is contained in:
@@ -606,7 +606,7 @@ fn sense_living(m: &mut Mob, w: &MobWorld) {
|
||||
let r = m.attrs.follow_range;
|
||||
let area = m.bounds().inflate(Vec3::new(r, r, r));
|
||||
let mut found: Vec<(Who, f64)> = Vec::new();
|
||||
for o in w.others {
|
||||
for o in w.others_near(area) {
|
||||
if o.id != m.id && o.alive && o.bounds.intersects(area) {
|
||||
found.push((Who::Mob(o.id), m.distance_sqr(o.position)));
|
||||
}
|
||||
|
||||
@@ -441,7 +441,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!(
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
@@ -970,8 +974,7 @@ impl Goal for LookAtPlayer {
|
||||
let (id, only) = (m.id, self.only);
|
||||
let at = Vec3::new(m.position.x, m.eye_y(), m.position.z);
|
||||
let candidates: Vec<(u32, Vec3)> =
|
||||
cx.w.others
|
||||
.iter()
|
||||
cx.w.others_near(area)
|
||||
.filter(|s| s.id != id && s.alive && s.bounds.intersects(area))
|
||||
.filter(|s| only.is_none_or(|o| s.species == o))
|
||||
.map(|s| (s.id, s.position))
|
||||
@@ -1902,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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -299,7 +299,7 @@ fn sense_living(m: &mut Mob, w: &MobWorld) {
|
||||
let r = m.attrs.follow_range;
|
||||
let area = m.bounds().inflate(Vec3::new(r, r, r));
|
||||
let mut found: Vec<(Who, f64)> = Vec::new();
|
||||
for o in w.others {
|
||||
for o in w.others_near(area) {
|
||||
if o.id != m.id && o.alive && o.bounds.intersects(area) {
|
||||
found.push((Who::Mob(o.id), m.distance_sqr(o.position)));
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ fn roar(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
velocity: fling(p.position),
|
||||
});
|
||||
}
|
||||
for s in w.others.iter() {
|
||||
for s in w.others_near(area) {
|
||||
if s.id == m.id || !s.alive || s.species == Species::Ravager || !s.bounds.intersects(area) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@ fn sense_living(m: &mut Mob, w: &MobWorld) {
|
||||
let r = m.attrs.follow_range;
|
||||
let area = m.bounds().inflate(Vec3::new(r, r, r));
|
||||
let mut found: Vec<(Who, f64)> = Vec::new();
|
||||
for o in w.others {
|
||||
for o in w.others_near(area) {
|
||||
if o.id != m.id && o.alive && o.bounds.intersects(area) {
|
||||
found.push((Who::Mob(o.id), m.distance_sqr(o.position)));
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ fn sense_entities(m: &mut Mob, w: &MobWorld) {
|
||||
let r = m.attrs.follow_range;
|
||||
let area = m.bounds().inflate(Vec3::new(r, r, r));
|
||||
let mut found: Vec<(Who, f64)> = Vec::new();
|
||||
for o in w.others {
|
||||
for o in w.others_near(area) {
|
||||
if o.id != m.id && o.alive && o.bounds.intersects(area) {
|
||||
found.push((Who::Mob(o.id), m.distance_sqr(o.position)));
|
||||
}
|
||||
|
||||
@@ -226,7 +226,13 @@ impl MobWorld<'_> {
|
||||
.chain(all.into_iter().flatten())
|
||||
}
|
||||
pub fn seen(&self, id: u32) -> Option<&Seen> {
|
||||
self.others.iter().find(|s| s.id == id)
|
||||
match self.others_index {
|
||||
Some(index) => index
|
||||
.get(&id)
|
||||
.and_then(|&i| self.others.get(i as usize))
|
||||
.filter(|s| s.id == id),
|
||||
None => self.others.iter().find(|s| s.id == id),
|
||||
}
|
||||
}
|
||||
/// Living mobs of the given species within `range` of `from`, nearest first.
|
||||
pub fn nearby<'s>(
|
||||
@@ -235,9 +241,15 @@ impl MobWorld<'_> {
|
||||
range: f64,
|
||||
pred: impl Fn(&Seen) -> bool + 's,
|
||||
) -> impl Iterator<Item = &'s Seen> + 's {
|
||||
// A position within `range` puts the box's bottom face in this area
|
||||
// (one block wider, as the box test is strict).
|
||||
let r = range + 1.0;
|
||||
let area = Aabb::new(
|
||||
Vec3::new(from.x - r, from.y - r, from.z - r),
|
||||
Vec3::new(from.x + r, from.y + r, from.z + r),
|
||||
);
|
||||
let mut v: Vec<&Seen> = self
|
||||
.others
|
||||
.iter()
|
||||
.others_near(area)
|
||||
.filter(|s| {
|
||||
s.alive
|
||||
&& (s.position.x - from.x).abs() <= range
|
||||
|
||||
Reference in New Issue
Block a user