From 9f54af9737733dd8645a10cca63d1b1af00df3a3 Mon Sep 17 00:00:00 2001 From: goodroach <68086172+goodroach@users.noreply.github.com> Date: Sat, 25 Jan 2025 13:59:11 -1000 Subject: [PATCH] improve TrackedLocation (#727) --- .../movecraft/TrackedLocation.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java b/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java index d61d74cab..8b395d0b2 100644 --- a/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java +++ b/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java @@ -2,8 +2,11 @@ import net.countercraft.movecraft.craft.Craft; import net.countercraft.movecraft.util.MathUtils; +import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; +import java.util.HashSet; + public class TrackedLocation { private MovecraftLocation offSet; private final Craft craft; @@ -20,6 +23,21 @@ public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location offSet = location.subtract(midPoint); } + /** + * Creates a new TrackedLocation instance which tracks a location about a craft's midpoint. + * @param craft The craft that's that tied to the location. + * @param location The absolute position to track. This location will be stored as a relative + * location to the craft's central hitbox. + * @param key The namespaced key that references a set of tracked locations stored within the craft. + */ + public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location, @NotNull NamespacedKey key) { + this(craft, location); + if (craft.getTrackedLocations().get(key) == null) { + craft.getTrackedLocations().put(key, new HashSet<>()); + } + craft.getTrackedLocations().get(key).add(this); + } + /** * Rotates the stored location. * @param rotation A clockwise or counter-clockwise direction to rotate. @@ -44,4 +62,12 @@ public MovecraftLocation getAbsoluteLocation() { public MovecraftLocation getOffSet() { return offSet; } + + /** + * Gets the craft associated with the tracked location. + * @return Returns the craft. + */ + public Craft getCraft() { + return craft; + } }