Skip to content

Commit

Permalink
Clone goal vector
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 5, 2023
1 parent de29466 commit 1d75cd1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Expand Up @@ -6,7 +6,7 @@
import net.citizensnpcs.api.astar.AStarGoal;

public class VectorGoal implements AStarGoal<VectorNode> {
final Vector goal;
private final Vector goal;
private final float leeway;

public VectorGoal(Location dest, float range) {
Expand All @@ -23,6 +23,10 @@ public float g(VectorNode from, VectorNode to) {
return from.distance(to);
}

public Vector getGoalVector() {
return goal.clone();
}

@Override
public float getInitialCost(VectorNode node) {
return (float) node.getVector().distance(goal);
Expand All @@ -35,7 +39,7 @@ public float h(VectorNode from) {

@Override
public boolean isFinished(VectorNode node) {
double distanceSquared = node.location.distanceSquared(goal);
return goal.equals(node.location) || distanceSquared <= leeway;
double distance = node.location.distance(goal);
return goal.equals(node.location) || distance <= leeway;
}
}
Expand Up @@ -89,7 +89,7 @@ private float getBlockCost() {

@Override
public Vector getGoal() {
return info.goal.goal;
return info.goal.getGoalVector();
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/citizensnpcs/api/trait/Trait.java
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.event.Listener;

import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey;
Expand Down Expand Up @@ -78,6 +79,13 @@ public void onCopy() {
public void onDespawn() {
}

/**
* Called just before the attached {@link NPC} is despawned. {@link NPC#getEntity()} will be non-null.
*/
public void onDespawn(DespawnReason reason) {
onDespawn();
}

/**
* Called just before the {@link NPC} is spawned. {@link NPC#getEntity()} will return an <em>unspawned</em> entity.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/citizensnpcs/api/util/BoundingBox.java
Expand Up @@ -90,6 +90,10 @@ public BoundingBox mul(double x, double y, double z) {
return new BoundingBox(minX * x, minY * y, minZ * z, maxX * x, maxY * y, maxZ * z);
}

public org.bukkit.util.BoundingBox toBukkit() {
return new org.bukkit.util.BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}

public EntityDim toDimensions() {
return new EntityDim(Math.abs(maxX - minX) * 2, Math.abs(maxY - minY));
}
Expand Down

0 comments on commit 1d75cd1

Please sign in to comment.