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:
@@ -623,6 +623,18 @@ impl Game<'_> {
|
|||||||
SculkKind::Shrieker => sculk::shrieker_can_listen(event),
|
SculkKind::Shrieker => sculk::shrieker_can_listen(event),
|
||||||
_ => sculk::is_vibration(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) {
|
if !sculk::valid_vibration(listens, event, ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -693,12 +705,15 @@ impl Game<'_> {
|
|||||||
fn warden_listen(&mut self, index: usize, event: &'static str, pos: [f64; 3], ctx: &Context) {
|
fn warden_listen(&mut self, index: usize, event: &'static str, pos: [f64; 3], ctx: &Context) {
|
||||||
let now = self.world.game_time;
|
let now = self.world.game_time;
|
||||||
let (occludes, world) = (&self.sculk.tables.occludes, &self.world);
|
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| {
|
sculk::is_occluded(a, b, |p| {
|
||||||
let state = world.block(p.x, p.y, p.z);
|
let state = world.block(p.x, p.y, p.z);
|
||||||
occludes.get(state.0 as usize).copied().unwrap_or(false)
|
occludes.get(state.0 as usize).copied().unwrap_or(false)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
if avoided {
|
||||||
|
self.trigger_player("minecraft:avoid_vibration");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- ticking ----
|
// ---- ticking ----
|
||||||
|
|||||||
@@ -489,7 +489,8 @@ pub fn can_receive_vibration(m: &Mob, _now: i64, ctx: &Context) -> bool {
|
|||||||
}
|
}
|
||||||
/// `VibrationSystem.Listener.handleGameEvent` for the warden: a free
|
/// `VibrationSystem.Listener.handleGameEvent` for the warden: a free
|
||||||
/// listener within 16 blocks of its eyes schedules what it can hear.
|
/// 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(
|
pub fn listen(
|
||||||
m: &mut Mob,
|
m: &mut Mob,
|
||||||
now: i64,
|
now: i64,
|
||||||
@@ -497,23 +498,35 @@ pub fn listen(
|
|||||||
pos: [f64; 3],
|
pos: [f64; 3],
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
occluded: impl Fn([f64; 3], [f64; 3]) -> bool,
|
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 eye = [m.position.x, m.position.y + m.kind.eye_height, m.position.z];
|
||||||
let Some(st) = m.extra.warden.as_ref() else {
|
let Some(st) = m.extra.warden.as_ref() else {
|
||||||
return;
|
return false;
|
||||||
};
|
};
|
||||||
if st.vibration.current.is_some() {
|
if st.vibration.current.is_some() {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
let block = |p: [f64; 3]| p.map(|v| i64::from(v.floor() as i32));
|
let block = |p: [f64; 3]| p.map(|v| i64::from(v.floor() as i32));
|
||||||
let (source, listener) = (block(pos), block(eye));
|
let (source, listener) = (block(pos), block(eye));
|
||||||
let d = [0, 1, 2].map(|i| source[i] - listener[i]);
|
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
|
if d[0] * d[0] + d[1] * d[1] + d[2] * d[2] > 256 {
|
||||||
|| !sculk::valid_vibration(sculk::warden_can_listen(event), event, ctx)
|
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)
|
|| !can_receive_vibration(m, i64::from(m.age), ctx)
|
||||||
|| occluded(pos, eye)
|
|| occluded(pos, eye)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
let d = [pos[0] - eye[0], pos[1] - eye[1], pos[2] - eye[2]];
|
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;
|
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,
|
now,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
/// `Level.gameEvent` for the mobs' own movement events from `from` on, as
|
/// `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.
|
/// the mob AI probe has no sculk layer: every warden's listener hears them.
|
||||||
|
|||||||
Reference in New Issue
Block a user