4
4
#include " ParticleAPI.h"
5
5
6
6
#include " McAPI.h"
7
+ #include " ll/api/service/Bedrock.h"
7
8
#include " mc/deps/core/math/Color.h"
9
+ #include " mc/network/packet/SpawnParticleEffectPacket.h"
10
+ #include " mc/util/MolangVariable.h"
11
+ #include " mc/util/MolangVariableMap.h"
12
+ #include " mc/world/actor/player/Player.h"
13
+ #include " mc/world/level/Level.h"
14
+ #include " mc/world/level/dimension/Dimension.h"
15
+ #include " mc/world/phys/AABB.h"
8
16
9
17
#define GETVEC3 (v, d, u ) \
10
18
if (IsInstanceOf<IntPos>(u)) { \
@@ -28,58 +36,58 @@ std::string fto_string(const T a_value) {
28
36
out << a_value;
29
37
return out.str ();
30
38
}
31
- ParticleCUI ::ColorPalette getColorType (std::string s) {
39
+ ParticleSpawner ::ColorPalette getColorType (std::string s) {
32
40
switch (s[0 ]) {
33
41
case ' B' :
34
- return ParticleCUI ::ColorPalette::BLACK;
42
+ return ParticleSpawner ::ColorPalette::BLACK;
35
43
break ;
36
44
case ' I' :
37
- return ParticleCUI ::ColorPalette::INDIGO;
45
+ return ParticleSpawner ::ColorPalette::INDIGO;
38
46
break ;
39
47
case ' L' :
40
- return ParticleCUI ::ColorPalette::LAVENDER;
48
+ return ParticleSpawner ::ColorPalette::LAVENDER;
41
49
break ;
42
50
case ' T' :
43
- return ParticleCUI ::ColorPalette::TEAL;
51
+ return ParticleSpawner ::ColorPalette::TEAL;
44
52
break ;
45
53
case ' C' :
46
- return ParticleCUI ::ColorPalette::COCOA;
54
+ return ParticleSpawner ::ColorPalette::COCOA;
47
55
break ;
48
56
case ' D' :
49
- return ParticleCUI ::ColorPalette::DARK;
57
+ return ParticleSpawner ::ColorPalette::DARK;
50
58
break ;
51
59
case ' O' :
52
- return ParticleCUI ::ColorPalette::OATMEAL;
60
+ return ParticleSpawner ::ColorPalette::OATMEAL;
53
61
break ;
54
62
case ' W' :
55
- return ParticleCUI ::ColorPalette::WHITE;
63
+ return ParticleSpawner ::ColorPalette::WHITE;
56
64
break ;
57
65
case ' R' :
58
- return ParticleCUI ::ColorPalette::RED;
66
+ return ParticleSpawner ::ColorPalette::RED;
59
67
break ;
60
68
case ' A' :
61
- return ParticleCUI ::ColorPalette::APRICOT;
69
+ return ParticleSpawner ::ColorPalette::APRICOT;
62
70
break ;
63
71
case ' Y' :
64
- return ParticleCUI ::ColorPalette::YELLOW;
72
+ return ParticleSpawner ::ColorPalette::YELLOW;
65
73
break ;
66
74
case ' G' :
67
- return ParticleCUI ::ColorPalette::GREEN;
75
+ return ParticleSpawner ::ColorPalette::GREEN;
68
76
break ;
69
77
case ' V' :
70
- return ParticleCUI ::ColorPalette::VATBLUE;
78
+ return ParticleSpawner ::ColorPalette::VATBLUE;
71
79
break ;
72
80
case ' S' :
73
- return ParticleCUI ::ColorPalette::SLATE;
81
+ return ParticleSpawner ::ColorPalette::SLATE;
74
82
break ;
75
83
case ' P' :
76
- return ParticleCUI ::ColorPalette::PINK;
84
+ return ParticleSpawner ::ColorPalette::PINK;
77
85
break ;
78
86
case ' F' :
79
- return ParticleCUI ::ColorPalette::FAWN;
87
+ return ParticleSpawner ::ColorPalette::FAWN;
80
88
break ;
81
89
default :
82
- return ParticleCUI ::ColorPalette::WHITE;
90
+ return ParticleSpawner ::ColorPalette::WHITE;
83
91
break ;
84
92
}
85
93
}
@@ -89,9 +97,6 @@ ParticleSpawner* ParticleSpawner::create(const Arguments& args) {
89
97
if (args.size () < 3 ) return nullptr ;
90
98
try {
91
99
ParticleSpawner* p = new ParticleSpawner (args.thiz ());
92
- p->displayRadius = args[0 ].asNumber ().toInt64 ();
93
- p->highDetial = args[1 ].asBoolean ().value ();
94
- p->doubleSide = args[2 ].asBoolean ().value ();
95
100
return p;
96
101
} catch (...) {
97
102
return nullptr ;
@@ -126,207 +131,23 @@ Local<Value> ParticleSpawner::spawnParticle(const Arguments& args) {
126
131
GETVEC3 (pos, dimId, args[0 ])
127
132
CHECK_ARG_TYPE (args[1 ], ValueKind::kString );
128
133
particleName = args[1 ].asString ().toString ();
129
- ParticleCUI::spawnParticle (pos, particleName, dimId);
130
- return Boolean::newBoolean (true );
131
- }
132
- Local<Value> ParticleSpawner::drawPoint (const Arguments& args) {
133
- CHECK_ARGS_COUNT (args, 1 );
134
- Vec3 pos;
135
- int dimId;
136
- GETVEC3 (pos, dimId, args[0 ])
137
- auto pointSize = ParticleCUI::PointSize::PX4;
138
-
139
- if (args.size () > 1 ) {
140
- CHECK_ARG_TYPE (args[1 ], ValueKind::kNumber );
141
- pointSize = static_cast <ParticleCUI::PointSize>(args[1 ].asNumber ().toInt32 ());
134
+ auto dim = ll::service::getLevel ()->getDimension (dimId).lock ();
135
+ if (dim) {
136
+ dim->forEachPlayer ([&](Player& player) {
137
+ SpawnParticleEffectPacket pkt (pos, particleName, dimId, std::nullopt );
138
+ player.sendNetworkPacket (pkt);
139
+ return true ;
140
+ });
142
141
}
143
- std::string color = " W" ;
144
- if (args.size () > 2 ) {
145
- CHECK_ARG_TYPE (args[2 ], ValueKind::kString );
146
- color = args[2 ].asString ().toString ();
147
- }
148
- ParticleCUI::drawPoint (pos, dimId, pointSize, getColorType (color));
149
142
return Boolean::newBoolean (true );
150
143
}
144
+ Local<Value> ParticleSpawner::drawPoint (const Arguments& args) { return Boolean::newBoolean (true ); }
151
145
152
- Local<Value> ParticleSpawner::drawNumber (const Arguments& args) {
153
- CHECK_ARGS_COUNT (args, 2 );
154
- Vec3 pos;
155
- int dimId;
156
- GETVEC3 (pos, dimId, args[0 ])
157
- std::string numName;
158
- std::string color = " W" ;
159
- if (args.size () > 2 ) {
160
- CHECK_ARG_TYPE (args[2 ], ValueKind::kString );
161
- color = args[2 ].asString ().toString ();
162
- }
163
- if (args[1 ].getKind () == ValueKind::kNumber ) {
164
- numName = std::to_string (args[1 ].asNumber ().toInt64 ());
165
- } else if (args[1 ].getKind () == ValueKind::kString ) {
166
- numName = args[1 ].asString ().toString ();
167
- } else {
168
- LOG_WRONG_ARG_TYPE (__FUNCTION__);
169
- return Local<Value>();
170
- }
171
- ParticleCUI::spawnParticle (pos, std::string (" ll:num" ) + numName + color, dimId);
172
- return Boolean::newBoolean (true );
173
- }
174
- Local<Value> ParticleSpawner::drawAxialLine (const Arguments& args) {
175
- CHECK_ARGS_COUNT (args, 3 );
176
- Vec3 pos;
177
- int dimId;
178
- ParticleCUI::Direction direction;
179
- double length;
180
- GETVEC3 (pos, dimId, args[0 ])
181
- CHECK_ARG_TYPE (args[1 ], ValueKind::kNumber );
182
- direction = static_cast <ParticleCUI::Direction>(args[1 ].asNumber ().toInt32 ());
183
- CHECK_ARG_TYPE (args[2 ], ValueKind::kNumber );
184
- length = args[2 ].asNumber ().toDouble ();
185
- std::string color = " W" ;
186
- if (args.size () > 3 ) {
187
- CHECK_ARG_TYPE (args[3 ], ValueKind::kString );
188
- color = args[3 ].asString ().toString ();
189
- }
190
- ParticleCUI::drawAxialLine (pos, direction, length, dimId, getColorType (color));
191
- return Boolean::newBoolean (true );
192
- }
193
- Local<Value> ParticleSpawner::drawOrientedLine (const Arguments& args) {
194
- auto size = args.size ();
195
- CHECK_ARGS_COUNT (args, 2 );
196
- Vec3 start;
197
- Vec3 end;
198
- int dimId1;
199
- int dimId2;
200
- auto lineWidth = ParticleCUI::PointSize::PX4;
201
- double minSpacing = 1 ;
202
- int maxParticlesNum = 64 ;
203
- GETVEC3 (start, dimId1, args[0 ])
204
- GETVEC3 (end, dimId2, args[1 ])
205
- if (dimId1 != dimId2) {
206
- LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, " Pos should in the same dimension!" );
207
- return Local<Value>();
208
- }
209
-
210
- if (size > 2 ) {
211
- CHECK_ARG_TYPE (args[2 ], ValueKind::kNumber );
212
- lineWidth = static_cast <ParticleCUI::PointSize>(args[2 ].asNumber ().toInt32 ());
213
- }
214
-
215
- if (size > 3 ) {
216
- CHECK_ARG_TYPE (args[3 ], ValueKind::kNumber );
217
- minSpacing = args[3 ].asNumber ().toDouble ();
218
- }
219
-
220
- if (size > 4 ) {
221
- CHECK_ARG_TYPE (args[4 ], ValueKind::kNumber );
222
- maxParticlesNum = args[4 ].asNumber ().toInt32 ();
223
- }
224
-
225
- std::string color = " W" ;
226
- if (args.size () > 5 ) {
227
- CHECK_ARG_TYPE (args[5 ], ValueKind::kString );
228
- color = args[5 ].asString ().toString ();
229
- }
230
-
231
- ParticleCUI::drawOrientedLine (start, end, dimId1, lineWidth, minSpacing, maxParticlesNum, getColorType (color));
232
-
233
- return Boolean::newBoolean (true );
234
- }
235
- Local<Value> ParticleSpawner::drawCuboid (const Arguments& args) {
236
- auto size = args.size ();
237
- CHECK_ARGS_COUNT (args, 1 );
238
- Vec3 min;
239
- Vec3 max;
240
- int dimId1;
241
- int dimId2 = -1 ;
242
- std::string color = " W" ;
243
-
244
- if (IsInstanceOf<IntPos>(args[0 ])) {
245
- auto pos2 = EngineScope::currentEngine ()->getNativeInstance <IntPos>(args[0 ]);
246
- min = Vec3 (pos2->x , pos2->y , pos2->z );
247
- dimId1 = pos2->dim ;
248
- } else if (IsInstanceOf<FloatPos>(args[0 ])) {
249
- auto pos2 = EngineScope::currentEngine ()->getNativeInstance <FloatPos>(args[0 ]);
250
- min = Vec3 (pos2->x , pos2->y , pos2->z );
251
- dimId1 = pos2->dim ;
252
- } else {
253
- LOG_WRONG_ARG_TYPE (__FUNCTION__);
254
- return Local<Value>();
255
- }
256
- if (size > 1 ) {
257
- if (IsInstanceOf<IntPos>(args[1 ])) {
258
- auto pos2 = EngineScope::currentEngine ()->getNativeInstance <IntPos>(args[1 ]);
259
- max = Vec3 (pos2->x , pos2->y , pos2->z ) + 1 ;
260
- dimId2 = pos2->dim ;
261
- } else if (IsInstanceOf<FloatPos>(args[1 ])) {
262
- auto pos2 = EngineScope::currentEngine ()->getNativeInstance <FloatPos>(args[1 ]);
263
- max = Vec3 (pos2->x , pos2->y , pos2->z );
264
- dimId2 = pos2->dim ;
265
- } else {
266
- max = min + 1 ;
267
- CHECK_ARG_TYPE (args[1 ], ValueKind::kString );
268
- color = args[1 ].asString ().toString ();
269
- }
270
- } else {
271
- max = min + 1 ;
272
- }
273
-
274
- if (dimId2 != -1 && dimId1 != dimId2) {
275
- LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, " Pos should in the same dimension!" );
276
- return Local<Value>();
277
- }
278
-
279
- if (size > 2 ) {
280
- CHECK_ARG_TYPE (args[2 ], ValueKind::kString );
281
- color = args[2 ].asString ().toString ();
282
- }
283
-
284
- ParticleCUI::drawCuboid (AABB (min, max), dimId1, getColorType (color));
285
-
286
- return Boolean::newBoolean (true );
287
- }
288
- Local<Value> ParticleSpawner::drawCircle (const Arguments& args) {
289
- auto size = args.size ();
290
- CHECK_ARGS_COUNT (args, 3 );
291
- Vec3 pos;
292
- int dimId;
293
- ParticleCUI::Direction facing;
294
- double radius;
295
- GETVEC3 (pos, dimId, args[0 ])
296
- CHECK_ARG_TYPE (args[1 ], ValueKind::kNumber );
297
- facing = static_cast <ParticleCUI::Direction>(args[1 ].asNumber ().toInt32 ());
298
- CHECK_ARG_TYPE (args[2 ], ValueKind::kNumber );
299
- radius = args[2 ].asNumber ().toDouble ();
300
-
301
- auto lineWidth = ParticleCUI::PointSize::PX4;
302
- double minSpacing = 1 ;
303
- int maxParticlesNum = 64 ;
304
-
305
- if (size > 3 ) {
306
- CHECK_ARG_TYPE (args[3 ], ValueKind::kNumber );
307
- lineWidth = static_cast <ParticleCUI::PointSize>(args[3 ].asNumber ().toInt32 ());
308
- }
309
-
310
- if (size > 4 ) {
311
- CHECK_ARG_TYPE (args[4 ], ValueKind::kNumber );
312
- minSpacing = args[4 ].asNumber ().toDouble ();
313
- }
314
-
315
- if (size > 5 ) {
316
- CHECK_ARG_TYPE (args[5 ], ValueKind::kNumber );
317
- maxParticlesNum = args[5 ].asNumber ().toInt32 ();
318
- }
319
-
320
- std::string color = " W" ;
321
- if (args.size () > 6 ) {
322
- CHECK_ARG_TYPE (args[6 ], ValueKind::kString );
323
- color = args[6 ].asString ().toString ();
324
- }
325
-
326
- ParticleCUI::drawCircle (pos, facing, radius, dimId, lineWidth, minSpacing, maxParticlesNum, getColorType (color));
327
-
328
- return Boolean::newBoolean (true );
329
- }
146
+ Local<Value> ParticleSpawner::drawNumber (const Arguments& args) { return Boolean::newBoolean (true ); }
147
+ Local<Value> ParticleSpawner::drawAxialLine (const Arguments& args) { return Boolean::newBoolean (true ); }
148
+ Local<Value> ParticleSpawner::drawOrientedLine (const Arguments& args) { return Boolean::newBoolean (true ); }
149
+ Local<Value> ParticleSpawner::drawCuboid (const Arguments& args) { return Boolean::newBoolean (true ); }
150
+ Local<Value> ParticleSpawner::drawCircle (const Arguments& args) { return Boolean::newBoolean (true ); }
330
151
331
152
ClassDefine<ParticleSpawner> ParticleSpawnerBuilder =
332
153
defineClass<ParticleSpawner>(" ParticleSpawner" )
0 commit comments