Botcraft 26.3
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#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
32#endif
33#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
36#endif
37
38#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
39#include "protocolCraft/Types/Particles/ExplosionParticleInfo.hpp" // Not a particle info type, used in ClientboundExplodePacket
40#endif
41
42#include <array>
43#include <stdexcept>
44
45namespace ProtocolCraft
46{
47 // ParticlesOption subtypes
49#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
51#endif
52#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
54#endif
55#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
57#endif
59#if PROTOCOL_VERSION < 393 /* < 1.13 */
60 DEFINE_NETWORK_TYPE(IconcrackParticleOption);
61#endif
62#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
64#endif
65#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
67#endif
68#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
70#endif
71#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
73#endif
74#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
77#endif
78#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
81#endif
82
83#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
84 DEFINE_NETWORK_TYPE(ExplosionParticleInfo); // Not a particle info type, used in ClientboundExplodePacket
85#endif
86
88 {
89
90 };
91
93 {
94
95 }
96
97 std::string_view Particle::GetName() const
98 {
99#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
100 static constexpr std::array<std::string_view, static_cast<size_t>(ParticleType::NUM_PARTICLE_TYPES)> names = {
101#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
102 "ambient_entity_effect",
103#endif
104 "angry_villager",
105#if PROTOCOL_VERSION < 757 /* < 1.18 */
106 "barrier",
107#endif
108#if PROTOCOL_VERSION > 754 /* > 1.16.5 */ && PROTOCOL_VERSION < 757 /* < 1.18 */
109 "light",
110#endif
111 "block",
112#if PROTOCOL_VERSION > 756 /* > 1.17.1 */
113 "block_marker",
114#endif
115 "bubble",
116#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
117 "sulfur_bubbles",
118 "noxious_gas",
119 "noxious_gas_cloud",
120 "geyser",
121 "geyser_base",
122 "geyser_poof",
123 "geyser_plume",
124#endif
125 "cloud",
126#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
127 "copper_fire_flame",
128#endif
129 "crit",
130 "damage_indicator",
131 "dragon_breath",
132 "dripping_lava",
133#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
134 "falling_lava",
135 "landing_lava",
136#endif
137 "dripping_water",
138#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
139 "falling_water",
140#endif
141 "dust",
142#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
143 "dust_color_transition",
144#endif
145 "effect",
146 "elder_guardian",
147 "enchanted_hit",
148 "enchant",
149 "end_rod",
150 "entity_effect",
151 "explosion_emitter",
152 "explosion",
153#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
154 "gust",
155#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
156 "gust_emitter",
157#endif
158#endif
159#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
160 "small_gust",
161 "gust_emitter_large",
162 "gust_emitter_small",
163#endif
164#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
165 "sonic_boom",
166#endif
167 "falling_dust",
168 "firework",
169 "fishing",
170 "flame",
171#if PROTOCOL_VERSION > 761 /* > 1.19.3 */ && PROTOCOL_VERSION < 763 /* < 1.20 */
172 "dripping_cherry_leaves",
173 "falling_cherry_leaves",
174 "landing_cherry_leaves",
175#endif
176#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
177 "infested",
178#endif
179#if PROTOCOL_VERSION > 762 /* > 1.19.4 */
180 "cherry_leaves",
181#endif
182#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
183 "pale_oak_leaves",
184#endif
185#if PROTOCOL_VERSION > 776 /* > 26.2 */
186 "red_poplar_leaves",
187 "orange_poplar_leaves",
188 "yellow_poplar_leaves",
189#endif
190#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
191 "tinted_leaves",
192#endif
193#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
194 "sculk_soul",
195 "sculk_charge",
196 "sculk_charge_pop",
197#endif
198#if PROTOCOL_VERSION > 734 /* > 1.15.2 */
199 "soul_fire_flame",
200 "soul",
201#endif
202#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
203 "flash",
204#endif
205 "happy_villager",
206#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
207 "composter",
208#endif
209 "heart",
210 "instant_effect",
211 "item",
212#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
213 "vibration",
214#endif
215#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
216 "trail",
217#endif
218#if PROTOCOL_VERSION > 775 /* > 1.21.11 */
219 "pause_mob_growth",
220 "reset_mob_growth",
221#endif
222 "item_slime",
223#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
224 "item_cobweb",
225#endif
226 "item_snowball",
227 "large_smoke",
228 "lava",
229 "mycelium",
230 "note",
231 "poof",
232 "portal",
233 "rain",
234 "smoke",
235#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
236 "white_smoke",
237#endif
238#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
239 "sneeze",
240#endif
241 "spit",
242 "squid_ink",
243 "sweep_attack",
244 "totem_of_undying",
245 "underwater",
246 "splash",
247 "witch",
248 "bubble_pop",
249 "current_down",
250 "bubble_column_up",
251 "nautilus",
252 "dolphin",
253#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
254 "campfire_cosy_smoke",
255 "campfire_signal_smoke",
256#endif
257#if PROTOCOL_VERSION > 572 /* > 1.14.4 */
258 "dripping_honey",
259 "falling_honey",
260 "landing_honey",
261 "falling_nectar",
262#endif
263#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
264 "falling_spore_blossom",
265#endif
266#if PROTOCOL_VERSION > 734 /* > 1.15.2 */
267 "ash",
268 "crimson_spore",
269 "warped_spore",
270#endif
271#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
272 "spore_blossom_air",
273#endif
274#if PROTOCOL_VERSION > 734 /* > 1.15.2 */
275 "dripping_obsidian_tear",
276 "falling_obsidian_tear",
277 "landing_obsidian_tear",
278 "reverse_portal",
279 "white_ash",
280#endif
281#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
282 "small_flame",
283 "snowflake",
284 "dripping_dripstone_lava",
285 "falling_dripstone_lava",
286 "dripping_dripstone_water",
287 "falling_dripstone_water",
288 "glow_squid_ink",
289 "glow",
290 "wax_on",
291 "wax_off",
292 "electric_spark",
293 "scrape",
294#endif
295#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
296 "shriek",
297#endif
298#if PROTOCOL_VERSION > 762 /* > 1.19.4 */
299 "egg_crack",
300#endif
301#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
302 "dust_plume",
303#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
304 "gust_dust",
305#endif
306 "trial_spawner_detection",
307#endif
308#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
309 "trial_spawner_detection_ominous",
310 "vault_connection",
311 "dust_pillar",
312 "ominous_spawning",
313 "raid_omen",
314 "trial_omen",
315#endif
316#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
317 "block_crumble",
318#endif
319#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
320 "firefly",
321#endif
322#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
323 "sulfur_cube_goo",
324#endif
325 };
326#else
327 static constexpr std::array<std::string_view, static_cast<size_t>(ParticleType::NUM_PARTICLE_TYPES)> names = {
328 "explode",
329 "largeexplode",
330 "hugeexplosion",
331 "fireworksSpark",
332 "bubble",
333 "splash",
334 "wake",
335 "suspended",
336 "depthsuspend",
337 "crit",
338 "magicCrit",
339 "smoke",
340 "largesmoke",
341 "spell",
342 "instantSpell",
343 "mobSpell",
344 "mobSpellAmbient",
345 "witchMagic",
346 "dripWater",
347 "dripLava",
348 "angryVillager",
349 "happyVillager",
350 "townaura",
351 "note",
352 "portal",
353 "enchantmenttable",
354 "flame",
355 "lava",
356 "footstep",
357 "cloud",
358 "reddust",
359 "snowballpoof",
360 "snowshovel",
361 "slime",
362 "heart",
363 "barrier",
364 "iconcrack",
365 "blockcrack",
366 "blockdust",
367 "droplet",
368 "take",
369 "mobappearance",
370 "dragonbreath",
371 "endRod",
372 "damageIndicator",
373 "sweepAttack",
374 "fallingdust",
375 "totem",
376 "spit",
377 };
378#endif
379 if (ParticleType <= ParticleType::None || ParticleType >= ParticleType::NUM_PARTICLE_TYPES)
380 {
381 return "";
382 }
383 return names[static_cast<size_t>(ParticleType)];
384 }
385
387 {
388 if (particle_type_ <= ParticleType::None || particle_type_ >= ParticleType::NUM_PARTICLE_TYPES)
389 {
390 throw std::runtime_error("Unable to create particle with id: " + std::to_string(static_cast<int>(particle_type_)) + ".");
391 }
392 ParticleType = particle_type_;
393
394 switch (ParticleType)
395 {
396#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
399#if PROTOCOL_VERSION > 756 /* > 1.17.1 */
401#endif
402#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
404#endif
405#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
407#endif
408 Option = std::make_shared<BlockParticleOption>();
409 break;
411 Option = std::make_shared<DustParticleOption>();
412 break;
414 Option = std::make_shared<ItemParticleOption>();
415 break;
416#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
418 Option = std::make_shared<DustColorTransitionOption>();
419 break;
421 Option = std::make_shared<VibrationParticleOption>();
422 break;
423#endif
424#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
426 Option = std::make_shared<SculkChargeParticleOption>();
427 break;
429 Option = std::make_shared<ShriekParticleOption>();
430 break;
431#endif
432#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
434#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
436#endif
437#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
439#endif
440 Option = std::make_shared<ColorParticleOption>();
441 break;
442#endif
443#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
445 Option = std::make_shared<TrailParticleOption>();
446 break;
447#endif
448#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
450 Option = std::make_shared<PowerParticleOption>();
451 break;
454 Option = std::make_shared<SpellParticleOption>();
455 break;
456#endif
457#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
460 Option = std::make_shared<GeyserBaseParticleOptions>();
461 break;
464 Option = std::make_shared<GeyserParticleOptions>();
465 break;
466#endif
467#else //1.12.2
468 case ParticleType::Blockcrack:
469 case ParticleType::Blockdust:
471 Option = std::make_shared<BlockParticleOption>();
472 break;
473 case ParticleType::Iconcrack:
474 Option = std::make_shared<IconcrackParticleOption>();
475 break;
476#endif
477 default:
478 Option = std::make_shared<EmptyParticleOption>();
479 break;
480 }
481 return *this;
482 }
483
484#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
485 void Particle::ReadOption(ReadIterator& iter, size_t& length)
486 {
487 if (Option != nullptr)
488 {
489 Option->Read(iter, length);
490 }
491 }
492
493 void Particle::WriteOption(WriteContainer& container) const
494 {
495 if (Option != nullptr)
496 {
497 Option->Write(container);
498 }
499 }
500#endif
501
502 void Particle::ReadImpl(ReadIterator& iter, size_t& length)
503 {
504 ParticleType = ReadData<ProtocolCraft::ParticleType, VarInt>(iter, length);
506 if (Option != nullptr)
507 {
508 Option->Read(iter, length);
509 }
510 }
511
512 void Particle::WriteImpl(WriteContainer& container) const
513 {
514 WriteData<ProtocolCraft::ParticleType, VarInt>(ParticleType, container);
515 if (Option != nullptr)
516 {
517 Option->Write(container);
518 }
519 }
520
521 Json::Value Particle::SerializeImpl() const
522 {
523 Json::Value output;
524
525 output[std::string(field_name<ParticleType_index>)] = GetName();
526 output[std::string(field_name<Option_index>)] = Option == nullptr ? Json::Object() : Option->Serialize();
527
528 return output;
529 }
530}
#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:386
std::string_view GetName() const
Definition Particle.cpp:97
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator