Merge pull request #1853 from ludovic111/fix/mob-ambient-particles

🤖 Agent: merged after verify and the parity harnesses this change reaches passed on its head.
This commit is contained in:
Ludovic Marie
2026-10-26 00:01:39 +01:00
committed by GitHub
7 changed files with 181 additions and 1 deletions
+50
View File
@@ -63,6 +63,10 @@ enum Animate {
SculkSensor,
/// Potent sulfur that is not dry.
PotentSulfur,
DriedGhast {
waterlogged: bool,
},
EndPortal,
}
fn step(facing: &str) -> [i32; 3] {
match facing {
@@ -137,6 +141,10 @@ fn classify(name: &str, prop: &dyn Fn(&str) -> Option<String>) -> Animate {
drag: prop("drag").as_deref() == Some("true"),
},
"fire" | "soul_fire" => Animate::Fire,
"dried_ghast" => Animate::DriedGhast {
waterlogged: prop("waterlogged").as_deref() == Some("true"),
},
"end_portal" => Animate::EndPortal,
"sculk_sensor" | "calibrated_sculk_sensor"
if prop("sculk_sensor_phase").as_deref() == Some("active") =>
{
@@ -180,6 +188,8 @@ pub struct AnimateTables {
impermeable: Vec<bool>,
power_provider: Vec<bool>,
power_transmitter: Vec<bool>,
/// `#triggers_ambient_dried_ghast_block_sounds` (soul sand, soul soil).
dried_ghast_sounds: Vec<bool>,
/// Biome id -> ambient particles and probabilities (`minecraft:visual/ambient_particles`).
ambient: Vec<Vec<(T, f32)>>,
}
@@ -237,6 +247,7 @@ impl AnimateTables {
impermeable: by_state("minecraft:impermeable"),
power_provider: by_state("minecraft:enchantment_power_provider"),
power_transmitter: by_state("minecraft:enchantment_power_transmitter"),
dried_ghast_sounds: by_state("minecraft:triggers_ambient_dried_ghast_block_sounds"),
ambient,
})
}
@@ -869,6 +880,45 @@ fn block_animate_tick(
];
add(engine, T::Smoke, p, [0.0; 3]);
}
Animate::DriedGhast { waterlogged } => {
// DriedGhastBlock.animateTick.
let c = [fx + 0.5, fy + 0.5, fz + 0.5];
if waterlogged {
if next_int(engine.random(), 40) == 0 {
let name = "minecraft:block.dried_ghast.ambient_water";
sound(engine, name, c, 1.0, 1.0);
}
let r = engine.random();
if next_int(r, 6) == 0 {
let x = c[0] + f64::from((r.next_float() * 2.0 - 1.0) / 3.0);
let y = c[1] + 0.4;
let z = c[2] + f64::from((r.next_float() * 2.0 - 1.0) / 3.0);
let v = [0.0, f64::from(r.next_float()), 0.0];
add(engine, T::HappyVillager, [x, y, z], v);
}
} else {
let below = ctx.state([pos[0], pos[1] - 1, pos[2]]);
let triggers = || {
tables
.dried_ghast_sounds
.get(below.0 as usize)
.copied()
.unwrap_or(false)
};
if next_int(engine.random(), 40) == 0 && triggers() {
sound(engine, "minecraft:block.dried_ghast.ambient", c, 1.0, 1.0);
}
if next_int(engine.random(), 6) == 0 {
add(engine, T::WhiteSmoke, c, [0.0, 0.02, 0.0]);
}
}
}
Animate::EndPortal => {
// EndPortalBlock.animateTick: one smoke particle above the surface.
let r = engine.random();
let p = [fx + r.next_double(), fy + 0.8, fz + r.next_double()];
add(engine, T::Smoke, p, [0.0; 3]);
}
Animate::EnderChest => {
for _ in 0..3 {
let r = engine.random();
+2
View File
@@ -20,6 +20,7 @@ mod bossbars;
mod breezes;
mod cartography;
mod chat;
mod client_ambient;
mod clipboard;
mod combat;
mod command_blocks;
@@ -4481,6 +4482,7 @@ impl Game<'_> {
self.tick_block_entity_anims()
});
horizon_client::spans::time("tick_particles", || self.tick_particles());
self.tick_client_ambient();
}
// ServerBossEvent broadcasts, after this level's entities have ticked.
self.publish_boss_bars();
@@ -0,0 +1,37 @@
//! The window's own ambient effects of entities, which a client makes for
//! itself (`level().isClientSide()` branches): endermen's and endermites'
//! portal particles, blazes' smoke and burn, eyes of ender's trail. They run
//! on the game that has the window, in-frame or following a server, never on
//! a server: nothing of them goes over the network.
use super::Game;
use horizon_client::mobs::{MobEvent, ambient};
use horizon_client::particles::{ParticleOptions, ParticleType};
impl Game<'_> {
pub(super) fn tick_client_ambient(&mut self) {
if self.serving.is_some() || self.options.dedicated.is_some() {
return;
}
let mut events = Vec::new();
for m in self.mobs.iter_mut().filter(|m| !m.removed) {
ambient::client_ai_step(m, &mut events);
}
for event in events {
match event {
MobEvent::ParticleAt { kind, at, velocity } => {
if let Some(ty) = ParticleType::from_name(kind) {
self.particles
.add(&ParticleOptions::simple(ty), at, velocity);
}
}
// Each guest of a LAN host makes its own.
MobEvent::LocalSound(name, at, volume, pitch) => {
self.audio
.play_unshared(&format!("minecraft:{name}"), Some(at), volume, pitch)
}
_ => {}
}
}
self.eye_particles();
}
}
+35 -1
View File
@@ -4,7 +4,12 @@
//! inactive until the dragon dies.
use super::{Dim, Game};
use horizon_client::{
Result, environment::Environment, items::ItemStack, mesher::Vertex, motion::PlayerMotion,
Result,
environment::Environment,
items::ItemStack,
mesher::Vertex,
motion::PlayerMotion,
particles::{ParticleOptions, ParticleType},
vanillagen::VanillaTerrain,
};
use horizon_core::{
@@ -1122,6 +1127,35 @@ impl Game<'_> {
self.end.eyes = eyes;
}
/// `EyeOfEnder.tick` on a client: behind each eye (a quarter of its last
/// move back), four bubbles in water, else a portal particle.
pub(super) fn eye_particles(&mut self) {
for i in 0..self.end.eyes.len() {
let e = &self.end.eyes[i];
let movement = (e.position - e.previous).to_array();
let origin = (e.position - (e.position - e.previous) * 0.25).to_array();
let block = origin.map(|v| v.floor() as i32);
let water = self
.res
.facts()
.get(self.world.block(block[0], block[1], block[2]))
.fluid
== horizon_client::blocks::Fluid::Water;
if water {
let bubble = ParticleOptions::simple(ParticleType::Bubble);
for _ in 0..4 {
self.particles.add(&bubble, origin, movement);
}
} else {
let r = self.particles.random();
let x = origin[0] + r.next_double() * 0.6 - 0.3;
let z = origin[2] + r.next_double() * 0.6 - 0.3;
let portal = ParticleOptions::simple(ParticleType::Portal);
self.particles
.add(&portal, [x, origin[1] - 0.5, z], movement);
}
}
}
/// ThrownItemRenderer: the ender eye item facing the camera.
fn eye_geometry(&self, camera: glam::DVec3, out: &mut Vec<Vertex>) {
let Some(r) = self.gui.atlas.sprites.get("item/ender_eye").copied() else {
+1
View File
@@ -3060,6 +3060,7 @@ impl Game<'_> {
self.tick_block_entity_anims();
self.tick_hand();
self.tick_particles();
self.tick_client_ambient();
self.tick_client_effects();
// Player.tick's sleep counter (the darkening and the wake-up fade).
self.sleep_timer = super::tick_sleep_timer(self.sleep_timer, self.sleeping.is_some());
+1
View File
@@ -7,6 +7,7 @@
//! behaviour, models, animations and sounds.
pub mod ai;
pub mod allay;
pub mod ambient;
pub mod anim;
pub mod animal_brain;
pub mod aquatic;
+55
View File
@@ -0,0 +1,55 @@
//! What a client's copy of a mob makes on its own, in the
//! `level().isClientSide()` branches of `aiStep`: nothing of it reaches the
//! server or goes over the network, so the window's game runs it, whether it
//! simulates the world (in-frame) or follows a server.
use super::{Mob, MobEvent, Species};
use horizon_core::random::RandomSource;
/// `Enderman.aiStep`, `Endermite.aiStep` and `Blaze.aiStep` on a client:
/// two portal particles a tick around endermen and endermites; two large
/// smoke particles a tick around blazes and, one tick in 24, their burn.
pub fn client_ai_step(m: &mut Mob, out: &mut Vec<MobEvent>) {
let species = m.species();
if !matches!(
species,
Species::Enderman | Species::Endermite | Species::Blaze
) {
return;
}
let (w, h) = (f64::from(m.width()), f64::from(m.height()));
let p = m.position;
if species == Species::Blaze && m.random.next_int_bound(24).unwrap_or(1) == 0 && !m.silent {
let volume = 1.0 + m.random.next_float();
let pitch = m.random.next_float() * 0.7 + 0.3;
out.push(MobEvent::LocalSound(
"entity.blaze.burn",
[p.x + 0.5, p.y + 0.5, p.z + 0.5],
volume,
pitch,
));
}
for _ in 0..2 {
// Entity.getRandomX(0.5), getRandomY(), getRandomZ(0.5).
let r = &mut m.random;
let x = p.x + w * (2.0 * r.next_double() - 1.0) * 0.5;
let y = p.y + h * r.next_double();
let z = p.z + w * (2.0 * r.next_double() - 1.0) * 0.5;
let (kind, at, velocity) = if species == Species::Blaze {
("large_smoke", [x, y, z], [0.0; 3])
} else {
// The enderman's are a quarter block lower.
let y = if species == Species::Enderman {
y - 0.25
} else {
y
};
let velocity = [
(r.next_double() - 0.5) * 2.0,
-r.next_double(),
(r.next_double() - 0.5) * 2.0,
];
("portal", [x, y, z], velocity)
};
out.push(MobEvent::ParticleAt { kind, at, velocity });
}
}