I asked this question a while ago and fullwall told me I'd need to code it myself, so here's my approach so far:
- Make a custom trait
- Make it so that the NPC will navigate normally if it can get to the path via walking
- Make the NPC build (todo) if it cannot get to the path normally
Here's my approach so far:
@Override
public void run() {
new BukkitRunnable() {
@Override
public void run() {
if (!npc.isSpawned()) return;
try {
Location targetLocation = npc.getNavigator().getTargetAsLocation();
if (targetLocation != null && npc.getNavigator().canNavigateTo(targetLocation)) {
debugMessage("NPC can navigate to " + targetLocation);
} else {
debugMessage("NPC cannot navigate to " + targetLocation);
}
// If stuck or unable to see the target, handle obstacles
debugMessage("NPC cannot see target location.");
handleObstacle();
} catch (Exception e) {
e.printStackTrace();
}
}
}.runTaskTimer(JavaPlugin.getPlugin(Mai.class), 1, 1);
the handleObstacle(); code will be written later to handle the actual building
however, canNavigateTo running every tick is extremely computationally expensive, my server is basically unplayable with that code. is there a more elegant way to do this? i want to make sure im not overcomplicating it