Sculk: pass over idle sensors and catalysts in the block entity tick
A sculk sensor, shrieker or catalyst with no vibration chosen, travelling or waiting, and no charge cursors, ticks without changing anything (vanilla's VibrationSystem.Ticker.tick and SculkSpreader.updateCursors return at once). The tick now leaves those out before asking whether the chunks around them tick (nine lookups each) and before looking them up a second time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -718,17 +718,24 @@ impl Game<'_> {
|
||||
})
|
||||
};
|
||||
// The ticking ones in the index's order, with whether the chunks
|
||||
// around them tick too.
|
||||
// around them tick too. Most sensors and catalysts wait for a
|
||||
// vibration or a death: their tick would change nothing, so they
|
||||
// are passed over here (a vibration scheduled during these ticks is
|
||||
// chosen on the next tick at the earliest, as in vanilla).
|
||||
let entities = &self.world.block_entities;
|
||||
let due: Vec<((i32, i32, i32), bool)> = self
|
||||
.sculk
|
||||
.index
|
||||
.iter()
|
||||
.filter_map(|&key| {
|
||||
let (cx, cz) = (key.0 >> 4, key.2 >> 4);
|
||||
ticks(cx, cz).then(|| {
|
||||
let adjacent = (-1..=1).all(|dx| (-1..=1).all(|dz| ticks(cx + dx, cz + dz)));
|
||||
(key, adjacent)
|
||||
})
|
||||
if !ticks(cx, cz)
|
||||
|| matches!(entities.get(&key), Some(BlockEntity::Sculk(e)) if e.idle())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let adjacent = (-1..=1).all(|dx| (-1..=1).all(|dz| ticks(cx + dx, cz + dz)));
|
||||
Some((key, adjacent))
|
||||
})
|
||||
.collect();
|
||||
for (key, adjacent) in due {
|
||||
|
||||
@@ -413,6 +413,13 @@ impl SculkEntity {
|
||||
spreader: SculkSpreader::default(),
|
||||
}
|
||||
}
|
||||
/// Whether its block entity tick does nothing: no vibration chosen
|
||||
/// or on its way, none waiting to be chosen, and no charge to spread.
|
||||
pub fn idle(&self) -> bool {
|
||||
self.vibration.current.is_none()
|
||||
&& self.vibration.selector.current().is_none()
|
||||
&& self.spreader.cursors.is_empty()
|
||||
}
|
||||
pub fn for_block(name: &str) -> Option<Self> {
|
||||
Some(Self::new(match name {
|
||||
"minecraft:sculk_sensor" => SculkKind::Sensor,
|
||||
|
||||
Reference in New Issue
Block a user