Skip to main content

azalea_registry/registry_holder/
particle.rs

1use azalea_block::BlockState;
2use azalea_buf::AzBuf;
3use azalea_codec::Codec;
4use azalea_core::{
5    color::RgbColor,
6    entity_id::MinecraftEntityId,
7    position::{BlockPos, Vec3},
8};
9use azalea_registry_builtin::builtin::BlockKind;
10
11use crate::{builtin::ParticleKind, item::ItemStack};
12
13// the order of this enum must be kept in sync with ParticleKind, otherwise
14// we get errors parsing particles.
15
16/// A [`ParticleKind`] with data potentially attached to it.
17#[derive(AzBuf, Clone, Debug, PartialEq, Codec)]
18#[codec(tag = "type", tag_as = ParticleKind)]
19#[codec(default_snake_case_key)]
20pub enum Particle {
21    AngryVillager,
22    Block(BlockParticle),
23    BlockMarker(BlockParticle),
24    Bubble,
25    SulfurBubbles,
26    NoxiousGas,
27    NoxiousGasCloud,
28    Geyser(GeyserParticle),
29    GeyserBase(GeyserBaseParticle),
30    GeyserPoof(GeyserBaseParticle),
31    GeyserPlume(GeyserParticle),
32    Cloud,
33    CopperFireFlame,
34    Crit,
35    DamageIndicator,
36    DragonBreath(PowerParticle),
37    DrippingLava,
38    FallingLava,
39    LandingLava,
40    DrippingWater,
41    FallingWater,
42    Dust(DustParticle),
43    DustColorTransition(DustColorTransitionParticle),
44    Effect(SpellParticle),
45    ElderGuardian,
46    EnchantedHit,
47    Enchant,
48    EndRod,
49    EntityEffect(ColorParticle),
50    ExplosionEmitter,
51    Explosion,
52    Gust,
53    SmallGust,
54    GustEmitterLarge,
55    GustEmitterSmall,
56    SonicBoom,
57    FallingDust(BlockParticle),
58    Firework,
59    Fishing,
60    Flame,
61    Infested,
62    CherryLeaves,
63    PaleOakLeaves,
64    RedPoplarLeaves,
65    OrangePoplarLeaves,
66    YellowPoplarLeaves,
67    TintedLeaves(ColorParticle),
68    SculkSoul,
69    SculkCharge(SculkChargeParticle),
70    SculkChargePop,
71    SoulFireFlame,
72    Soul,
73    Flash(ColorParticle),
74    HappyVillager,
75    Composter,
76    Heart,
77    InstantEffect(SpellParticle),
78    Item(ItemParticle),
79    Vibration(Box<VibrationParticle>),
80    Trail(Box<TrailParticle>),
81    PauseMobGrowth,
82    ResetMobGrowth,
83    ItemSlime,
84    ItemCobweb,
85    ItemSnowball,
86    LargeSmoke,
87    Lava,
88    Mycelium,
89    Note,
90    Poof,
91    Portal,
92    Rain,
93    Smoke,
94    WhiteSmoke,
95    Sneeze,
96    Spit,
97    SquidInk,
98    SweepAttack,
99    TotemOfUndying,
100    Underwater,
101    Splash,
102    Witch,
103    BubblePop,
104    CurrentDown,
105    BubbleColumnUp,
106    Nautilus,
107    Dolphin,
108    CampfireCosySmoke,
109    CampfireSignalSmoke,
110    DrippingHoney,
111    FallingHoney,
112    LandingHoney,
113    FallingNectar,
114    FallingSporeBlossom,
115    Ash,
116    CrimsonSpore,
117    WarpedSpore,
118    SporeBlossomAir,
119    DrippingObsidianTear,
120    FallingObsidianTear,
121    LandingObsidianTear,
122    ReversePortal,
123    WhiteAsh,
124    SmallFlame,
125    Snowflake,
126    DrippingDripstoneLava,
127    FallingDripstoneLava,
128    DrippingDripstoneWater,
129    FallingDripstoneWater,
130    GlowSquidInk,
131    Glow,
132    WaxOn,
133    WaxOff,
134    ElectricSpark,
135    Scrape,
136    Shriek(ShriekParticle),
137    EggCrack,
138    DustPlume,
139    TrialSpawnerDetection,
140    TrialSpawnerDetectionOminous,
141    VaultConnection,
142    DustPillar(BlockParticle),
143    OminousSpawning,
144    RaidOmen,
145    TrialOmen,
146    BlockCrumble(BlockParticle),
147    Firefly,
148    SulfurCubeGoo,
149}
150const _: () = assert!(size_of::<Particle>() == 16);
151
152impl Default for Particle {
153    fn default() -> Self {
154        Self::EntityEffect(ColorParticle::default())
155    }
156}
157
158#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
159pub struct BlockParticle {
160    #[codec(with = BlockKind)]
161    pub block_state: BlockState,
162}
163#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
164pub struct DustParticle {
165    pub color: RgbColor,
166    /// The scale, will be clamped between 0.01 and 4.
167    pub scale: f32,
168}
169
170#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
171pub struct DustColorTransitionParticle {
172    pub from: RgbColor,
173    pub to: RgbColor,
174    /// The scale, will be clamped between 0.01 and 4.
175    pub scale: f32,
176}
177
178#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
179pub struct ColorParticle {
180    pub color: RgbColor,
181}
182
183#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
184pub struct ItemParticle {
185    pub item: ItemStack,
186}
187
188#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
189pub struct VibrationParticle {
190    pub position: PositionSource,
191    #[var]
192    pub ticks: u32,
193}
194
195#[derive(AzBuf, Clone, Debug, PartialEq, Codec)]
196pub enum PositionSource {
197    Block(BlockPos),
198    #[codec(skip)]
199    Entity {
200        #[var]
201        id: MinecraftEntityId,
202        y_offset: f32,
203    },
204}
205impl Default for PositionSource {
206    fn default() -> Self {
207        // bad default but hopefully it never gets used anyways
208        Self::Block(BlockPos::default())
209    }
210}
211
212#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
213pub struct SculkChargeParticle {
214    pub roll: f32,
215}
216
217#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
218pub struct ShriekParticle {
219    /// The time in ticks before the particle is displayed.
220    #[var]
221    pub delay: i32,
222}
223
224#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
225pub struct GeyserParticle {
226    pub water_blocks: i32,
227}
228
229#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
230pub struct GeyserBaseParticle {
231    pub water_blocks: i32,
232    pub burst_impulse_base: f32,
233}
234
235#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
236pub struct TrailParticle {
237    pub target: Vec3,
238    pub color: RgbColor,
239    #[var]
240    pub duration: u32,
241}
242
243#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
244pub struct PowerParticle {
245    #[codec(optional, default = 1.0)]
246    pub power: f32,
247}
248
249#[derive(AzBuf, Clone, Debug, Default, PartialEq, Codec)]
250pub struct SpellParticle {
251    #[codec(optional, default = RgbColor::WHITE)]
252    pub color: RgbColor,
253    #[codec(optional, default = 1.0)]
254    pub power: f32,
255}