Botcraft 26.2
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 > 769 /* > 1.21.4 */
186 "tinted_leaves",
187#endif
188#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
189 "sculk_soul",
190 "sculk_charge",
191 "sculk_charge_pop",
192#endif
193#if PROTOCOL_VERSION > 734 /* > 1.15.2 */
194 "soul_fire_flame",
195 "soul",
196#endif
197#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
198 "flash",
199#endif
200 "happy_villager",
201#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
202 "composter",
203#endif
204 "heart",
205 "instant_effect",
206 "item",
207#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
208 "vibration",
209#endif
210#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
211 "trail",
212#endif
213#if PROTOCOL_VERSION > 775 /* > 1.21.11 */
214 "pause_mob_growth",
215 "reset_mob_growth",
216#endif
217 "item_slime",
218#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
219 "item_cobweb",
220#endif
221 "item_snowball",
222 "large_smoke",
223 "lava",
224 "mycelium",
225 "note",
226 "poof",
227 "portal",
228 "rain",
229 "smoke",
230#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
231 "white_smoke",
232#endif
233#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
234 "sneeze",
235#endif
236 "spit",
237 "squid_ink",
238 "sweep_attack",
239 "totem_of_undying",
240 "underwater",
241 "splash",
242 "witch",
243 "bubble_pop",
244 "current_down",
245 "bubble_column_up",
246 "nautilus",
247 "dolphin",
248#if PROTOCOL_VERSION > 476 /* > 1.13.2 */
249 "campfire_cosy_smoke",
250 "campfire_signal_smoke",
251#endif
252#if PROTOCOL_VERSION > 572 /* > 1.14.4 */
253 "dripping_honey",
254 "falling_honey",
255 "landing_honey",
256 "falling_nectar",
257#endif
258#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
259 "falling_spore_blossom",
260#endif
261#if PROTOCOL_VERSION > 734 /* > 1.15.2 */
262 "ash",
263 "crimson_spore",
264 "warped_spore",
265#endif
266#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
267 "spore_blossom_air",
268#endif
269#if PROTOCOL_VERSION > 734 /* > 1.15.2 */
270 "dripping_obsidian_tear",
271 "falling_obsidian_tear",
272 "landing_obsidian_tear",
273 "reverse_portal",
274 "white_ash",
275#endif
276#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
277 "small_flame",
278 "snowflake",
279 "dripping_dripstone_lava",
280 "falling_dripstone_lava",
281 "dripping_dripstone_water",
282 "falling_dripstone_water",
283 "glow_squid_ink",
284 "glow",
285 "wax_on",
286 "wax_off",
287 "electric_spark",
288 "scrape",
289#endif
290#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
291 "shriek",
292#endif
293#if PROTOCOL_VERSION > 762 /* > 1.19.4 */
294 "egg_crack",
295#endif
296#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
297 "dust_plume",
298#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
299 "gust_dust",
300#endif
301 "trial_spawner_detection",
302#endif
303#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
304 "trial_spawner_detection_ominous",
305 "vault_connection",
306 "dust_pillar",
307 "ominous_spawning",
308 "raid_omen",
309 "trial_omen",
310#endif
311#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
312 "block_crumble",
313#endif
314#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
315 "firefly",
316#endif
317#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
318 "sulfur_cube_goo",
319#endif
320 };
321#else
322 static constexpr std::array<std::string_view, static_cast<size_t>(ParticleType::NUM_PARTICLE_TYPES)> names = {
323 "explode",
324 "largeexplode",
325 "hugeexplosion",
326 "fireworksSpark",
327 "bubble",
328 "splash",
329 "wake",
330 "suspended",
331 "depthsuspend",
332 "crit",
333 "magicCrit",
334 "smoke",
335 "largesmoke",
336 "spell",
337 "instantSpell",
338 "mobSpell",
339 "mobSpellAmbient",
340 "witchMagic",
341 "dripWater",
342 "dripLava",
343 "angryVillager",
344 "happyVillager",
345 "townaura",
346 "note",
347 "portal",
348 "enchantmenttable",
349 "flame",
350 "lava",
351 "footstep",
352 "cloud",
353 "reddust",
354 "snowballpoof",
355 "snowshovel",
356 "slime",
357 "heart",
358 "barrier",
359 "iconcrack",
360 "blockcrack",
361 "blockdust",
362 "droplet",
363 "take",
364 "mobappearance",
365 "dragonbreath",
366 "endRod",
367 "damageIndicator",
368 "sweepAttack",
369 "fallingdust",
370 "totem",
371 "spit",
372 };
373#endif
374 if (ParticleType <= ParticleType::None || ParticleType >= ParticleType::NUM_PARTICLE_TYPES)
375 {
376 return "";
377 }
378 return names[static_cast<size_t>(ParticleType)];
379 }
380
382 {
383 if (particle_type_ <= ParticleType::None || particle_type_ >= ParticleType::NUM_PARTICLE_TYPES)
384 {
385 throw std::runtime_error("Unable to create particle with id: " + std::to_string(static_cast<int>(particle_type_)) + ".");
386 }
387 ParticleType = particle_type_;
388
389 switch (ParticleType)
390 {
391#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
394#if PROTOCOL_VERSION > 756 /* > 1.17.1 */
396#endif
397#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
399#endif
400#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
402#endif
403 Option = std::make_shared<BlockParticleOption>();
404 break;
406 Option = std::make_shared<DustParticleOption>();
407 break;
409 Option = std::make_shared<ItemParticleOption>();
410 break;
411#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
413 Option = std::make_shared<DustColorTransitionOption>();
414 break;
416 Option = std::make_shared<VibrationParticleOption>();
417 break;
418#endif
419#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
421 Option = std::make_shared<SculkChargeParticleOption>();
422 break;
424 Option = std::make_shared<ShriekParticleOption>();
425 break;
426#endif
427#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
429#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
431#endif
432#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
434#endif
435 Option = std::make_shared<ColorParticleOption>();
436 break;
437#endif
438#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
440 Option = std::make_shared<TrailParticleOption>();
441 break;
442#endif
443#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
445 Option = std::make_shared<PowerParticleOption>();
446 break;
449 Option = std::make_shared<SpellParticleOption>();
450 break;
451#endif
452#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
455 Option = std::make_shared<GeyserBaseParticleOptions>();
456 break;
459 Option = std::make_shared<GeyserParticleOptions>();
460 break;
461#endif
462#else //1.12.2
463 case ParticleType::Blockcrack:
464 case ParticleType::Blockdust:
466 Option = std::make_shared<BlockParticleOption>();
467 break;
468 case ParticleType::Iconcrack:
469 Option = std::make_shared<IconcrackParticleOption>();
470 break;
471#endif
472 default:
473 Option = std::make_shared<EmptyParticleOption>();
474 break;
475 }
476 return *this;
477 }
478
479#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
480 void Particle::ReadOption(ReadIterator& iter, size_t& length)
481 {
482 if (Option != nullptr)
483 {
484 Option->Read(iter, length);
485 }
486 }
487
488 void Particle::WriteOption(WriteContainer& container) const
489 {
490 if (Option != nullptr)
491 {
492 Option->Write(container);
493 }
494 }
495#endif
496
497 void Particle::ReadImpl(ReadIterator& iter, size_t& length)
498 {
499 ParticleType = ReadData<ProtocolCraft::ParticleType, VarInt>(iter, length);
501 if (Option != nullptr)
502 {
503 Option->Read(iter, length);
504 }
505 }
506
507 void Particle::WriteImpl(WriteContainer& container) const
508 {
509 WriteData<ProtocolCraft::ParticleType, VarInt>(ParticleType, container);
510 if (Option != nullptr)
511 {
512 Option->Write(container);
513 }
514 }
515
516 Json::Value Particle::SerializeImpl() const
517 {
518 Json::Value output;
519
520 output[std::string(field_name<ParticleType_index>)] = GetName();
521 output[std::string(field_name<Option_index>)] = Option == nullptr ? Json::Object() : Option->Serialize();
522
523 return output;
524 }
525}
#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:381
std::string_view GetName() const
Definition Particle.cpp:97
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator