azalea_entity/
particle.rs

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