Botcraft 1.21.4
Loading...
Searching...
No Matches
Particle.cpp
Go to the documentation of this file.
3
7
8#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
11#else
13#endif
14
15#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
18#endif
19#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
22#endif
23#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
25#endif
26#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
28#endif
29
30#include <array>
31#include <stdexcept>
32
33namespace ProtocolCraft
34{
35 // ParticlesOptions
37#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
39#endif
40#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
42#endif
43#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
45#endif
47#if PROTOCOL_VERSION < 393 /* < 1.13 */
48 DEFINE_NETWORK_TYPE(IconcrackParticleOptions);
49#endif
50#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
52#endif
53#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
55#endif
56#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
58#endif
59#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
61#endif
62
64 {
65
66 };
67
69 {
70
71 }
72
73 std::string_view Particle::GetName() const
74 {
75#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
76 static constexpr std::array<std::string_view, static_cast<size_t>(ParticleType::NUM_PARTICLE_TYPES)> names = {
77 #if PROTOCOL_VERSION < 766 /* < 1.20.5 */
78 "ambient_entity_effect",
79 #endif
80 "angry_villager",
81 #if PROTOCOL_VERSION < 757 /* < 1.18 */
82 "barrier",
83 #endif
84 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */ && PROTOCOL_VERSION < 757 /* < 1.18 */
85 "light",
86 #endif
87 "block",
88 #if PROTOCOL_VERSION > 756 /* > 1.17.1 */
89 "block_marker",
90 #endif
91 "bubble",
92 "cloud",
93 "crit",
94 "damage_indicator",
95 "dragon_breath",
96 "dripping_lava",
97 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
98 "falling_lava",
99 "landing_lava",
100 #endif
101 "dripping_water",
102 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
103 "falling_water",
104 #endif
105 "dust",
106 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
107 "dust_color_transition",
108 #endif
109 "effect",
110 "elder_guardian",
111 "enchanted_hit",
112 "enchant",
113 "end_rod",
114 "entity_effect",
115 "explosion_emitter",
116 "explosion",
117 #if PROTOCOL_VERSION > 764 /* > 1.20.2 */
118 "gust",
119 #if PROTOCOL_VERSION < 766 /* < 1.20.5 */
120 "gust_emitter",
121 #endif
122 #endif
123 #if PROTOCOL_VERSION > 765 /* > 1.20.4 */
124 "small_gust",
125 "gust_emitter_large",
126 "gust_emitter_small",
127 #endif
128 #if PROTOCOL_VERSION > 758 /* > 1.18.2 */
129 "sonic_boom",
130 #endif
131 "falling_dust",
132 "firework",
133 "fishing",
134 "flame",
135 #if PROTOCOL_VERSION > 761 /* > 1.19.3 */ && PROTOCOL_VERSION < 763 /* < 1.20 */
136 "dripping_cherry_leaves",
137 "falling_cherry_leaves",
138 "landing_cherry_leaves",
139 #endif
140 #if PROTOCOL_VERSION > 765 /* > 1.20.4 */
141 "infested",
142 #endif
143 #if PROTOCOL_VERSION > 762 /* > 1.19.4 */
144 "cherry_leaves",
145 #endif
146 #if PROTOCOL_VERSION > 768 /* > 1.21.3 */
147 "pale_oak_leaves",
148 #endif
149 #if PROTOCOL_VERSION > 758 /* > 1.18.2 */
150 "sculk_soul",
151 "sculk_charge",
152 "sculk_charge_pop",
153 #endif
154 #if PROTOCOL_VERSION > 734 /* > 1.15.2 */
155 "soul_fire_flame",
156 "soul",
157 #endif
158 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
159 "flash",
160 #endif
161 "happy_villager",
162 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
163 "composter",
164 #endif
165 "heart",
166 "instant_effect",
167 "item",
168 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
169 "vibration",
170 #endif
171#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
172 "trail",
173#endif
174 "item_slime",
175 #if PROTOCOL_VERSION > 765 /* > 1.20.4 */
176 "item_cobweb",
177 #endif
178 "item_snowball",
179 "large_smoke",
180 "lava",
181 "mycelium",
182 "note",
183 "poof",
184 "portal",
185 "rain",
186 "smoke",
187 #if PROTOCOL_VERSION > 764 /* > 1.20.2 */
188 "white_smoke",
189 #endif
190 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
191 "sneeze",
192 #endif
193 "spit",
194 "squid_ink",
195 "sweep_attack",
196 "totem_of_undying",
197 "underwater",
198 "splash",
199 "witch",
200 "bubble_pop",
201 "current_down",
202 "bubble_column_up",
203 "nautilus",
204 "dolphin",
205 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
206 "campfire_cosy_smoke",
207 "campfire_signal_smoke",
208 #endif
209 #if PROTOCOL_VERSION > 572 /* > 1.14.4 */
210 "dripping_honey",
211 "falling_honey",
212 "landing_honey",
213 "falling_nectar",
214 #endif
215 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
216 "falling_spore_blossom",
217 #endif
218 #if PROTOCOL_VERSION > 734 /* > 1.15.2 */
219 "ash",
220 "crimson_spore",
221 "warped_spore",
222 #endif
223 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
224 "spore_blossom_air",
225 #endif
226 #if PROTOCOL_VERSION > 734 /* > 1.15.2 */
227 "dripping_obsidian_tear",
228 "falling_obsidian_tear",
229 "landing_obsidian_tear",
230 "reverse_portal",
231 "white_ash",
232 #endif
233 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
234 "small_flame",
235 "snowflake",
236 "dripping_dripstone_lava",
237 "falling_dripstone_lava",
238 "dripping_dripstone_water",
239 "falling_dripstone_water",
240 "glow_squid_ink",
241 "glow",
242 "wax_on",
243 "wax_off",
244 "electric_spark",
245 "scrape",
246 #endif
247 #if PROTOCOL_VERSION > 758 /* > 1.18.2 */
248 "shriek",
249 #endif
250 #if PROTOCOL_VERSION > 762 /* > 1.19.4 */
251 "egg_crack",
252 #endif
253 #if PROTOCOL_VERSION > 764 /* > 1.20.2 */
254 "dust_plume",
255 #if PROTOCOL_VERSION < 766 /* < 1.20.5 */
256 "gust_dust",
257 #endif
258 "trial_spawner_detection",
259 #endif
260 #if PROTOCOL_VERSION > 765 /* > 1.20.4 */
261 "trial_spawner_detection_ominous",
262 "vault_connection",
263 "dust_pillar",
264 "ominous_spawning",
265 "raid_omen",
266 "trial_omen",
267 #endif
268#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
269 "block_crumble",
270#endif
271 };
272#else
273 static constexpr std::array<std::string_view, static_cast<size_t>(ParticleType::NUM_PARTICLE_TYPES)> names = {
274 "explode",
275 "largeexplode",
276 "hugeexplosion",
277 "fireworksSpark",
278 "bubble",
279 "splash",
280 "wake",
281 "suspended",
282 "depthsuspend",
283 "crit",
284 "magicCrit",
285 "smoke",
286 "largesmoke",
287 "spell",
288 "instantSpell",
289 "mobSpell",
290 "mobSpellAmbient",
291 "witchMagic",
292 "dripWater",
293 "dripLava",
294 "angryVillager",
295 "happyVillager",
296 "townaura",
297 "note",
298 "portal",
299 "enchantmenttable",
300 "flame",
301 "lava",
302 "footstep",
303 "cloud",
304 "reddust",
305 "snowballpoof",
306 "snowshovel",
307 "slime",
308 "heart",
309 "barrier",
310 "iconcrack",
311 "blockcrack",
312 "blockdust",
313 "droplet",
314 "take",
315 "mobappearance",
316 "dragonbreath",
317 "endRod",
318 "damageIndicator",
319 "sweepAttack",
320 "fallingdust",
321 "totem",
322 "spit",
323 };
324#endif
325 if (ParticleType <= ParticleType::None || ParticleType >= ParticleType::NUM_PARTICLE_TYPES)
326 {
327 return "";
328 }
329 return names[static_cast<size_t>(ParticleType)];
330 }
331
333 {
334 if (particle_type_ <= ParticleType::None || particle_type_ >= ParticleType::NUM_PARTICLE_TYPES)
335 {
336 throw std::runtime_error("Unable to create particle with id: " + std::to_string(static_cast<int>(particle_type_)) + ".");
337 }
338 ParticleType = particle_type_;
339
340 switch (ParticleType)
341 {
342#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
345#if PROTOCOL_VERSION > 756 /* > 1.17.1 */
347#endif
348#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
350#endif
351#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
353#endif
354 Options = std::make_shared<BlockParticleOptions>();
355 break;
357 Options = std::make_shared<DustParticleOptions>();
358 break;
360 Options = std::make_shared<ItemParticleOptions>();
361 break;
362#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
364 Options = std::make_shared<DustColorTransitionOptions>();
365 break;
367 Options = std::make_shared<VibrationParticleOptions>();
368 break;
369#endif
370#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
372 Options = std::make_shared<SculkChargeParticleOptions>();
373 break;
375 Options = std::make_shared<ShriekParticleOptions>();
376 break;
377#endif
378#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
380 Options = std::make_shared<ColorParticleOptions>();
381 break;
382#endif
383#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
385 Options = std::make_shared<TrailParticleOptions>();
386 break;
387#endif
388#else //1.12.2
389 case ParticleType::Blockcrack:
390 case ParticleType::Blockdust:
392 Options = std::make_shared<BlockParticleOptions>();
393 break;
394 case ParticleType::Iconcrack:
395 Options = std::make_shared<IconcrackParticleOptions>();
396 break;
397#endif
398 default:
399 Options = std::make_shared<EmptyParticleOptions>();
400 break;
401 }
402 return *this;
403 }
404
405#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
406 void Particle::ReadOptions(ReadIterator& iter, size_t& length)
407 {
408 if (Options != nullptr)
409 {
410 Options->Read(iter, length);
411 }
412 }
413
414 void Particle::WriteOptions(WriteContainer& container) const
415 {
416 if (Options != nullptr)
417 {
418 Options->Write(container);
419 }
420 }
421#endif
422
423 void Particle::ReadImpl(ReadIterator& iter, size_t& length)
424 {
425 ParticleType = ReadData<ProtocolCraft::ParticleType, VarInt>(iter, length);
427 if (Options != nullptr)
428 {
429 Options->Read(iter, length);
430 }
431 }
432
433 void Particle::WriteImpl(WriteContainer& container) const
434 {
435 WriteData<ProtocolCraft::ParticleType, VarInt>(ParticleType, container);
436 if (Options != nullptr)
437 {
438 Options->Write(container);
439 }
440 }
441
442 Json::Value Particle::SerializeImpl() const
443 {
444 Json::Value output;
445
446 output[std::string(field_name<ParticleType_index>)] = GetName();
447 output[std::string(field_name<Options_index>)] = Options == nullptr ? Json::Object() : Options->Serialize();
448
449 return output;
450 }
451}
#define DEFINE_NETWORK_TYPE(ClassName)
virtual Json::Value SerializeImpl() const =0
virtual void WriteImpl(WriteContainer &container) const =0
virtual Json::Value Serialize() const
virtual void ReadImpl(ReadIterator &iter, size_t &length)=0
Particle & SetParticleType(const ProtocolCraft::ParticleType particle_type_)
Definition Particle.cpp:332
std::string_view GetName() const
Definition Particle.cpp:73
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator