Fire avoid_vibration when a sneaking step is ignored

Vanilla's VibrationSystem fires AVOID_VIBRATION for a sneaking player whose step a sculk sensor or a warden ignores; a shrieker cannot trigger it.
This commit is contained in:
Kacpherek
2026-10-27 22:08:13 +01:00
parent 3cf601f760
commit 7aaa4b433b
2 changed files with 37 additions and 8 deletions
+16 -1
View File
@@ -623,6 +623,18 @@ impl Game<'_> {
SculkKind::Shrieker => sculk::shrieker_can_listen(event),
_ => sculk::is_vibration(event),
};
// VibrationSystem.User.isValidVibration: a player sneaking past a
// sensor, whose step it ignores, is AVOID_VIBRATION (sensors only;
// a shrieker cannot trigger it).
if listens
&& matches!(kind, SculkKind::Sensor | SculkKind::Calibrated)
&& ctx.source == Some(Who::Player)
&& !ctx.spectator
&& ctx.stepping_carefully
&& sculk::ignored_when_sneaking(event)
{
self.trigger_player("minecraft:avoid_vibration");
}
if !sculk::valid_vibration(listens, event, ctx) {
return;
}
@@ -693,12 +705,15 @@ impl Game<'_> {
fn warden_listen(&mut self, index: usize, event: &'static str, pos: [f64; 3], ctx: &Context) {
let now = self.world.game_time;
let (occludes, world) = (&self.sculk.tables.occludes, &self.world);
warden::listen(&mut self.mobs[index], now, event, pos, ctx, |a, b| {
let avoided = warden::listen(&mut self.mobs[index], now, event, pos, ctx, |a, b| {
sculk::is_occluded(a, b, |p| {
let state = world.block(p.x, p.y, p.z);
occludes.get(state.0 as usize).copied().unwrap_or(false)
})
});
if avoided {
self.trigger_player("minecraft:avoid_vibration");
}
}
// ---- ticking ----
+21 -7
View File
@@ -489,7 +489,8 @@ pub fn can_receive_vibration(m: &Mob, _now: i64, ctx: &Context) -> bool {
}
/// `VibrationSystem.Listener.handleGameEvent` for the warden: a free
/// listener within 16 blocks of its eyes schedules what it can hear.
/// `occluded` is `VibrationSystem.Listener.isOccluded`.
/// `occluded` is `VibrationSystem.Listener.isOccluded`. Returns true when a
/// sneaking player's step was avoided (AVOID_VIBRATION) instead.
pub fn listen(
m: &mut Mob,
now: i64,
@@ -497,23 +498,35 @@ pub fn listen(
pos: [f64; 3],
ctx: &Context,
occluded: impl Fn([f64; 3], [f64; 3]) -> bool,
) {
) -> bool {
let eye = [m.position.x, m.position.y + m.kind.eye_height, m.position.z];
let Some(st) = m.extra.warden.as_ref() else {
return;
return false;
};
if st.vibration.current.is_some() {
return;
return false;
}
let block = |p: [f64; 3]| p.map(|v| i64::from(v.floor() as i32));
let (source, listener) = (block(pos), block(eye));
let d = [0, 1, 2].map(|i| source[i] - listener[i]);
if d[0] * d[0] + d[1] * d[1] + d[2] * d[2] > 256
|| !sculk::valid_vibration(sculk::warden_can_listen(event), event, ctx)
if d[0] * d[0] + d[1] * d[1] + d[2] * d[2] > 256 {
return false;
}
// isValidVibration: the warden can trigger avoid vibration.
let listens = sculk::warden_can_listen(event);
if listens
&& ctx.source == Some(Who::Player)
&& !ctx.spectator
&& ctx.stepping_carefully
&& sculk::ignored_when_sneaking(event)
{
return true;
}
if !sculk::valid_vibration(listens, event, ctx)
|| !can_receive_vibration(m, i64::from(m.age), ctx)
|| occluded(pos, eye)
{
return;
return false;
}
let d = [pos[0] - eye[0], pos[1] - eye[1], pos[2] - eye[2]];
let distance = (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt() as f32;
@@ -529,6 +542,7 @@ pub fn listen(
now,
);
}
false
}
/// `Level.gameEvent` for the mobs' own movement events from `from` on, as
/// the mob AI probe has no sculk layer: every warden's listener hears them.