Skip to content

Commit 9f54af9

Browse files
authored
improve TrackedLocation (#727)
1 parent 990e6d8 commit 9f54af9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

api/src/main/java/net/countercraft/movecraft/TrackedLocation.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import net.countercraft.movecraft.craft.Craft;
44
import net.countercraft.movecraft.util.MathUtils;
5+
import org.bukkit.NamespacedKey;
56
import org.jetbrains.annotations.NotNull;
67

8+
import java.util.HashSet;
9+
710
public class TrackedLocation {
811
private MovecraftLocation offSet;
912
private final Craft craft;
@@ -20,6 +23,21 @@ public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location
2023
offSet = location.subtract(midPoint);
2124
}
2225

26+
/**
27+
* Creates a new TrackedLocation instance which tracks a location about a craft's midpoint.
28+
* @param craft The craft that's that tied to the location.
29+
* @param location The absolute position to track. This location will be stored as a relative
30+
* location to the craft's central hitbox.
31+
* @param key The namespaced key that references a set of tracked locations stored within the craft.
32+
*/
33+
public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location, @NotNull NamespacedKey key) {
34+
this(craft, location);
35+
if (craft.getTrackedLocations().get(key) == null) {
36+
craft.getTrackedLocations().put(key, new HashSet<>());
37+
}
38+
craft.getTrackedLocations().get(key).add(this);
39+
}
40+
2341
/**
2442
* Rotates the stored location.
2543
* @param rotation A clockwise or counter-clockwise direction to rotate.
@@ -44,4 +62,12 @@ public MovecraftLocation getAbsoluteLocation() {
4462
public MovecraftLocation getOffSet() {
4563
return offSet;
4664
}
65+
66+
/**
67+
* Gets the craft associated with the tracked location.
68+
* @return Returns the craft.
69+
*/
70+
public Craft getCraft() {
71+
return craft;
72+
}
4773
}

0 commit comments

Comments
 (0)