From efa2f0e3be5e4b9d8f29b91ed82830e74774fa47 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 14 Oct 2026 16:24:37 +0200 Subject: [PATCH] Particles: 29 missing vanilla particle types Horizon's engine knew 91 of vanilla's 128 particle types. These come from their real providers, constructor to tick: - sweep_attack (AttackSweepParticle) - glow, wax_on, wax_off, electric_spark, scrape (GlowParticle and its providers) - squid_ink, glow_squid_ink (SquidInkParticle: sinks through air) - item, item_slime, item_snowball, item_cobweb, sulfur_cube_goo (BreakingItemParticle: a quarter of the item's ground-model sprite in full colour, unlike terrain crumbs) - flash (FireworkParticles.OverlayParticle, its sine pulse and fading alpha), which firework explosions now show as vanilla's Starter does - firefly (FireflyParticle: wanders, fades in and out, vanishes inside blocks) - trial_spawner_detection(_ominous) (TrialSpawnerDetectionParticle) - trial_omen, raid_omen (SpellParticle) - ominous_spawning (FlyStraightTowardsParticle, colour lerped like ARGB.srgbLerp) - spit (ExplodeParticle falling at 0.5), fishing (WakeParticle), dust_plume (DustPlumeParticle) - red/orange/yellow_poplar_leaves (FallingLeavesParticle.PoplarProvider) - pause_mob_growth, reset_mob_growth (SimpleVerticalParticle) - block_marker (BlockMarker) ParticleType.getOverrideLimiter now lists every type vanilla registers with it (gust, sonic_boom, sculk charges, campfire smoke, vault_connection and the new ones were missing), so they show beyond 32 blocks. The /particle commands take the new types; item particles resolve the stack's ground model. The particle_providers harness now builds all 120 types Horizon implements through the real providers (1428 cases). Part of #63 Co-Authored-By: Claude Opus 5.5 --- .../examples/particle_providers_probe.rs | 24 +- crates/horizon-client/src/game.rs | 1 + .../src/game/commands/world_cmds.rs | 25 +- .../horizon-client/src/game/item_particles.rs | 35 ++ .../horizon-client/src/game/render_control.rs | 14 +- crates/horizon-client/src/particles.rs | 503 +++++++++++++++++- .../VanillaParticleProvidersOracle.java | 1 + tools/test_particle_providers_parity.py | 18 +- 8 files changed, 599 insertions(+), 22 deletions(-) create mode 100644 crates/horizon-client/src/game/item_particles.rs diff --git a/crates/horizon-client/examples/particle_providers_probe.rs b/crates/horizon-client/examples/particle_providers_probe.rs index ddd71b52e..7c819eccd 100644 --- a/crates/horizon-client/examples/particle_providers_probe.rs +++ b/crates/horizon-client/examples/particle_providers_probe.rs @@ -46,9 +46,10 @@ fn options(case: &Value) -> Option { [r, g, b, ((c >> 24) & 255) as f32 / 255.0] }; Some(match ty { - ParticleType::Block | ParticleType::BlockCrumble | ParticleType::DustPillar => { - ParticleOptions::block(ty, "terrain".into(), 0xFF_FFFF) - } + ParticleType::Block + | ParticleType::BlockCrumble + | ParticleType::DustPillar + | ParticleType::BlockMarker => ParticleOptions::block(ty, "terrain".into(), 0xFF_FFFF), // Stone's map colour: FallingDustParticle.Provider's tint without a tint source. ParticleType::FallingDust => ParticleOptions::block(ty, "terrain".into(), 0x70_7070), ParticleType::Dust => ParticleOptions::dust(rgb(c), scale), @@ -59,7 +60,15 @@ fn options(case: &Value) -> Option { scale, ..ParticleOptions::colored(ty, argb) }, - ParticleType::EntityEffect | ParticleType::TintedLeaves => { + // The oracle's item models: one layer whose sprite is named after the item. + ParticleType::Item => { + let item = o["item"].as_str()?; + ParticleOptions::item(vec![format!( + "item_{}", + item.strip_prefix("minecraft:").unwrap_or(item) + )]) + } + ParticleType::EntityEffect | ParticleType::TintedLeaves | ParticleType::Flash => { ParticleOptions::colored(ty, argb) } ParticleType::DragonBreath => ParticleOptions { @@ -137,6 +146,13 @@ fn main() -> Result<()> { world(&assets, &facts, true)?, ]; let mut engine = ParticleEngine::new(root, &HashMap::new()); + for (ty, item) in [ + (ParticleType::ItemSlime, "item_slime_ball"), + (ParticleType::ItemSnowball, "item_snowball"), + (ParticleType::ItemCobweb, "item_cobweb"), + ] { + engine.item_sprites.insert(ty, vec![item.to_owned()]); + } // The oracle's output: the seed line of each case. let mut seeds = Vec::new(); for line in BufReader::new(File::open(&args[2])?).lines() { diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 3cd8d5105..d6b027c57 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -45,6 +45,7 @@ mod golems; mod growth; mod hand; mod item_draw; +mod item_particles; mod jukebox; mod lan; mod lan_actions; diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs index 0a6cb379a..43049111a 100644 --- a/crates/horizon-client/src/game/commands/world_cmds.rs +++ b/crates/horizon-client/src/game/commands/world_cmds.rs @@ -418,7 +418,30 @@ impl Game<'_> { .unwrap_or(1.0) .clamp(0.01, 4.0), ), - ParticleType::Block | ParticleType::FallingDust | ParticleType::DustPillar => { + // ItemParticleOption: an item id, or a stack {id, ...}. + ParticleType::Item => { + let id = match field("item") { + Some(Tag::String(s)) => s.to_string_lossy(), + Some(Tag::Compound(c)) => { + c.get(&"id".into()).and_then(string).unwrap_or_default() + } + _ => String::new(), + }; + let id = if id.contains(':') { + id + } else { + format!("minecraft:{id}") + }; + self.item_particle(&horizon_client::items::ItemStack::new(&id, 1)) + } + ParticleType::ItemSlime | ParticleType::ItemSnowball | ParticleType::ItemCobweb => { + self.ensure_item_particle_sprites(); + ParticleOptions::simple(ty) + } + ParticleType::Block + | ParticleType::FallingDust + | ParticleType::DustPillar + | ParticleType::BlockMarker => { // BlockParticleOption: a block id, or {Name, Properties}. let text = match field("block_state") { Some(Tag::String(s)) => s.to_string_lossy(), diff --git a/crates/horizon-client/src/game/item_particles.rs b/crates/horizon-client/src/game/item_particles.rs new file mode 100644 index 000000000..a60fca68a --- /dev/null +++ b/crates/horizon-client/src/game/item_particles.rs @@ -0,0 +1,35 @@ +//! The sprites of item particles: `BreakingItemParticle.ItemParticleProvider.getSprite` +//! resolves the stack's model for the ground and picks a layer's particle sprite. +use super::Game; +use horizon_assets::item_model::DisplayContext; +use horizon_client::{ + items::ItemStack, + particles::{ParticleOptions, ParticleType}, +}; + +impl Game<'_> { + /// `ItemParticleOption(ITEM, stack)`: the layer particle sprites of the + /// stack's model resolved for the ground, with seed 0. + pub(super) fn item_particle(&self, stack: &ItemStack) -> ParticleOptions { + let state = self.resolve_item(stack, DisplayContext::Ground, None, 0); + ParticleOptions::item(state.layers.iter().map(|l| l.particle.clone()).collect()) + } + /// The slime ball, snowball and cobweb models behind `item_slime`, + /// `item_snowball` and `item_cobweb`, resolved on first use. + pub(super) fn ensure_item_particle_sprites(&mut self) { + if !self.particles.item_sprites.is_empty() { + return; + } + for (ty, item) in [ + (ParticleType::ItemSlime, "minecraft:slime_ball"), + (ParticleType::ItemSnowball, "minecraft:snowball"), + (ParticleType::ItemCobweb, "minecraft:cobweb"), + ] { + let sprites = self + .item_particle(&ItemStack::new(item, 1)) + .item + .unwrap_or_default(); + self.particles.item_sprites.insert(ty, sprites); + } + } +} diff --git a/crates/horizon-client/src/game/render_control.rs b/crates/horizon-client/src/game/render_control.rs index cf57a9abe..d34b1d7ab 100644 --- a/crates/horizon-client/src/game/render_control.rs +++ b/crates/horizon-client/src/game/render_control.rs @@ -83,9 +83,21 @@ impl Game<'_> { let count = num(8, 1.0)? as u32; let options = match ty { ParticleType::Dust => ParticleOptions::dust([1.0, 0.0, 0.0], 1.0), - ParticleType::Block | ParticleType::FallingDust | ParticleType::DustPillar => { + ParticleType::Block + | ParticleType::FallingDust + | ParticleType::DustPillar + | ParticleType::BlockMarker => { ParticleOptions::block(ty, "block/stone".into(), 0x808080) } + ParticleType::Item => self.item_particle( + &horizon_client::items::ItemStack::new("minecraft:apple", 1), + ), + ParticleType::ItemSlime + | ParticleType::ItemSnowball + | ParticleType::ItemCobweb => { + self.ensure_item_particle_sprites(); + ParticleOptions::simple(ty) + } _ => ParticleOptions::simple(ty), }; // ServerLevel.sendParticles: count 0 uses the delta as velocity. diff --git a/crates/horizon-client/src/particles.rs b/crates/horizon-client/src/particles.rs index f9ecd61ba..34d0957de 100644 --- a/crates/horizon-client/src/particles.rs +++ b/crates/horizon-client/src/particles.rs @@ -130,18 +130,69 @@ particle_types! { Shriek = "shriek", SonicBoom = "sonic_boom", Vibration = "vibration", + SweepAttack = "sweep_attack", + Glow = "glow", + WaxOn = "wax_on", + WaxOff = "wax_off", + ElectricSpark = "electric_spark", + Scrape = "scrape", + SquidInk = "squid_ink", + GlowSquidInk = "glow_squid_ink", + Item = "item", + ItemSlime = "item_slime", + ItemSnowball = "item_snowball", + ItemCobweb = "item_cobweb", + SulfurCubeGoo = "sulfur_cube_goo", + Flash = "flash", + Firefly = "firefly", + TrialSpawnerDetection = "trial_spawner_detection", + TrialSpawnerDetectionOminous = "trial_spawner_detection_ominous", + TrialOmen = "trial_omen", + RaidOmen = "raid_omen", + OminousSpawning = "ominous_spawning", + Spit = "spit", + Fishing = "fishing", + DustPlume = "dust_plume", + RedPoplarLeaves = "red_poplar_leaves", + OrangePoplarLeaves = "orange_poplar_leaves", + YellowPoplarLeaves = "yellow_poplar_leaves", + PauseMobGrowth = "pause_mob_growth", + ResetMobGrowth = "reset_mob_growth", + BlockMarker = "block_marker", } impl ParticleType { - /// `ParticleType.getOverrideLimiter`: spawned regardless of distance. + /// `ParticleType.getOverrideLimiter` (`ParticleTypes.register(name, true)`): + /// spawned regardless of distance. pub fn override_limiter(self) -> bool { matches!( self, - Self::DamageIndicator + Self::BlockMarker + | Self::DamageIndicator | Self::ExplosionEmitter | Self::Explosion - | Self::Poof + | Self::Gust | Self::GustEmitterLarge | Self::GustEmitterSmall + | Self::SonicBoom + | Self::SculkCharge + | Self::SculkChargePop + | Self::Vibration + | Self::Poof + | Self::Spit + | Self::SquidInk + | Self::SweepAttack + | Self::CampfireCosySmoke + | Self::CampfireSignalSmoke + | Self::GlowSquidInk + | Self::Glow + | Self::WaxOn + | Self::WaxOff + | Self::ElectricSpark + | Self::Scrape + | Self::TrialSpawnerDetection + | Self::TrialSpawnerDetectionOminous + | Self::VaultConnection + | Self::OminousSpawning ) } } @@ -161,6 +212,9 @@ pub struct ParticleOptions { pub to_color: [f32; 3], /// `TrailParticleOption`: the point it flies to and how many ticks it takes. pub trail: Option<([f64; 3], i32)>, + /// `ItemParticleOption`: the particle sprite of each layer of the item's + /// model as resolved for the ground. + pub item: Option>, } impl ParticleOptions { pub fn simple(ty: ParticleType) -> Self { @@ -171,6 +225,14 @@ impl ParticleOptions { scale: 1.0, to_color: [1.0, 0.0, 0.0], trail: None, + item: None, + } + } + /// `ItemParticleOption`: the stack's layer particle sprites (`BreakingItemParticle`). + pub fn item(layers: Vec) -> Self { + Self { + item: Some(layers), + ..Self::simple(ParticleType::Item) } } /// `DustColorTransitionOptions`. @@ -260,6 +322,8 @@ enum Size { ReversePortal, /// `ShriekParticle.getQuadSize`. Shriek, + /// `FireworkParticles.OverlayParticle.getQuadSize`: a sine pulse. + Flash, } #[derive(Clone, Copy, Debug, PartialEq)] enum Light { @@ -271,6 +335,8 @@ enum Light { AgeEmission, /// `addSmoothBlockEmission` with the age fraction to the fourth power. AgeEmission4, + /// `FireflyParticle.getLightCoords`: block light fading in and out, no sky. + Firefly, } #[derive(Clone, Copy, Debug, PartialEq)] enum Behaviour { @@ -359,6 +425,20 @@ enum Behaviour { Trail { target: [f64; 3], }, + /// `SquidInkParticle`: `SimpleAnimatedParticle`, sinking through air. + SquidInk, + /// `FireflyParticle`: wanders, fading in and out, gone inside blocks. + Firefly, + /// `WakeParticle` (fishing): grows and cycles four sprites. + Wake, + /// `DustPlumeParticle`: gravity and friction decay every tick. + DustPlume, + /// `FlyStraightTowardsParticle`: from its start along its motion back to + /// the start, the colour moving from one to the other. + FlyStraight { + start: [f64; 3], + colors: [u32; 2], + }, } #[derive(Clone, Copy, Debug, PartialEq)] enum DripStage { @@ -692,6 +772,11 @@ impl Particle { let b = (b * b) * (b * b); (sky, (block + (b.clamp(0.0, 1.0) * 240.0) as u32).min(240)) } + Light::Firefly => ( + 0, + (255.0 * fade_amount(self.lifetime_progress(self.age as f32 + partial), 0.1, 0.3)) + as u32, + ), } } fn quad_size(&self, a: f32) -> f32 { @@ -709,8 +794,27 @@ impl Particle { self.size * (1.0 - (self.age as f32 + a) / (self.lifetime as f32 * 1.5)) } Size::Shriek => self.size * (t * 0.75).clamp(0.0, 1.0), + Size::Flash => { + 7.1 * trig::sin(f64::from( + (self.age as f32 + a - 1.0) * 0.25 * std::f64::consts::PI as f32, + )) + } } } + /// `FireflyParticle.getLifetimeProgress`. + fn lifetime_progress(&self, age: f32) -> f32 { + (age / self.lifetime as f32).clamp(0.0, 1.0) + } +} +/// `FireflyParticle.getFadeAmount`. +fn fade_amount(progress: f32, fade_in: f32, fade_out: f32) -> f32 { + if progress >= 1.0 - fade_in { + (1.0 - progress) / fade_in + } else if progress <= fade_out { + progress / fade_out + } else { + 1.0 + } } /// A particle's fields as the parity probe reports them. @@ -827,6 +931,9 @@ pub struct ParticleEngine { starters: Vec, /// Local sounds requested by particles (dripstone drips): (event, position, volume, pitch). pub sounds: Vec<(&'static str, [f64; 3], f32, f32)>, + /// The item particles' sprites (`BreakingItemParticle`'s slime ball, snowball + /// and cobweb models, resolved for the ground), one per model layer. + pub item_sprites: HashMap>, } /// `ParticleGroup.MAX_PARTICLES` (per render group; one group here). const MAX_PARTICLES: usize = 16384; @@ -849,6 +956,7 @@ impl ParticleEngine { starters: Vec::new(), camera: [0.0; 3], sounds: Vec::new(), + item_sprites: HashMap::new(), }; let dir = root.join("assets/minecraft/particles"); for &ty in ParticleType::ALL { @@ -1227,12 +1335,22 @@ impl ParticleEngine { q.set = set; q } - T::Smoke | T::LargeSmoke | T::WhiteSmoke | T::Ash | T::WhiteAsh => { + T::Smoke | T::LargeSmoke | T::WhiteSmoke | T::Ash | T::WhiteAsh | T::DustPlume => { // BaseAshSmokeParticle(dir, xa, scale, colorRandom, maxLifetime, gravity, hasPhysics). let (dir, scale, color_random, max_lifetime, gravity, physics, vel) = match ty { T::Smoke | T::WhiteSmoke => ([0.1, 0.1, 0.1], 1.0, 0.3, 8, -0.1, true, v), T::LargeSmoke => ([0.1, 0.1, 0.1], 2.5, 0.3, 8, -0.1, true, v), T::Ash => ([0.1, -0.1, 0.1], 1.0, 0.5, 20, 0.1, false, [0.0; 3]), + // DustPlumeParticle: ya + 0.15F. + T::DustPlume => ( + [0.7, 0.6, 0.7], + 1.0, + 0.5, + 7, + 0.5, + false, + [v[0], v[1] + f64::from(0.15f32), v[2]], + ), _ => { // WhiteAshParticle.Provider draws the motion. let pr = &mut self.random; @@ -1267,6 +1385,15 @@ impl ParticleEngine { } q.size_curve = Size::GrowIn; q.behaviour = Behaviour::Animated; + if ty == T::DustPlume { + let shift = r.next_float() * 0.2; + q.set_color( + 186.0 / 255.0 - shift, + 177.0 / 255.0 - shift, + 194.0 / 255.0 - shift, + ); + q.behaviour = Behaviour::DustPlume; + } q.set = set; q } @@ -1740,9 +1867,9 @@ impl ParticleEngine { } q } - T::Poof | T::Snowflake => { + T::Poof | T::Snowflake | T::Spit => { let mut q = Particle::at(r, ty, p); - if ty == T::Poof { + if ty != T::Snowflake { q.gravity = -0.1; q.friction = 0.9; } else { @@ -1752,7 +1879,7 @@ impl ParticleEngine { for i in 0..3 { q.velocity[i] = v[i] + f64::from((r.next_float() * 2.0 - 1.0) * 0.05); } - if ty == T::Poof { + if ty != T::Snowflake { let col = r.next_float() * 0.3 + 0.7; q.set_color(col, col, col); q.size = 0.1 * (r.next_float() * r.next_float() * 6.0 + 1.0); @@ -1760,11 +1887,15 @@ impl ParticleEngine { q.size = 0.1 * (r.next_float() * r.next_float() + 1.0); } q.lifetime = (16.0 / (f64::from(r.next_float()) * 0.8 + 0.2)) as i32 + 2; - q.behaviour = if ty == T::Poof { - Behaviour::Animated - } else { + q.behaviour = if ty == T::Snowflake { Behaviour::Snowflake + } else { + Behaviour::Animated }; + // SpitParticle: ExplodeParticle falling at gravity 0.5. + if ty == T::Spit { + q.gravity = 0.5; + } if ty == T::Snowflake { q.set_color(0.923, 0.964, 0.999); } @@ -2005,7 +2136,12 @@ impl ParticleEngine { q.set = set; q } - T::CherryLeaves | T::PaleOakLeaves | T::TintedLeaves => { + T::CherryLeaves + | T::PaleOakLeaves + | T::TintedLeaves + | T::RedPoplarLeaves + | T::OrangePoplarLeaves + | T::YellowPoplarLeaves => { let (fall, side, swirl, flow, scale, start) = if ty == T::CherryLeaves { (0.25f32, 2.0f32, false, true, 1.0f32, 0.0f32) } else { @@ -2041,7 +2177,13 @@ impl ParticleEngine { }; q } - T::Effect | T::InstantEffect | T::EntityEffect | T::Witch | T::Infested => { + T::Effect + | T::InstantEffect + | T::EntityEffect + | T::Witch + | T::Infested + | T::TrialOmen + | T::RaidOmen => { // SpellParticle: x/z velocity from `SpellParticle.RANDOM`, y from the option. let xa = 0.5 - self.spell_random.next_double(); let za = 0.5 - self.spell_random.next_double(); @@ -2117,6 +2259,239 @@ impl ParticleEngine { q.set_power(o.scale); q } + // AttackSweepParticle: `xAux` shrinks it; still, bright, animated over 4 ticks. + T::SweepAttack => { + let mut q = Particle::moving(r, ty, p, [0.0; 3]); + q.lifetime = 4; + let col = r.next_float() * 0.6 + 0.4; + q.set_color(col, col, col); + q.size = 1.0 - v[0] as f32 * 0.5; + q.light = Light::FullBright; + q.behaviour = Behaviour::HugeExplosion; + q.set = set; + q + } + // GlowParticle and its providers. + T::Glow | T::WaxOn | T::WaxOff | T::ElectricSpark | T::Scrape => { + let pr = &mut self.random; + let start = if ty == T::Glow { + let xa = 0.5 - pr.next_double(); + [xa, v[1], 0.5 - pr.next_double()] + } else { + [0.0; 3] + }; + let mut q = Particle::moving(r, ty, p, start); + q.friction = 0.96; + q.speed_up_when_y_blocked = true; + q.size *= 0.75; + q.has_physics = false; + q.light = Light::AgeEmission; + q.behaviour = Behaviour::Animated; + q.set = set; + match ty { + T::ElectricSpark => { + q.set_color(1.0, 0.9, 1.0); + q.velocity = [v[0] * 0.25, v[1] * 0.25, v[2] * 0.25]; + q.lifetime = pr.next_int_bound(2).unwrap_or(0) + 2; + } + T::Glow => { + if pr.next_boolean() { + q.set_color(0.6, 1.0, 0.8); + } else { + q.set_color(0.08, 0.4, 0.4); + } + q.velocity[1] *= f64::from(0.2f32); + if v[0] == 0.0 && v[2] == 0.0 { + q.velocity[0] *= f64::from(0.1f32); + q.velocity[2] *= f64::from(0.1f32); + } + q.lifetime = (8.0 / (pr.next_double() * 0.8 + 0.2)) as i32; + } + T::Scrape => { + if pr.next_boolean() { + q.set_color(0.29, 0.58, 0.51); + } else { + q.set_color(0.43, 0.77, 0.62); + } + q.velocity = [v[0] * 0.01, v[1] * 0.01, v[2] * 0.01]; + q.lifetime = pr.next_int_bound(30).unwrap_or(0) + 10; + } + _ => { + if ty == T::WaxOn { + q.set_color(0.91, 0.55, 0.08); + } else { + q.set_color(1.0, 0.9, 1.0); + } + q.velocity = [v[0] * 0.01 / 2.0, v[1] * 0.01, v[2] * 0.01 / 2.0]; + q.lifetime = pr.next_int_bound(30).unwrap_or(0) + 10; + } + } + q + } + // SquidInkParticle (SimpleAnimatedParticle, gravity 0). + T::SquidInk | T::GlowSquidInk => { + let mut q = Particle::at(r, ty, p); + q.friction = 0.92; + q.size = 0.5; + if ty == T::GlowSquidInk { + // ARGB.colorFromFloat(1, 0.2, 0.8, 0.6), back to floats. + q.set_color(51.0 / 255.0, 204.0 / 255.0, 153.0 / 255.0); + } else { + q.set_color(0.0, 0.0, 0.0); + } + q.lifetime = (q.size * 12.0 / (r.next_float() * 0.8 + 0.2)) as i32; + q.has_physics = false; + q.velocity = v; + q.light = Light::FullBright; + q.behaviour = Behaviour::SquidInk; + q.set = set; + q + } + // BreakingItemParticle: a crumb of the item's sprite. + T::Item | T::ItemSlime | T::ItemSnowball | T::ItemCobweb | T::SulfurCubeGoo => { + let sprite = if ty == T::SulfurCubeGoo { + self.first(ty) + } else { + // ItemStackRenderState.pickParticleMaterial. + let layers = match ty { + T::Item => o.item.clone().unwrap_or_default(), + _ => self.item_sprites.get(&ty).cloned().unwrap_or_default(), + }; + if layers.is_empty() { + Sprite::Index(u32::MAX) + } else { + let i = self.random.next_int_bound(layers.len() as i32).unwrap_or(0); + Sprite::Named(layers[i as usize].clone()) + } + }; + let mut q = Particle::moving(r, ty, p, [0.0; 3]); + q.sprite = sprite; + q.gravity = 1.0; + q.size /= 2.0; + let uo = r.next_float() * 3.0; + let vo = r.next_float() * 3.0; + q.uv = [(uo + 1.0) / 4.0, vo / 4.0, uo / 4.0, (vo + 1.0) / 4.0]; + if ty == T::Item { + for i in 0..3 { + q.velocity[i] = q.velocity[i] * f64::from(0.1f32) + v[i]; + } + } + q + } + // FireworkParticles.OverlayParticle: the flash of an explosion. + T::Flash => { + let mut q = Particle::at(r, ty, p); + q.lifetime = 4; + q.set_color(o.color[0], o.color[1], o.color[2]); + q.rgba[3] = o.color[3]; + q.size_curve = Size::Flash; + q + } + // FireflyParticle; the provider draws its motion, sprite and lifetime. + T::Firefly => { + let pr = &mut self.random; + let xa = 0.5 - pr.next_double(); + let ya = if pr.next_boolean() { v[1] } else { -v[1] }; + let za = 0.5 - pr.next_double(); + let sprite = self.sprite_from_set(ty); + let mut q = Particle::moving(r, ty, p, [xa, ya, za]); + q.sprite = sprite; + q.speed_up_when_y_blocked = true; + q.friction = 0.96; + q.size *= 0.75; + q.velocity[1] *= f64::from(0.8f32); + q.velocity[0] *= f64::from(0.8f32); + q.velocity[2] *= f64::from(0.8f32); + q.lifetime = self + .random + .next_int_between_inclusive(200, 300) + .unwrap_or(200); + q.scale(1.5); + q.rgba[3] = 0.0; + q.light = Light::Firefly; + q.behaviour = Behaviour::Firefly; + q + } + // TrialSpawnerDetectionParticle (scale 1.5 from the provider). + T::TrialSpawnerDetection | T::TrialSpawnerDetectionOminous => { + let scale = 1.5f32; + let mut q = Particle::moving(r, ty, p, [0.0; 3]); + q.friction = 0.96; + q.gravity = -0.1; + q.speed_up_when_y_blocked = true; + q.velocity[0] *= 0.0; + q.velocity[1] *= 0.9; + q.velocity[2] *= 0.0; + for i in 0..3 { + q.velocity[i] += v[i]; + } + q.size *= 0.75 * scale; + // Mth.randomBetween(random, 0.5, 1.0). + q.lifetime = ((8.0 / (r.next_float() * (1.0 - 0.5) + 0.5) * scale) as i32).max(1); + q.light = Light::Block15; + q.size_curve = Size::GrowIn; + q.behaviour = Behaviour::Animated; + q.set = set; + q + } + // FlyStraightTowardsParticle.OminousSpawnProvider. + T::OminousSpawning => { + let sprite = self.sprite_from_set(ty); + let mut q = Particle::at(r, ty, p); + q.sprite = sprite; + q.velocity = v; + let start = [p[0] + v[0], p[1] + v[1], p[2] + v[2]]; + q.previous = start; + q.position = start; + q.size = 0.1 * (r.next_float() * 0.5 + 0.2); + q.has_physics = false; + q.free_move = true; + q.lifetime = (r.next_float() * 5.0) as i32 + 25; + q.light = Light::Block15; + q.behaviour = Behaviour::FlyStraight { + start: p, + colors: [0xFF45_AEFE, 0xFFFF_FFFF], + }; + // Mth.randomBetween(level.getRandom(), 3, 5). + let s = self.level_random.next_float() * (5.0 - 3.0) + 3.0; + q.scale(s); + q + } + // WakeParticle. + T::Fishing => { + let mut q = Particle::moving(r, ty, p, [0.0; 3]); + q.velocity[0] *= f64::from(0.3f32); + q.velocity[1] = f64::from(r.next_float() * 0.2 + 0.1); + q.velocity[2] *= f64::from(0.3f32); + q.set_size(0.01, 0.01); + q.lifetime = (8.0 / (f64::from(r.next_float()) * 0.8 + 0.2)) as i32; + q.gravity = 0.0; + q.velocity = v; + q.behaviour = Behaviour::Wake; + q.set = set; + q + } + // SimpleVerticalParticle. + T::PauseMobGrowth | T::ResetMobGrowth => { + let mut q = Particle::moving(r, ty, p, v); + q.velocity = v; + q.gravity = 0.0; + q.velocity[1] += if ty == T::ResetMobGrowth { 0.03 } else { -0.03 }; + q.size *= r.next_float() * 0.6 + 0.5; + q.lifetime = 8; + q + } + // BlockMarker: the block's particle sprite, half a block wide, 80 ticks. + T::BlockMarker => { + let (sprite, _) = o.block.clone()?; + let mut q = Particle::at(r, ty, p); + q.sprite = Sprite::Named(sprite); + q.gravity = 0.0; + q.lifetime = 80; + q.has_physics = false; + q.size = 0.5; + q + } T::Trail => { let (target, duration) = o.trail?; let mut q = Particle::moving(r, ty, p, v); @@ -2256,6 +2631,19 @@ impl ParticleEngine { } } } + // The flash: ColorParticleOption.create(FLASH, first colour), alpha 0. + let c = colors[0]; + let rgba = [ + ((c >> 16) & 255) as f32 / 255.0, + ((c >> 8) & 255) as f32 / 255.0, + (c & 255) as f32 / 255.0, + ((c >> 24) & 255) as f32 / 255.0, + ]; + self.create( + &ParticleOptions::colored(ParticleType::Flash, rgba), + s.at, + [0.0; 3], + ); } s.life += 1; if s.life > s.lifetime { @@ -2886,6 +3274,93 @@ impl ParticleEngine { p.velocity[1] -= f64::from(0.003f32); p.velocity[1] = p.velocity[1].max(f64::from(-0.14f32)); } + Behaviour::SquidInk => { + // SimpleAnimatedParticle.tick, then SquidInkParticle's. + p.base_tick(level); + self.sprite_from_age(p); + let half = |p: &mut Particle| { + if p.age > p.lifetime / 2 { + p.rgba[3] = + 1.0 - (p.age as f32 - (p.lifetime / 2) as f32) / p.lifetime as f32; + } + }; + half(p); + if !p.removed { + self.sprite_from_age(p); + half(p); + let b = ParticleLevel::block_at(p.position); + if level.facts.is_air(level.world.block(b[0], b[1], b[2])) { + p.velocity[1] -= f64::from(0.0074f32); + } + } + } + Behaviour::Firefly => { + p.base_tick(level); + let b = ParticleLevel::block_at(p.position); + if !level.facts.is_air(level.world.block(b[0], b[1], b[2])) { + p.removed = true; + } else { + p.rgba[3] = fade_amount(p.lifetime_progress(p.age as f32), 0.3, 0.5); + if p.random.next_float() > 0.95 || p.age == 1 { + let r = &mut p.random; + let mut speed = || f64::from(-0.05f32 + 0.1 * r.next_float()); + p.velocity = [speed(), speed(), speed()]; + } + } + } + Behaviour::Wake => { + p.previous = p.position; + let life = 60 - p.lifetime; + let lifetime = p.lifetime; + p.lifetime -= 1; + if lifetime <= 0 { + p.removed = true; + return; + } + p.velocity[1] -= f64::from(p.gravity); + p.move_by(level, p.velocity); + for c in &mut p.velocity { + *c *= f64::from(0.98f32); + } + let size = life as f32 * 0.001; + p.set_size(size, size); + // SpriteSet.get(life % 4, 4). + if let Some(set) = p.set { + let sprites = &self.set_sprites[set as usize]; + let index = (life % 4) as usize * (sprites.len() - 1) / 4; + p.sprite = Sprite::Index(sprites[index]); + } + } + Behaviour::DustPlume => { + p.gravity *= 0.88; + p.friction *= 0.92; + p.base_tick(level); + self.sprite_from_age(p); + } + Behaviour::FlyStraight { start, colors } => { + p.previous = p.position; + let age = p.age; + p.age += 1; + if age >= p.lifetime { + p.removed = true; + return; + } + let normalized = p.age as f32 / p.lifetime as f32; + let along = 1.0 - normalized; + for i in 0..3 { + p.position[i] = start[i] + p.velocity[i] * f64::from(along); + } + // ARGB.srgbLerp: Mth.lerpInt on each 8-bit channel. + let lerp = |shift: u32| { + let (a, b) = ( + (colors[0] >> shift & 255) as i32, + (colors[1] >> shift & 255) as i32, + ); + (a + (normalized * (b - a) as f32).floor() as i32) as f32 / 255.0 + }; + p.set_color(lerp(16), lerp(8), lerp(0)); + p.rgba[3] = lerp(24); + } Behaviour::DragonBreath { mut hit_ground } => { p.previous = p.position; let age = p.age; @@ -2961,6 +3436,10 @@ impl ParticleEngine { }; let size = p.quad_size(partial); let mut alpha = p.rgba[3]; + // OverlayParticle.extract: the flash fades as it pulses. + if p.ty == ParticleType::Flash { + alpha = 0.6 - (p.age as f32 + partial - 1.0) * 0.25 * 0.5; + } if let Behaviour::FlyTowards { alpha: la, .. } = p.behaviour { alpha = lifetime_alpha(la, p.age, p.lifetime, partial); } diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaParticleProvidersOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaParticleProvidersOracle.java index c1531c1a0..f060351b3 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaParticleProvidersOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaParticleProvidersOracle.java @@ -198,6 +198,7 @@ public final class VanillaParticleProvidersOracle { public static void main(String[] args) throws Exception { SharedConstants.tryDetectVersion(); Bootstrap.bootStrap(); + ParityData.init(); // item components, for the item particle providers' stacks var u = Class.forName("sun.misc.Unsafe"); unsafe = field(u, "theUnsafe").get(null); allocate = u.getMethod("allocateInstance", Class.class); var mc = make(Minecraft.class); field(Minecraft.class, "instance").set(null, mc); var manager = make(ModelManager.class); field(ModelManager.class, "blockStateModelSet").set(manager, new Models()); diff --git a/tools/test_particle_providers_parity.py b/tools/test_particle_providers_parity.py index b413c38fe..afd283359 100644 --- a/tools/test_particle_providers_parity.py +++ b/tools/test_particle_providers_parity.py @@ -31,11 +31,15 @@ falling_lava falling_nectar falling_obsidian_tear falling_spore_blossom falling_ gust gust_emitter_large gust_emitter_small happy_villager heart infested landing_honey landing_lava landing_obsidian_tear large_smoke lava mycelium nautilus note pale_oak_leaves poof portal rain reverse_portal sculk_charge_pop sculk_soul smoke small_flame small_gust sneeze snowflake sonic_boom soul soul_fire_flame splash -spore_blossom_air totem_of_undying underwater vault_connection warped_spore white_ash white_smoke witch""".split() +spore_blossom_air totem_of_undying underwater vault_connection warped_spore white_ash white_smoke witch +sweep_attack glow wax_on wax_off electric_spark scrape squid_ink glow_squid_ink item_slime item_snowball item_cobweb +sulfur_cube_goo firefly trial_spawner_detection trial_spawner_detection_ominous trial_omen raid_omen ominous_spawning +spit fishing dust_plume red_poplar_leaves orange_poplar_leaves yellow_poplar_leaves pause_mob_growth +reset_mob_growth""".split() def options(kind, rng): - if kind in ('block', 'block_crumble', 'dust_pillar', 'falling_dust'): + if kind in ('block', 'block_crumble', 'dust_pillar', 'falling_dust', 'block_marker'): return dict(state=STONE) if kind == 'dust': return dict(color=rng.choice([0xFF0000, 0x3A9E2C, 0xFFFFFF]), scale=rng.choice([1.0, 0.5, 2.0])) @@ -47,6 +51,10 @@ def options(kind, rng): return dict(color=rng.choice([0xFF3366CC, 0x26AA00FF])) if kind == 'tinted_leaves': return dict(color=0xFF48B518) + if kind == 'flash': + return dict(color=rng.choice([0xFF3366CC, 0x00FFAA00])) + if kind == 'item': + return dict(item=rng.choice(['minecraft:apple', 'minecraft:cooked_beef', 'minecraft:egg'])) if kind == 'dragon_breath': return dict(scale=rng.choice([1.0, 0.25])) if kind == 'sculk_charge': @@ -60,7 +68,8 @@ def options(kind, rng): def cases(rng): kinds = SIMPLE + ['block', 'block_crumble', 'dust_pillar', 'falling_dust', 'dust', 'dust_color_transition', 'effect', - 'instant_effect', 'entity_effect', 'tinted_leaves', 'dragon_breath', 'sculk_charge', 'shriek', 'trail'] + 'instant_effect', 'entity_effect', 'tinted_leaves', 'dragon_breath', 'sculk_charge', 'shriek', 'trail', + 'block_marker', 'flash', 'item'] # Dyadic values: serde_json's decimal parsing may round others a unit off. starts = [([0.3125, 66.6875, -0.40625], False), ([0.3125, 64.046875, -0.40625], True), ([-5.75, 64.59375, 3.125], True)] velocities = [[0.0, 0.0, 0.0], [0.078125, 0.125, -0.046875], [0.0, -0.296875, 0.0], [0.5, 0.0, 0.25]] @@ -99,7 +108,8 @@ def decode(token): # (Intel's libm) round a fraction of a percent of arguments a unit apart from # the platform libm horizon_core::jmath uses, so their motion is compared to # 1e-12 relative error; everything else about them, and every other type, exactly. -LIBM = {'cherry_leaves', 'pale_oak_leaves', 'tinted_leaves'} +LIBM = {'cherry_leaves', 'pale_oak_leaves', 'tinted_leaves', 'red_poplar_leaves', 'orange_poplar_leaves', + 'yellow_poplar_leaves'} def sections(path):