Merge worktree-agent-ad30db2169aa3bd5b

This commit is contained in:
Ludovic Marie
2026-10-10 09:05:49 +02:00
17 changed files with 326 additions and 9 deletions
@@ -466,6 +466,11 @@ impl Game<'_> {
block_tags: &self.res.items.block_tags,
biomes: &self.res.biomes,
mob_griefing: self.ui.rules.bool("mob_griefing"),
difficulty: self.local_difficulty(
self.player
.as_ref()
.map_or([0.0; 3], |p| [p.position.x, p.position.y, p.position.z]),
),
}
}
/// `ServerLevel.getCurrentDifficultyAt`.
+1
View File
@@ -79,6 +79,7 @@ impl Game<'_> {
let ally = matches!(
m.species(),
Species::Evoker
| Species::Illusioner
| Species::Vex
| Species::Pillager
| Species::Vindicator
+5
View File
@@ -27,6 +27,7 @@ pub mod guardian;
pub mod happy_ghast;
pub mod hostile;
pub mod illager;
pub mod illusioner;
pub mod keyframes;
pub mod leash;
pub mod living;
@@ -491,6 +492,8 @@ pub struct Extra {
pub vector: [f64; 3],
/// Active status effects: (effect id, ticks left, amplifier).
pub effects: Vec<(&'static str, i32, i32)>,
/// An invisible illusioner's mirror images.
pub illusions: Option<illusioner::Illusions>,
/// A villager's claimed bed head and meeting bell.
pub bed: Option<[i32; 3]>,
pub meeting: Option<[i32; 3]>,
@@ -890,6 +893,8 @@ pub struct MobWorld<'a> {
pub biomes: &'a crate::biome::Biomes,
/// The `mob_griefing` game rule.
pub mob_griefing: bool,
/// `getCurrentDifficultyAt` near the player.
pub difficulty: spawning::LocalDifficulty,
}
impl Mob {
pub fn new(id: u32, kind: Arc<MobType>, position: Vec3, yaw: f32) -> Self {
+5 -1
View File
@@ -122,7 +122,7 @@ pub fn family(s: Species) -> Family {
S::Wolf | S::Cat => Family::Tame,
S::Blaze | S::Ghast => Family::Nether,
S::IronGolem | S::SnowGolem => Family::Golem,
S::Pillager | S::Vindicator | S::Evoker => Family::Illager,
S::Pillager | S::Vindicator | S::Evoker | S::Illusioner => Family::Illager,
S::Vex => Family::Vex,
S::Ravager => Family::Ravager,
S::Wither => Family::Wither,
@@ -168,6 +168,7 @@ pub fn register(m: &mut Mob) {
Family::Golem => super::golem::register_snow(m),
Family::Illager if m.species() == Species::Pillager => super::illager::register_pillager(m),
Family::Illager if m.species() == Species::Evoker => super::illager::register_evoker(m),
Family::Illager if m.species() == Species::Illusioner => super::illusioner::register(m),
Family::Illager => super::illager::register_vindicator(m),
Family::Equine => super::equine::register(m),
Family::Phantom => super::phantom::register(m),
@@ -383,6 +384,9 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
}
tick_effects(m);
if m.species() == Species::Illusioner {
super::illusioner::tick(m, events);
}
if m.hurt_time > 0 {
m.hurt_time -= 1;
}
+23 -2
View File
@@ -20,6 +20,7 @@ fn raider(s: Species) -> bool {
| Species::Vindicator
| Species::Witch
| Species::Evoker
| Species::Illusioner
| Species::Ravager
)
}
@@ -30,6 +31,7 @@ fn targets(m: &mut Mob, villagers_seen: bool) {
Species::Vindicator,
Species::Witch,
Species::Evoker,
Species::Illusioner,
Species::Vex,
Species::Ravager,
];
@@ -95,7 +97,7 @@ enum Spell {
/// `SpellcasterCastingSpellGoal`: stand still facing the target while a
/// spell is cast.
#[derive(Clone, Debug)]
struct CastingSpell;
pub(super) struct CastingSpell;
impl Goal for CastingSpell {
goal_clone!();
fn flags(&self) -> u8 {
@@ -542,6 +544,7 @@ enum ArmPose {
Attacking,
CrossbowHold,
CrossbowCharge,
Bow,
}
/// `Pillager` / `Vindicator.getArmPose`.
fn arm_pose(m: &Mob) -> ArmPose {
@@ -557,6 +560,9 @@ fn arm_pose(m: &Mob) -> ArmPose {
ArmPose::Neutral
}
}
Species::Illusioner if m.extra.variant2 != 0 => ArmPose::Spellcasting,
Species::Illusioner if m.ai.aggressive => ArmPose::Bow,
Species::Illusioner => ArmPose::Crossed,
Species::Evoker if m.extra.variant2 != 0 => ArmPose::Spellcasting,
Species::Evoker if celebrating(m) => ArmPose::Celebrating,
Species::Evoker => ArmPose::Crossed,
@@ -576,7 +582,11 @@ fn celebrating(m: &Mob) -> bool {
}
/// Whether the held item shows (vindicators only draw their axe when angry).
pub fn shows_item(m: &Mob) -> bool {
m.species() != Species::Vindicator || m.ai.aggressive
match m.species() {
Species::Vindicator => m.ai.aggressive,
Species::Illusioner => m.extra.variant2 != 0 || m.ai.aggressive,
_ => true,
}
}
fn hide(p: &mut Poses, part: &str) {
if p.has(part) {
@@ -600,6 +610,10 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
p.zrot("left_arm", 0.0);
p.xrot("right_leg", (pos * 0.6662).cos() * 1.4 * sp * 0.5);
p.xrot("left_leg", (pos * 0.6662 + PI).cos() * 1.4 * sp * 0.5);
// IllagerModel hides the hat; the illusioner's renderer shows it.
if m.species() != Species::Illusioner {
hide(p, "hat");
}
let pose = arm_pose(m);
match pose {
ArmPose::Attacking => {
@@ -638,6 +652,13 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
bob(p, "right_arm", 1.0);
bob(p, "left_arm", -1.0);
}
ArmPose::Bow => {
p.yrot("right_arm", -0.1 + hy);
p.xrot("right_arm", -PI / 2.0 + hx);
p.xrot("left_arm", -0.942_477_9 + hx);
p.yrot("left_arm", hy - 0.4);
p.zrot("left_arm", PI / 2.0);
}
ArmPose::CrossbowHold => {
p.yrot("right_arm", -0.3 + hy);
p.yrot("left_arm", 0.6 + hy);
@@ -0,0 +1,235 @@
//! The illusioner (`Illusioner`): a bow-wielding spellcaster that turns
//! invisible behind four mirror images and blinds its target.
use super::{
Mob, MobEvent, Species, Who,
goals::{
Avoid, AvoidEntity, Cx, Float, Goal, HurtByTarget, LookAtPlayer, NearestTarget, Stroll,
goal_clone, reduced,
},
illager::CastingSpell,
undead::BowAttack,
};
use horizon_core::random::RandomSource;
const INVISIBILITY: &str = "minecraft:invisibility";
const BLINDNESS: &str = "minecraft:blindness";
/// `Illusioner.NUM_ILLUSIONS`.
pub const COPIES: usize = 4;
/// `Illusioner.clientSideIllusionTicks` and the two offset sets.
#[derive(Clone, Debug, Default)]
pub struct Illusions {
pub ticks: i32,
pub offsets: [[[f64; 3]; COPIES]; 2],
}
pub const MIRROR: u8 = 5;
pub const BLINDNESS_SPELL: u8 = 4;
pub fn register(m: &mut Mob) {
let g = &mut m.ai.goals;
g.add(0, Float);
g.add(1, CastingSpell);
g.add(
3,
AvoidEntity::new(Avoid::Species(vec![Species::Creaking]), 8.0, 1.0, 1.2),
);
g.add(4, Spell::new(MIRROR));
g.add(5, Spell::new(BLINDNESS_SPELL));
g.add(6, BowAttack::new(0.5, 20, 15.0));
g.add(8, Stroll::new(0.6));
g.add(9, LookAtPlayer::new(3.0).probability(1.0));
g.add(10, LookAtPlayer::new(8.0));
let mut hurt = HurtByTarget::new().alert();
hurt.ignore = vec![
Species::Pillager,
Species::Vindicator,
Species::Witch,
Species::Evoker,
Species::Illusioner,
Species::Vex,
Species::Ravager,
];
m.ai.targets.add(1, hurt);
m.ai.targets.add(2, NearestTarget::player(true));
m.ai.targets.add(
3,
NearestTarget::species(&[Species::Villager, Species::WanderingTrader], false),
);
m.ai.targets
.add(3, NearestTarget::species(&[Species::IronGolem], false));
}
/// `Illusioner.finalizeSpawn`: a bow in the main hand.
pub fn finalize(m: &mut Mob) {
m.extra.main_hand = Some("minecraft:bow".into());
}
/// `IllusionerMirrorSpellGoal` and `IllusionerBlindnessSpellGoal`.
#[derive(Clone, Debug)]
struct Spell {
spell: u8,
warmup: i32,
next: i64,
last_target: Option<Who>,
}
impl Spell {
fn new(spell: u8) -> Self {
Self {
spell,
warmup: 0,
next: 0,
last_target: None,
}
}
/// (casting time, interval, prepare sound).
fn timing(&self) -> (i32, i64, &'static str) {
if self.spell == MIRROR {
(20, 340, "entity.illusioner.prepare_mirror")
} else {
(20, 180, "entity.illusioner.prepare_blindness")
}
}
}
impl Goal for Spell {
goal_clone!();
fn flags(&self) -> u8 {
0
}
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
if !m.target_info(cx.w).is_some_and(|t| t.alive)
|| m.extra.counter > 0
|| i64::from(m.age) < self.next
{
return false;
}
if self.spell == MIRROR {
!m.has_effect(INVISIBILITY)
} else {
m.ai.target != self.last_target && cx.w.difficulty.effective > 2.0
}
}
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
m.target_info(cx.w).is_some_and(|t| t.alive) && self.warmup > 0
}
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
let (casting, interval, sound) = self.timing();
self.warmup = reduced(20);
m.extra.counter = casting;
self.next = i64::from(m.age) + interval;
cx.events.push(MobEvent::Sound(sound, m.center(), 1.0, 1.0));
m.extra.variant2 = self.spell;
if self.spell == BLINDNESS_SPELL {
self.last_target = m.ai.target;
}
}
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
self.warmup -= 1;
if self.warmup != 0 {
return;
}
if self.spell == MIRROR {
m.add_effect(INVISIBILITY, 1200, 0);
} else if m.ai.target == Some(Who::Player) {
cx.events.push(MobEvent::EffectPlayer {
effect: BLINDNESS,
ticks: 400,
amplifier: 0,
});
}
cx.events.push(MobEvent::Sound(
"entity.illusioner.cast_spell",
m.center(),
1.0,
1.0,
));
}
}
/// The client-side half of `Illusioner.aiStep`: new image offsets when
/// hurt and once a minute, with a puff of cloud and a sound.
pub fn tick(m: &mut Mob, events: &mut Vec<MobEvent>) {
if !m.has_effect(INVISIBILITY) {
return;
}
let hurt = m.hurt_time;
let age = m.age;
let mut il = m.extra.illusions.take().unwrap_or_default();
il.ticks = (il.ticks - 1).max(0);
if hurt == 1 || age % 1200 == 0 {
il.ticks = 3;
for i in 0..COPIES {
il.offsets[0][i] = il.offsets[1][i];
let r = &mut m.random;
let x = (-6 + r.next_int_bound(13).unwrap_or(0)) as f64 * 0.5;
let y = (r.next_int_bound(6).unwrap_or(0) - 4).max(0) as f64;
let z = (-6 + r.next_int_bound(13).unwrap_or(0)) as f64 * 0.5;
il.offsets[1][i] = [x, y, z];
}
events.push(MobEvent::Particles {
kind: "minecraft:cloud",
at: [m.position.x, m.position.y + 0.9, m.position.z],
count: 16,
});
events.push(MobEvent::Sound(
"entity.illusioner.mirror_move",
m.center(),
1.0,
1.0,
));
} else if hurt == 9 {
il.ticks = 3;
for i in 0..COPIES {
il.offsets[0][i] = il.offsets[1][i];
il.offsets[1][i] = [0.0; 3];
}
}
m.extra.illusions = Some(il);
}
/// `Illusioner.getIllusionOffsets`.
pub fn offsets(m: &Mob, partial: f32) -> [[f64; 3]; COPIES] {
let Some(il) = &m.extra.illusions else {
return [[0.0; 3]; COPIES];
};
if il.ticks <= 0 {
return il.offsets[1];
}
let scale = (f64::from(il.ticks as f32 - partial) / 3.0).powf(0.25);
let mut out = [[0.0; 3]; COPIES];
for (i, o) in out.iter_mut().enumerate() {
for k in 0..3 {
o[k] = il.offsets[1][i][k] * (1.0 - scale) + il.offsets[0][i][k] * scale;
}
}
out
}
/// The wobble `IllusionerRenderer.submit` adds to each image.
pub fn wobble(i: usize, age: f32) -> [f64; 3] {
let i = i as f32;
[
f64::from((i + age * 0.5).cos()) * 0.025,
f64::from((i + age * 0.75).cos()) * 0.0125,
f64::from((i + age * 0.7).cos()) * 0.025,
]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn settled_offsets_are_the_new_set() {
let il = Illusions {
ticks: 0,
offsets: [[[1.0; 3]; COPIES], [[2.0; 3]; COPIES]],
};
let mut v = [[0.0; 3]; COPIES];
v.copy_from_slice(&il.offsets[1]);
assert_eq!(v[0], [2.0; 3]);
}
#[test]
fn wobble_is_small() {
assert!(wobble(1, 10.0).iter().all(|c| c.abs() <= 0.025));
}
}
+1 -1
View File
@@ -48,7 +48,7 @@ fn is_zombie(s: &Seen) -> bool {
pub fn is_illager(s: &Seen) -> bool {
matches!(
s.species,
Species::Pillager | Species::Vindicator | Species::Evoker
Species::Pillager | Species::Vindicator | Species::Evoker | Species::Illusioner
)
}
pub fn register(m: &mut Mob) {
+1
View File
@@ -57,6 +57,7 @@ pub fn is_raider(s: Species) -> bool {
Species::Pillager
| Species::Vindicator
| Species::Evoker
| Species::Illusioner
| Species::Witch
| Species::Ravager
)
+2 -1
View File
@@ -25,6 +25,7 @@ pub fn register(m: &mut Mob) {
Species::Pillager,
Species::Vindicator,
Species::Evoker,
Species::Illusioner,
Species::Witch,
Species::Ravager,
];
@@ -180,7 +181,7 @@ fn roar(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
let illager = matches!(
s.species,
Species::Pillager | Species::Vindicator | Species::Evoker
Species::Pillager | Species::Vindicator | Species::Evoker | Species::Illusioner
);
if !illager {
events.push(MobEvent::AttackMob {
+24 -1
View File
@@ -822,10 +822,33 @@ pub fn render_with(
extra: &[(&Part, [f32; 4], u32)],
out: &mut Vec<Vertex>,
) {
// The invisibility effect hides the model (a drinking wandering trader).
// The invisibility effect hides the model (a drinking wandering trader);
// an illusioner shows its four mirror images instead.
if super::trader::is_invisible(m) {
if m.species() == Species::Illusioner {
let age = m.age as f32 + alpha;
for (i, off) in super::illusioner::offsets(m, alpha).iter().enumerate() {
let w = super::illusioner::wobble(i, age);
let shifted =
camera - glam::DVec3::new(off[0] + w[0], off[1] + w[1], off[2] + w[2]);
render_visible(m, alpha, shifted, atlas, light, data, extra, out);
}
}
return;
}
render_visible(m, alpha, camera, atlas, light, data, extra, out);
}
#[allow(clippy::too_many_arguments)]
fn render_visible(
m: &Mob,
alpha: f32,
camera: glam::DVec3,
atlas: Atlas,
light: u32,
data: &MobData,
extra: &[(&Part, [f32; 4], u32)],
out: &mut Vec<Vertex>,
) {
let base = base_transform(m, alpha, camera);
let overlay =
u32::from(m.hurt_time > 0 || (m.death_time > 0 && !super::creaking::tearing_down(m)));
+1 -1
View File
@@ -48,7 +48,7 @@ pub fn vehicle_attachment(r: &Mob) -> f64 {
| S::Bogged
| S::Parched
| S::WitherSkeleton => 0.7,
S::Pillager | S::Vindicator | S::Evoker => 0.6,
S::Pillager | S::Vindicator | S::Evoker | S::Illusioner => 0.6,
_ => 0.0,
}
}
@@ -397,6 +397,7 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts, difficulty: &LocalDifficulty) {
m.extra.main_hand = Some("minecraft:golden_axe".into());
m.extra.pick_up_loot = true;
}
S::Illusioner => super::illusioner::finalize(m),
S::Vindicator => m.extra.main_hand = Some("minecraft:iron_axe".into()),
S::Villager => {
m.extra.variant = villager_type(biome);
+16
View File
@@ -78,6 +78,7 @@ pub enum Species {
ElderGuardian,
Shulker,
Evoker,
Illusioner,
Vex,
Ravager,
Wither,
@@ -905,6 +906,20 @@ pub const ALL: &[Def] = &[
None,
Baby::None
),
def!(
Illusioner,
"illusioner",
"illusioner#main",
"entity/illager/illusioner",
A::Illager,
[
"entity.illusioner.ambient",
"entity.illusioner.hurt",
"entity.illusioner.death"
],
None,
Baby::None
),
def!(
Allay,
"allay",
@@ -1435,6 +1450,7 @@ impl Def {
| S::ElderGuardian
| S::Shulker
| S::Evoker
| S::Illusioner
| S::Vex
| S::Ravager
| S::Wither
+1
View File
@@ -44,6 +44,7 @@ pub fn register(m: &mut Mob) {
for (species, distance) in [
(Species::Zombie, 8.0),
(Species::Evoker, 12.0),
(Species::Illusioner, 12.0),
(Species::Vindicator, 8.0),
(Species::Vex, 8.0),
(Species::Pillager, 15.0),
+1
View File
@@ -32,6 +32,7 @@ pub fn register(m: &mut Mob) {
Species::Pillager,
Species::Vindicator,
Species::Evoker,
Species::Illusioner,
Species::Witch,
Species::Vex,
];
+2 -1
View File
@@ -63,6 +63,7 @@ pub fn register(m: &mut Mob) {
Species::Pillager,
Species::Vindicator,
Species::Evoker,
Species::Illusioner,
Species::Ravager,
Species::Zoglin,
];
@@ -1217,7 +1218,7 @@ fn hostile_range(s: Species) -> f64 {
| Species::Vex
| Species::Zombie
| Species::ZombieVillager => 8.0,
Species::Evoker | Species::Ravager => 12.0,
Species::Evoker | Species::Illusioner | Species::Ravager => 12.0,
Species::Pillager => 15.0,
Species::Vindicator | Species::Zoglin => 10.0,
_ => 0.0,
+2 -1
View File
@@ -21,7 +21,7 @@ pub fn set_source_volumes(volumes: [f32; 11]) {
pub fn sound_source(event: &str) -> usize {
let e = event.trim_start_matches("minecraft:");
let index = |name: &str| SOUND_SOURCES.iter().position(|n| *n == name).unwrap_or(0);
const HOSTILE: [&str; 24] = [
const HOSTILE: [&str; 25] = [
"zombie",
"skeleton",
"creeper",
@@ -40,6 +40,7 @@ pub fn sound_source(event: &str) -> usize {
"pillager",
"vindicator",
"evoker",
"illusioner",
"ravager",
"guardian",
"elder_guardian",