From 96c7fc9147e36df7252bf49f858d09bda55f1834 Mon Sep 17 00:00:00 2001 From: TheMode Date: Sun, 11 Jul 2021 19:56:15 +0200 Subject: [PATCH] Add Vec#fromPoint --- .../java/net/minestom/server/coordinate/Vec.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/net/minestom/server/coordinate/Vec.java b/src/main/java/net/minestom/server/coordinate/Vec.java index b4b5b3654..d5084c9b8 100644 --- a/src/main/java/net/minestom/server/coordinate/Vec.java +++ b/src/main/java/net/minestom/server/coordinate/Vec.java @@ -53,6 +53,19 @@ public final class Vec implements Point { this(value, value, value); } + /** + * Converts a {@link Point} into a {@link Vec}. + * Will cast if possible, or instantiate a new object. + * + * @param point the point to convert + * @return the converted vector + */ + public static @NotNull Vec fromPoint(@NotNull Point point) { + if (point instanceof Vec) + return (Vec) point; + return new Vec(point.x(), point.y(), point.z()); + } + /** * Creates a new point with coordinated depending on {@code this}. *