Skip to content

Commit

Permalink
improve TrackedLocation (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodroach authored Jan 25, 2025
1 parent 990e6d8 commit 9f54af9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions api/src/main/java/net/countercraft/movecraft/TrackedLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
}
}

0 comments on commit 9f54af9

Please sign in to comment.