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