1use std::collections::HashMap;
2
3use azalea_codec::{Codec, types::CompactListCodec};
4use azalea_core::{
5 identifier::Identifier,
6 position::{Vec3, Vec3i},
7 sound::CustomSound,
8};
9use azalea_registry_builtin::builtin::EnchantmentEntityEffectKind;
10
11use crate::{
12 Holder, HolderSet,
13 builtin::{BlockKind, EntityKind, GameEvent, MobEffect, SoundEvent},
14 data::DamageKind,
15 registry_holder::{
16 block_predicate::BlockPredicate, block_state_provider::BlockStateProvider,
17 float_provider::FloatProvider, particle::Particle, value::LevelBasedValue,
18 },
19};
20
21#[derive(Clone, Debug, PartialEq, Codec)]
22#[codec(tag = "type", tag_as=EnchantmentEntityEffectKind)]
23#[codec(default_snake_case_key)]
24pub enum EntityEffect {
25 AllOf(AllOf),
26 ApplyMobEffect(ApplyMobEffect),
27 ChangeItemDamage(ChangeItemDamage),
28 DamageEntity(DamageEntity),
29 Explode(Explode),
30 Ignite(Ignite),
31 ApplyImpulse(ApplyEntityImpulse),
32 ApplyExhaustion(ApplyExhaustion),
33 PlaySound(PlaySound),
34 ReplaceBlock(ReplaceBlock),
35 ReplaceDisk(ReplaceDisk),
36 RunFunction(RunFunction),
37 SetBlockProperties(SetBlockProperties),
38 SpawnParticles(SpawnParticles),
39 SummonEntity(SummonEntity),
40}
41
42#[derive(Clone, Debug, PartialEq, Codec)]
43pub struct AllOf {
44 pub effects: Vec<EntityEffect>,
45}
46
47#[derive(Clone, Debug, PartialEq, Codec)]
48pub struct ApplyMobEffect {
49 pub to_apply: HolderSet<MobEffect>,
51 pub min_duration: LevelBasedValue,
52 pub max_duration: LevelBasedValue,
53 pub min_amplifier: LevelBasedValue,
54 pub max_amplifier: LevelBasedValue,
55}
56
57#[derive(Clone, Debug, PartialEq, Codec)]
58pub struct ChangeItemDamage {
59 pub amount: LevelBasedValue,
60}
61
62#[derive(Clone, Debug, PartialEq, Codec)]
63pub struct DamageEntity {
64 pub min_damage: LevelBasedValue,
65 pub max_damage: LevelBasedValue,
66 #[codec(rename = "damage_type")]
67 pub damage_kind: DamageKind,
68}
69
70#[derive(Clone, Debug, PartialEq, Codec)]
71pub struct Explode {
72 #[codec(optional)]
73 pub attribute_to_user: bool,
74 #[codec(rename = "damage_type")]
75 #[codec(optional)]
76 pub damage_kind: Option<DamageKind>,
77 #[codec(optional)]
78 pub knockback_multiplier: Option<LevelBasedValue>,
79 #[codec(optional)]
80 pub immune_blocks: HolderSet<BlockKind>,
81 #[codec(optional)]
82 pub offset: Vec3,
83 pub radius: LevelBasedValue,
84 #[codec(optional)]
85 pub create_fire: bool,
86 pub block_interaction: ExplosionInteraction,
87 #[codec(optional)]
88 pub small_particle: Option<Particle>,
89 #[codec(optional)]
90 pub large_particle: Option<Particle>,
91 #[codec(optional)]
92 pub block_particles: Vec<ExplosionParticleInfo>,
93 #[codec(optional)]
94 pub sound: Option<SoundEvent>,
95}
96
97#[derive(Clone, Debug, PartialEq, Codec)]
98#[codec(default_snake_case_key)]
99pub enum ExplosionInteraction {
100 None,
101 Block,
102 Mob,
103 Tnt,
104 Trigger,
105}
106
107#[derive(Clone, Debug, PartialEq, Codec)]
108pub struct ExplosionParticleInfo {
109 pub particle: Particle,
110 #[codec(optional, default = 1.0)]
111 pub scaling: f32,
112 #[codec(optional, default = 1.0)]
113 pub speed: f32,
114}
115
116#[derive(Clone, Debug, PartialEq, Codec)]
117pub struct Ignite {
118 pub duration: LevelBasedValue,
119}
120
121#[derive(Clone, Debug, PartialEq, Codec)]
122pub struct ApplyEntityImpulse {
123 pub direction: Vec3,
124 pub coordinate_scale: Vec3,
125 pub magnitude: LevelBasedValue,
126}
127
128#[derive(Clone, Debug, PartialEq, Codec)]
129pub struct ApplyExhaustion {
130 pub amount: LevelBasedValue,
131}
132
133#[derive(Clone, Debug, PartialEq, Codec)]
134pub struct PlaySound {
135 #[codec(with = CompactListCodec::<_>)]
136 pub sound: Vec<Holder<SoundEvent, CustomSound>>,
137 pub volume: FloatProvider,
138 pub pitch: FloatProvider,
139}
140
141#[derive(Clone, Debug, PartialEq, Codec)]
142pub struct ReplaceBlock {
143 #[codec(optional)]
144 pub offset: Vec3i,
145 #[codec(optional)]
146 pub predicate: BlockPredicate,
147 pub block_state: BlockStateProvider,
148 #[codec(optional)]
149 pub trigger_game_event: Option<GameEvent>,
150}
151
152#[derive(Clone, Debug, PartialEq, Codec)]
153pub struct ReplaceDisk {
154 pub radius: LevelBasedValue,
155 pub height: LevelBasedValue,
156 #[codec(optional)]
157 pub offset: Vec3i,
158 #[codec(optional)]
159 pub predicate: BlockPredicate,
160 pub block_state: BlockStateProvider,
161 #[codec(optional)]
162 pub trigger_game_event: Option<GameEvent>,
163}
164
165#[derive(Clone, Debug, PartialEq, Codec)]
166pub struct RunFunction {
167 pub function: Identifier,
168}
169
170#[derive(Clone, Debug, PartialEq, Codec)]
171pub struct SetBlockProperties {
172 pub properties: HashMap<String, String>,
173 #[codec(optional)]
174 pub offset: Option<Vec3i>,
175 #[codec(optional)]
176 pub trigger_game_event: Option<GameEvent>,
177}
178
179#[derive(Clone, Debug, PartialEq, Codec)]
180pub struct SpawnParticles {
181 pub particle: Particle,
182 pub horizontal_position: SpawnParticlesPosition,
183 pub vertical_position: SpawnParticlesPosition,
184 pub horizontal_velocity: SpawnParticlesVelocity,
185 pub vertical_velocity: SpawnParticlesVelocity,
186 #[codec(optional)]
187 pub speed: Option<FloatProvider>,
188}
189
190#[derive(Clone, Debug, PartialEq, Codec)]
191pub struct SpawnParticlesPosition {
192 #[codec(rename = "type")]
193 pub kind: Identifier,
194 #[codec(optional)]
195 pub offset: Option<f32>,
196 #[codec(optional)]
197 pub scale: Option<f32>,
198}
199
200#[derive(Clone, Debug, PartialEq, Codec)]
201pub struct SpawnParticlesVelocity {
202 #[codec(optional)]
203 pub movement_scale: f32,
204 #[codec(optional)]
205 pub base: FloatProvider,
206}
207
208#[derive(Clone, Debug, PartialEq, Codec)]
209pub struct SummonEntity {
210 pub entity: HolderSet<EntityKind>,
211 #[codec(optional)]
212 pub join_team: Option<bool>,
213}