|
18 | 18 | import org.jetbrains.annotations.Contract; |
19 | 19 | import org.jetbrains.annotations.Nullable; |
20 | 20 | import org.joml.Quaternionf; |
| 21 | +import org.joml.Vector3d; |
21 | 22 |
|
22 | 23 | import java.io.StreamCorruptedException; |
23 | 24 | import java.util.UUID; |
@@ -303,6 +304,73 @@ public boolean mustSyncDeserialization() { |
303 | 304 | } |
304 | 305 | })); |
305 | 306 |
|
| 307 | + Classes.registerClass(new ClassInfo<>(Vector3d.class, "vector") |
| 308 | + .user("vectors?") |
| 309 | + .name("Vector") |
| 310 | + .description("Vector is a collection of numbers. In Minecraft, 3D vectors are used to express velocities of entities.") |
| 311 | + .usage("vector(x, y, z)") |
| 312 | + .examples("") |
| 313 | + .since("2.2-dev23") |
| 314 | + .defaultExpression(new EventValueExpression<>(Vector3d.class)) |
| 315 | + .parser(new Parser<Vector3d>() { |
| 316 | + @Override |
| 317 | + @Nullable |
| 318 | + public Vector3d parse(final String s, final ParseContext context) { |
| 319 | + return null; |
| 320 | + } |
| 321 | + |
| 322 | + @Override |
| 323 | + public boolean canParse(final ParseContext context) { |
| 324 | + return false; |
| 325 | + } |
| 326 | + |
| 327 | + @Override |
| 328 | + public String toString(final Vector3d vec, final int flags) { |
| 329 | + return "x: " + Skript.toString(vec.x()) + ", y: " + Skript.toString(vec.y()) + ", z: " + Skript.toString(vec.z()); |
| 330 | + } |
| 331 | + |
| 332 | + @Override |
| 333 | + public String toVariableNameString(final Vector3d vec) { |
| 334 | + return "vector:" + vec.x() + "," + vec.y() + "," + vec.z(); |
| 335 | + } |
| 336 | + |
| 337 | + @Override |
| 338 | + public String getDebugMessage(final Vector3d vec) { |
| 339 | + return "(" + vec.x() + "," + vec.y() + "," + vec.z() + ")"; |
| 340 | + } |
| 341 | + }) |
| 342 | + .serializer(new Serializer<>() { |
| 343 | + @Override |
| 344 | + public Fields serialize(Vector3d o) { |
| 345 | + Fields f = new Fields(); |
| 346 | + f.putPrimitive("x", o.x()); |
| 347 | + f.putPrimitive("y", o.y()); |
| 348 | + f.putPrimitive("z", o.z()); |
| 349 | + return f; |
| 350 | + } |
| 351 | + |
| 352 | + @Override |
| 353 | + public void deserialize(Vector3d o, Fields f) { |
| 354 | + assert false; |
| 355 | + } |
| 356 | + |
| 357 | + @Override |
| 358 | + public Vector3d deserialize(final Fields f) throws StreamCorruptedException { |
| 359 | + return new Vector3d(f.getPrimitive("x", double.class), f.getPrimitive("y", double.class), f.getPrimitive("z", double.class)); |
| 360 | + } |
| 361 | + |
| 362 | + @Override |
| 363 | + public boolean mustSyncDeserialization() { |
| 364 | + return false; |
| 365 | + } |
| 366 | + |
| 367 | + @Override |
| 368 | + protected boolean canBeInstantiated() { |
| 369 | + return false; |
| 370 | + } |
| 371 | + }) |
| 372 | + .cloner(Vector3d::new)); |
| 373 | + |
306 | 374 | // joml type - for display entities |
307 | 375 | if (Skript.classExists("org.joml.Quaternionf")) |
308 | 376 | Classes.registerClass(new ClassInfo<>(Quaternionf.class, "quaternion") |
|
0 commit comments