Skip to main content

azalea_entity/
particle.rs

1use azalea_block::BlockState;
2use azalea_buf::AzBuf;
3use azalea_core::{color::RgbColor, entity_id::MinecraftEntityId, position::BlockPos};
4use azalea_inventory::ItemStack;
5use azalea_registry::builtin::ParticleKind;
6
7// the order of this enum must be kept in sync with ParticleKind, otherwise
8// we get errors parsing particles.
9
10/// A [`ParticleKind`] with data potentially attached to it.
11#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))]
12#[derive(AzBuf, Clone, Debug, PartialEq)]
13pub enum Particle {
14    AngryVillager,
15    Block(BlockParticle),
16    BlockMarker(BlockParticle),
17    Bubble,
18    SulfurBubbles,
19    NoxiousGas,
20    NoxiousGasCloud,
21    Geyser(GeyserParticle),
22    GeyserBase(GeyserBaseParticle),
23    GeyserPoof(GeyserBaseParticle),
24    GeyserPlume(GeyserParticle),
25    Cloud,
26    CopperFireFlame,
27    Crit,
28    DamageIndicator,
29    DragonBreath,
30    DrippingLava,
31    FallingLava,
32    LandingLava,
33    DrippingWater,
34    FallingWater,
35    Dust(DustParticle),
36    DustColorTransition(DustColorTransitionParticle),
37    Effect,
38    ElderGuardian,
39    EnchantedHit,
40    Enchant,
41    EndRod,
42    EntityEffect(ColorParticle),
43    ExplosionEmitter,
44    Explosion,
45    Gust,
46    SmallGust,
47    GustEmitterLarge,
48    GustEmitterSmall,
49    SonicBoom,
50    FallingDust(BlockParticle),
51    Firework,
52    Fishing,
53    Flame,
54    Infested,
55    CherryLeaves,
56    PaleOakLeaves,
57    TintedLeaves,
58    SculkSoul,
59    SculkCharge(SculkChargeParticle),
60    SculkChargePop,
61    SoulFireFlame,
62    Soul,
63    Flash,
64    HappyVillager,
65    Composter,
66    Heart,
67    InstantEffect,
68    Item(ItemParticle),
69    Vibration(Box<VibrationParticle>),
70    Trail,
71    PauseMobGrowth,
72    ResetMobGrowth,
73    ItemSlime,
74    ItemCobweb,
75    ItemSnowball,
76    LargeSmoke,
77    Lava,
78    Mycelium,
79    Note,
80    Poof,
81    Portal,
82    Rain,
83    Smoke,
84    WhiteSmoke,
85    Sneeze,
86    Spit,
87    SquidInk,
88    SweepAttack,
89    TotemOfUndying,
90    Underwater,
91    Splash,
92    Witch,
93    BubblePop,
94    CurrentDown,
95    BubbleColumnUp,
96    Nautilus,
97    Dolphin,
98    CampfireCosySmoke,
99    CampfireSignalSmoke,
100    DrippingHoney,
101    FallingHoney,
102    LandingHoney,
103    FallingNectar,
104    FallingSporeBlossom,
105    Ash,
106    CrimsonSpore,
107    WarpedSpore,
108    SporeBlossomAir,
109    DrippingObsidianTear,
110    FallingObsidianTear,
111    LandingObsidianTear,
112    ReversePortal,
113    WhiteAsh,
114    SmallFlame,
115    Snowflake,
116    DrippingDripstoneLava,
117    FallingDripstoneLava,
118    DrippingDripstoneWater,
119    FallingDripstoneWater,
120    GlowSquidInk,
121    Glow,
122    WaxOn,
123    WaxOff,
124    ElectricSpark,
125    Scrape,
126    Shriek(ShriekParticle),
127    EggCrack,
128    DustPlume,
129    TrialSpawnerDetection,
130    TrialSpawnerDetectionOminous,
131    VaultConnection,
132    DustPillar,
133    OminousSpawning,
134    RaidOmen,
135    TrialOmen,
136    BlockCrumble,
137    Firefly,
138    SulfurCubeGoo,
139}
140
141impl From<ParticleKind> for Particle {
142    /// Convert a particle kind into particle data.
143    ///
144    /// If the particle has data attached (like block particles), then it's set
145    /// to the default.
146    fn from(kind: ParticleKind) -> Self {
147        // this is mostly just here so it fails to compile when a new particle
148        // is added to ParticleKind, since `Particle` has to be updated manually
149        match kind {
150            ParticleKind::AngryVillager => Self::AngryVillager,
151            ParticleKind::Block => Self::Block(BlockParticle::default()),
152            ParticleKind::BlockMarker => Self::BlockMarker(BlockParticle::default()),
153            ParticleKind::Bubble => Self::Bubble,
154            ParticleKind::Cloud => Self::Cloud,
155            ParticleKind::Crit => Self::Crit,
156            ParticleKind::DamageIndicator => Self::DamageIndicator,
157            ParticleKind::DragonBreath => Self::DragonBreath,
158            ParticleKind::DrippingLava => Self::DrippingLava,
159            ParticleKind::FallingLava => Self::FallingLava,
160            ParticleKind::LandingLava => Self::LandingLava,
161            ParticleKind::DrippingWater => Self::DrippingWater,
162            ParticleKind::FallingWater => Self::FallingWater,
163            ParticleKind::Dust => Self::Dust(DustParticle::default()),
164            ParticleKind::DustColorTransition => {
165                Self::DustColorTransition(DustColorTransitionParticle::default())
166            }
167            ParticleKind::Effect => Self::Effect,
168            ParticleKind::ElderGuardian => Self::ElderGuardian,
169            ParticleKind::EnchantedHit => Self::EnchantedHit,
170            ParticleKind::Enchant => Self::Enchant,
171            ParticleKind::EndRod => Self::EndRod,
172            ParticleKind::EntityEffect => Self::EntityEffect(ColorParticle::default()),
173            ParticleKind::ExplosionEmitter => Self::ExplosionEmitter,
174            ParticleKind::Explosion => Self::Explosion,
175            ParticleKind::Gust => Self::Gust,
176            ParticleKind::SonicBoom => Self::SonicBoom,
177            ParticleKind::FallingDust => Self::FallingDust(BlockParticle::default()),
178            ParticleKind::Firework => Self::Firework,
179            ParticleKind::Fishing => Self::Fishing,
180            ParticleKind::Flame => Self::Flame,
181            ParticleKind::CherryLeaves => Self::CherryLeaves,
182            ParticleKind::PaleOakLeaves => Self::PaleOakLeaves,
183            ParticleKind::TintedLeaves => Self::TintedLeaves,
184            ParticleKind::SculkSoul => Self::SculkSoul,
185            ParticleKind::SculkCharge => Self::SculkCharge(SculkChargeParticle::default()),
186            ParticleKind::SculkChargePop => Self::SculkChargePop,
187            ParticleKind::SoulFireFlame => Self::SoulFireFlame,
188            ParticleKind::Soul => Self::Soul,
189            ParticleKind::Flash => Self::Flash,
190            ParticleKind::HappyVillager => Self::HappyVillager,
191            ParticleKind::Composter => Self::Composter,
192            ParticleKind::Heart => Self::Heart,
193            ParticleKind::InstantEffect => Self::InstantEffect,
194            ParticleKind::Item => Self::Item(ItemParticle::default()),
195            ParticleKind::Vibration => Self::Vibration(Default::default()),
196            ParticleKind::ItemSlime => Self::ItemSlime,
197            ParticleKind::ItemSnowball => Self::ItemSnowball,
198            ParticleKind::LargeSmoke => Self::LargeSmoke,
199            ParticleKind::Lava => Self::Lava,
200            ParticleKind::Mycelium => Self::Mycelium,
201            ParticleKind::Note => Self::Note,
202            ParticleKind::Poof => Self::Poof,
203            ParticleKind::Portal => Self::Portal,
204            ParticleKind::Rain => Self::Rain,
205            ParticleKind::Smoke => Self::Smoke,
206            ParticleKind::WhiteSmoke => Self::WhiteSmoke,
207            ParticleKind::Sneeze => Self::Sneeze,
208            ParticleKind::Spit => Self::Spit,
209            ParticleKind::SquidInk => Self::SquidInk,
210            ParticleKind::SweepAttack => Self::SweepAttack,
211            ParticleKind::TotemOfUndying => Self::TotemOfUndying,
212            ParticleKind::Underwater => Self::Underwater,
213            ParticleKind::Splash => Self::Splash,
214            ParticleKind::Witch => Self::Witch,
215            ParticleKind::BubblePop => Self::BubblePop,
216            ParticleKind::CurrentDown => Self::CurrentDown,
217            ParticleKind::BubbleColumnUp => Self::BubbleColumnUp,
218            ParticleKind::Nautilus => Self::Nautilus,
219            ParticleKind::Dolphin => Self::Dolphin,
220            ParticleKind::CampfireCosySmoke => Self::CampfireCosySmoke,
221            ParticleKind::CampfireSignalSmoke => Self::CampfireSignalSmoke,
222            ParticleKind::DrippingHoney => Self::DrippingHoney,
223            ParticleKind::FallingHoney => Self::FallingHoney,
224            ParticleKind::LandingHoney => Self::LandingHoney,
225            ParticleKind::FallingNectar => Self::FallingNectar,
226            ParticleKind::FallingSporeBlossom => Self::FallingSporeBlossom,
227            ParticleKind::Ash => Self::Ash,
228            ParticleKind::CrimsonSpore => Self::CrimsonSpore,
229            ParticleKind::WarpedSpore => Self::WarpedSpore,
230            ParticleKind::SporeBlossomAir => Self::SporeBlossomAir,
231            ParticleKind::DrippingObsidianTear => Self::DrippingObsidianTear,
232            ParticleKind::FallingObsidianTear => Self::FallingObsidianTear,
233            ParticleKind::LandingObsidianTear => Self::LandingObsidianTear,
234            ParticleKind::ReversePortal => Self::ReversePortal,
235            ParticleKind::WhiteAsh => Self::WhiteAsh,
236            ParticleKind::SmallFlame => Self::SmallFlame,
237            ParticleKind::Snowflake => Self::Snowflake,
238            ParticleKind::DrippingDripstoneLava => Self::DrippingDripstoneLava,
239            ParticleKind::FallingDripstoneLava => Self::FallingDripstoneLava,
240            ParticleKind::DrippingDripstoneWater => Self::DrippingDripstoneWater,
241            ParticleKind::FallingDripstoneWater => Self::FallingDripstoneWater,
242            ParticleKind::GlowSquidInk => Self::GlowSquidInk,
243            ParticleKind::Glow => Self::Glow,
244            ParticleKind::WaxOn => Self::WaxOn,
245            ParticleKind::WaxOff => Self::WaxOff,
246            ParticleKind::ElectricSpark => Self::ElectricSpark,
247            ParticleKind::Scrape => Self::Scrape,
248            ParticleKind::Shriek => Self::Shriek(ShriekParticle::default()),
249            ParticleKind::EggCrack => Self::EggCrack,
250            ParticleKind::DustPlume => Self::DustPlume,
251            ParticleKind::SmallGust => Self::SmallGust,
252            ParticleKind::GustEmitterLarge => Self::GustEmitterLarge,
253            ParticleKind::GustEmitterSmall => Self::GustEmitterSmall,
254            ParticleKind::Infested => Self::Infested,
255            ParticleKind::ItemCobweb => Self::ItemCobweb,
256            ParticleKind::TrialSpawnerDetection => Self::TrialSpawnerDetection,
257            ParticleKind::TrialSpawnerDetectionOminous => Self::TrialSpawnerDetectionOminous,
258            ParticleKind::VaultConnection => Self::VaultConnection,
259            ParticleKind::DustPillar => Self::DustPillar,
260            ParticleKind::OminousSpawning => Self::OminousSpawning,
261            ParticleKind::RaidOmen => Self::RaidOmen,
262            ParticleKind::TrialOmen => Self::TrialOmen,
263            ParticleKind::Trail => Self::Trail,
264            ParticleKind::BlockCrumble => Self::BlockCrumble,
265            ParticleKind::Firefly => Self::Firefly,
266            ParticleKind::CopperFireFlame => Self::CopperFireFlame,
267            ParticleKind::PauseMobGrowth => Self::PauseMobGrowth,
268            ParticleKind::ResetMobGrowth => Self::ResetMobGrowth,
269            ParticleKind::SulfurBubbles => Self::SulfurBubbles,
270            ParticleKind::NoxiousGas => Self::NoxiousGas,
271            ParticleKind::NoxiousGasCloud => Self::NoxiousGasCloud,
272            ParticleKind::Geyser => Self::Geyser(GeyserParticle::default()),
273            ParticleKind::GeyserBase => Self::GeyserBase(GeyserBaseParticle::default()),
274            ParticleKind::GeyserPoof => Self::GeyserPoof(GeyserBaseParticle::default()),
275            ParticleKind::GeyserPlume => Self::GeyserPlume(GeyserParticle::default()),
276            ParticleKind::SulfurCubeGoo => Self::SulfurCubeGoo,
277        }
278    }
279}
280
281impl Default for Particle {
282    fn default() -> Self {
283        Self::EntityEffect(ColorParticle::default())
284    }
285}
286
287#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
288pub struct BlockParticle {
289    pub block_state: BlockState,
290}
291#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
292pub struct DustParticle {
293    pub color: RgbColor,
294    /// The scale, will be clamped between 0.01 and 4.
295    pub scale: f32,
296}
297
298#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
299pub struct DustColorTransitionParticle {
300    pub from: RgbColor,
301    pub to: RgbColor,
302    /// The scale, will be clamped between 0.01 and 4.
303    pub scale: f32,
304}
305
306#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
307pub struct ColorParticle {
308    pub color: RgbColor,
309}
310
311#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
312pub struct ItemParticle {
313    pub item: ItemStack,
314}
315
316#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
317pub struct VibrationParticle {
318    pub position: PositionSource,
319    #[var]
320    pub ticks: u32,
321}
322
323#[derive(AzBuf, Clone, Debug, PartialEq)]
324pub enum PositionSource {
325    Block(BlockPos),
326    Entity {
327        #[var]
328        id: MinecraftEntityId,
329        y_offset: f32,
330    },
331}
332impl Default for PositionSource {
333    fn default() -> Self {
334        // bad default but hopefully it never gets used anyways
335        Self::Block(BlockPos::default())
336    }
337}
338
339#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
340pub struct SculkChargeParticle {
341    pub roll: f32,
342}
343
344#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
345pub struct ShriekParticle {
346    /// The time in ticks before the particle is displayed.
347    #[var]
348    pub delay: i32,
349}
350
351#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
352pub struct GeyserParticle {
353    pub water_blocks: i32,
354}
355
356#[derive(AzBuf, Clone, Debug, Default, PartialEq)]
357pub struct GeyserBaseParticle {
358    pub water_blocks: i32,
359    pub burst_impulse_base: f32,
360}