Botcraft 1.21.5
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 > 769 /* > 1.21.4 */
150 "tinted_leaves",
151#endif
152 #if PROTOCOL_VERSION > 758 /* > 1.18.2 */
153 "sculk_soul",
154 "sculk_charge",
155 "sculk_charge_pop",
156 #endif
157 #if PROTOCOL_VERSION > 734 /* > 1.15.2 */
158 "soul_fire_flame",
159 "soul",
160 #endif
161 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
162 "flash",
163 #endif
164 "happy_villager",
165 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
166 "composter",
167 #endif
168 "heart",
169 "instant_effect",
170 "item",
171 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
172 "vibration",
173 #endif
174#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
175 "trail",
176#endif
177 "item_slime",
178 #if PROTOCOL_VERSION > 765 /* > 1.20.4 */
179 "item_cobweb",
180 #endif
181 "item_snowball",
182 "large_smoke",
183 "lava",
184 "mycelium",
185 "note",
186 "poof",
187 "portal",
188 "rain",
189 "smoke",
190 #if PROTOCOL_VERSION > 764 /* > 1.20.2 */
191 "white_smoke",
192 #endif
193 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
194 "sneeze",
195 #endif
196 "spit",
197 "squid_ink",
198 "sweep_attack",
199 "totem_of_undying",
200 "underwater",
201 "splash",
202 "witch",
203 "bubble_pop",
204 "current_down",
205 "bubble_column_up",
206 "nautilus",
207 "dolphin",
208 #if PROTOCOL_VERSION > 476 /* > 1.13.2 */
209 "campfire_cosy_smoke",
210 "campfire_signal_smoke",
211 #endif
212 #if PROTOCOL_VERSION > 572 /* > 1.14.4 */
213 "dripping_honey",
214 "falling_honey",
215 "landing_honey",
216 "falling_nectar",
217 #endif
218 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
219 "falling_spore_blossom",
220 #endif
221 #if PROTOCOL_VERSION > 734 /* > 1.15.2 */
222 "ash",
223 "crimson_spore",
224 "warped_spore",
225 #endif
226 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
227 "spore_blossom_air",
228 #endif
229 #if PROTOCOL_VERSION > 734 /* > 1.15.2 */
230 "dripping_obsidian_tear",
231 "falling_obsidian_tear",
232 "landing_obsidian_tear",
233 "reverse_portal",
234 "white_ash",
235 #endif
236 #if PROTOCOL_VERSION > 754 /* > 1.16.5 */
237 "small_flame",
238 "snowflake",
239 "dripping_dripstone_lava",
240 "falling_dripstone_lava",
241 "dripping_dripstone_water",
242 "falling_dripstone_water",
243 "glow_squid_ink",
244 "glow",
245 "wax_on",
246 "wax_off",
247 "electric_spark",
248 "scrape",
249 #endif
250 #if PROTOCOL_VERSION > 758 /* > 1.18.2 */
251 "shriek",
252 #endif
253 #if PROTOCOL_VERSION > 762 /* > 1.19.4 */
254 "egg_crack",
255 #endif
256 #if PROTOCOL_VERSION > 764 /* > 1.20.2 */
257 "dust_plume",
258 #if PROTOCOL_VERSION < 766 /* < 1.20.5 */
259 "gust_dust",
260 #endif
261 "trial_spawner_detection",
262 #endif
263 #if PROTOCOL_VERSION > 765 /* > 1.20.4 */
264 "trial_spawner_detection_ominous",
265 "vault_connection",
266 "dust_pillar",
267 "ominous_spawning",
268 "raid_omen",
269 "trial_omen",
270 #endif
271#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
272 "block_crumble",
273#endif
274#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
275 "firefly",
276#endif
277 };
278#else
279 static constexpr std::array<std::string_view, static_cast<size_t>(ParticleType::NUM_PARTICLE_TYPES)> names = {
280 "explode",
281 "largeexplode",
282 "hugeexplosion",
283 "fireworksSpark",
284 "bubble",
285 "splash",
286 "wake",
287 "suspended",
288 "depthsuspend",
289 "crit",
290 "magicCrit",
291 "smoke",
292 "largesmoke",
293 "spell",
294 "instantSpell",
295 "mobSpell",
296 "mobSpellAmbient",
297 "witchMagic",
298 "dripWater",
299 "dripLava",
300 "angryVillager",
301 "happyVillager",
302 "townaura",
303 "note",
304 "portal",
305 "enchantmenttable",
306 "flame",
307 "lava",
308 "footstep",
309 "cloud",
310 "reddust",
311 "snowballpoof",
312 "snowshovel",
313 "slime",
314 "heart",
315 "barrier",
316 "iconcrack",
317 "blockcrack",
318 "blockdust",
319 "droplet",
320 "take",
321 "mobappearance",
322 "dragonbreath",
323 "endRod",
324 "damageIndicator",
325 "sweepAttack",
326 "fallingdust",
327 "totem",
328 "spit",
329 };
330#endif
331 if (ParticleType <= ParticleType::None || ParticleType >= ParticleType::NUM_PARTICLE_TYPES)
332 {
333 return "";
334 }
335 return names[static_cast<size_t>(ParticleType)];
336 }
337
339 {
340 if (particle_type_ <= ParticleType::None || particle_type_ >= ParticleType::NUM_PARTICLE_TYPES)
341 {
342 throw std::runtime_error("Unable to create particle with id: " + std::to_string(static_cast<int>(particle_type_)) + ".");
343 }
344 ParticleType = particle_type_;
345
346 switch (ParticleType)
347 {
348#if PROTOCOL_VERSION > 392 /* > 1.12.2 */
351#if PROTOCOL_VERSION > 756 /* > 1.17.1 */
353#endif
354#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
356#endif
357#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
359#endif
360 Options = std::make_shared<BlockParticleOptions>();
361 break;
363 Options = std::make_shared<DustParticleOptions>();
364 break;
366 Options = std::make_shared<ItemParticleOptions>();
367 break;
368#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
370 Options = std::make_shared<DustColorTransitionOptions>();
371 break;
373 Options = std::make_shared<VibrationParticleOptions>();
374 break;
375#endif
376#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
378 Options = std::make_shared<SculkChargeParticleOptions>();
379 break;
381 Options = std::make_shared<ShriekParticleOptions>();
382 break;
383#endif
384#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
386#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
388#endif
389 Options = std::make_shared<ColorParticleOptions>();
390 break;
391#endif
392#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
394 Options = std::make_shared<TrailParticleOptions>();
395 break;
396#endif
397#else //1.12.2
398 case ParticleType::Blockcrack:
399 case ParticleType::Blockdust:
401 Options = std::make_shared<BlockParticleOptions>();
402 break;
403 case ParticleType::Iconcrack:
404 Options = std::make_shared<IconcrackParticleOptions>();
405 break;
406#endif
407 default:
408 Options = std::make_shared<EmptyParticleOptions>();
409 break;
410 }
411 return *this;
412 }
413
414#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
415 void Particle::ReadOptions(ReadIterator& iter, size_t& length)
416 {
417 if (Options != nullptr)
418 {
419 Options->Read(iter, length);
420 }
421 }
422
423 void Particle::WriteOptions(WriteContainer& container) const
424 {
425 if (Options != nullptr)
426 {
427 Options->Write(container);
428 }
429 }
430#endif
431
432 void Particle::ReadImpl(ReadIterator& iter, size_t& length)
433 {
434 ParticleType = ReadData<ProtocolCraft::ParticleType, VarInt>(iter, length);
436 if (Options != nullptr)
437 {
438 Options->Read(iter, length);
439 }
440 }
441
442 void Particle::WriteImpl(WriteContainer& container) const
443 {
444 WriteData<ProtocolCraft::ParticleType, VarInt>(ParticleType, container);
445 if (Options != nullptr)
446 {
447 Options->Write(container);
448 }
449 }
450
451 Json::Value Particle::SerializeImpl() const
452 {
453 Json::Value output;
454
455 output[std::string(field_name<ParticleType_index>)] = GetName();
456 output[std::string(field_name<Options_index>)] = Options == nullptr ? Json::Object() : Options->Serialize();
457
458 return output;
459 }
460}
#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:338
std::string_view GetName() const
Definition Particle.cpp:73
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator