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