Makes sure NPC movements are the same
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
This commit is contained in:
parent
b094d34c62
commit
f4fa9e99a5
@ -172,10 +172,7 @@ public class BlacksmithListener implements Listener {
|
|||||||
BlacksmithVisuals.debug("Restored LookCLose range");
|
BlacksmithVisuals.debug("Restored LookCLose range");
|
||||||
}
|
}
|
||||||
|
|
||||||
BlacksmithVisuals.debug("Scheduling movement back to idle location");
|
moveNPC(npc, entity, targetLocation);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
|
|
||||||
entity.teleport(targetLocation), getWalkTime(entity.getLocation(), targetLocation));
|
|
||||||
npc.getNavigator().setTarget(targetLocation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -212,19 +209,30 @@ public class BlacksmithListener implements Listener {
|
|||||||
npc.getName() + " is unreachable!");
|
npc.getName() + " is unreachable!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Location finalTargetLocation = targetLocation;
|
|
||||||
|
|
||||||
|
return moveNPC(npc, entity, targetLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves an NPC to a different location
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC to be moved</p>
|
||||||
|
* @param entity <p>The NPC's entity</p>
|
||||||
|
* @param finalTargetLocation <p>The location the NPC should be moved to</p>
|
||||||
|
* @return <p>The assumed time it will take the NPC to get to the position</p>
|
||||||
|
*/
|
||||||
|
private long moveNPC(@NotNull NPC npc, @NotNull Entity entity, @NotNull Location finalTargetLocation) {
|
||||||
// Move NPC using Citizens path-finding
|
// Move NPC using Citizens path-finding
|
||||||
Location current = entity.getLocation().clone();
|
|
||||||
BlacksmithVisuals.debug("Preparing rotation and walk to working location");
|
BlacksmithVisuals.debug("Preparing rotation and walk to working location");
|
||||||
npc.teleport(current.clone().setDirection(targetLocation.toVector().subtract(current.clone().toVector())), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
Location current = entity.getLocation().clone();
|
||||||
|
npc.teleport(current.setDirection(finalTargetLocation.toVector().subtract(current.toVector())), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> npc.getNavigator().setTarget(finalTargetLocation), 2);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> npc.getNavigator().setTarget(finalTargetLocation), 2);
|
||||||
|
|
||||||
// Teleport the NPC tp get it in the exact final location
|
// Teleport the NPC tp get it in the exact final location
|
||||||
long walkTime = getWalkTime(entity.getLocation(), targetLocation);
|
long walkTime = getWalkTime(entity.getLocation(), finalTargetLocation);
|
||||||
BlacksmithVisuals.debug("Queuing teleportation to working position");
|
BlacksmithVisuals.debug("Queuing teleportation to working position");
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
|
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
|
||||||
entity.teleport(finalTargetLocation), walkTime);
|
entity.teleport(finalTargetLocation, PlayerTeleportEvent.TeleportCause.PLUGIN), walkTime);
|
||||||
return walkTime;
|
return walkTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user