Fire spear_mobs when a spear stabs several mobs in one use

Vanilla's KineticWeapon fires SPEAR_MOBS with the number of living entities stabbed in the use, so stabbing five or more completes the spear advancement.
This commit is contained in:
Kacpherek
2026-10-27 22:07:25 +01:00
parent 16cda1637b
commit 3c72bf2d79
2 changed files with 17 additions and 0 deletions
@@ -1065,6 +1065,20 @@ impl Game<'_> {
})
});
}
/// `SpearMobsTrigger`: the living entities the spear stabbed in this use.
pub(super) fn trigger_spear_mobs(&mut self, stabbed: usize) {
let me = self.player_entity();
self.trigger("minecraft:spear_mobs", move |c, w| {
let pctx = adv::Entities {
this: Some(&me),
origin: me.position,
tool: None,
block_pos: None,
};
adv::conditions(&c["player"], &pctx, w)
&& c["count"].as_u64().is_none_or(|n| stabbed as u64 >= n)
});
}
/// A trigger with only the player condition (slept_in_bed, started_riding).
pub(super) fn trigger_player(&mut self, name: &str) {
let me = self.player_entity();
+3
View File
@@ -193,6 +193,9 @@ impl Game<'_> {
}
let who = actor.map_or(OWN, |conn| conn as i32);
self.kinetic_hit_feedback(who, &kinetic, [feet.x, feet.y, feet.z]);
// SPEAR_MOBS_TRIGGER: the living entities stabbed in this use.
let stabbed = self.stabbed.keys().filter(|(who, _)| *who == actor).count();
self.trigger_spear_mobs(stabbed);
}
}