Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
146 additions
and
25 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/net/citizensnpcs/api/ai/AbstractPathStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.citizensnpcs.api.ai; | ||
|
||
import net.citizensnpcs.api.ai.TargetType; | ||
import net.citizensnpcs.api.ai.event.CancelReason; | ||
|
||
public abstract class AbstractPathStrategy implements PathStrategy { | ||
private CancelReason cancelReason; | ||
private final TargetType type; | ||
|
||
protected AbstractPathStrategy(TargetType type) { | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public void clearCancelReason() { | ||
cancelReason = null; | ||
} | ||
|
||
@Override | ||
public CancelReason getCancelReason() { | ||
return cancelReason; | ||
} | ||
|
||
@Override | ||
public TargetType getTargetType() { | ||
return type; | ||
} | ||
|
||
protected void setCancelReason(CancelReason reason) { | ||
cancelReason = reason; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package net.citizensnpcs.api.ai; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.util.Vector; | ||
|
||
import net.citizensnpcs.api.ai.event.CancelReason; | ||
|
||
/** | ||
* A pathfinding strategy directed at a target. Has two states: pathfinding -> cancelled represented by | ||
* {@link #getCancelReason()}. | ||
*/ | ||
public interface PathStrategy { | ||
/** | ||
* Clears the CancelReason returned by {@link #getCancelReason()} and attempts to resume pathfinding. | ||
*/ | ||
void clearCancelReason(); | ||
|
||
/** | ||
* @return The reason for the pathfinding to stop, or null if it is still continuing. | ||
*/ | ||
CancelReason getCancelReason(); | ||
|
||
/** | ||
* @return A copy of the current path, if any | ||
*/ | ||
Iterable<Vector> getPath(); | ||
|
||
/** | ||
* @return Gets the target destination location | ||
*/ | ||
Location getTargetAsLocation(); | ||
|
||
/** | ||
* @return The {@link TargetType} of this strategy | ||
*/ | ||
TargetType getTargetType(); | ||
|
||
/** | ||
* Forcibly stops pathfinding. Note that this method does not necessarily set the cancel reason. | ||
*/ | ||
void stop(); | ||
|
||
/** | ||
* Updates and runs the pathfinding strategy on its current NPC and destination. | ||
* | ||
* @return Whether pathfinding has completed | ||
*/ | ||
boolean update(); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/net/citizensnpcs/api/astar/pathfinder/NeighbourGeneratorBlockExaminer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.citizensnpcs.api.astar.pathfinder; | ||
|
||
import java.util.List; | ||
|
||
public interface NeighbourGeneratorBlockExaminer extends BlockExaminer { | ||
public List<PathPoint> getNeighbours(BlockSource source, PathPoint point); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters