I took over setMoveDestination() for pathfinding my NPCs. I had to cancel the NPC navigator npc.getNavigator().cancelNavigation() to stop wander mode and do the custom pathfinding. How do I set the NPC back to wander mode? I tried the obvious getOrAddTrait() but I think I messed it up. Do I need to attach a new navigator or something or call useNewPathfinder(false)? To use custom pathfinding I did modify some of the local parameters on the navigator and took over setMoveDestination() each tick
#(shiftingkill) Wander Behavior vs Wander Waypoint Provider
1 messages · Page 1 of 1 (latest)
(shiftingkill) Resetting to wander after taking over setMoveDestination()
Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
Basically set waypoint provider to "wander" -> then to "none" to control with setMoveDestination() -> when set waypoint back to "wander" the NPC is just frozen
I tested without cancelNavigation() and the issue still persists
(shiftingkill) Wander Behavior vs Wander Waypoint Provider
When I acquire target and use custom pathfinding I setWaypointProvider to "none" and take over the npc navigator every tick but when I want to go back to "wander" how do I do that?
I clear my path set my target to null, cancel npc navigator, set "wander" waypoint provider, and I have tried nudging the NPC and all sorts of stuff
It's like the NPC only wandered when I spawned them and added their behaviors. Once the behaviors tried to set wander mode themselves it just breaks
I think it's because you used setWaypointProvider("none")
the new build allows you to use setWaypointProvider(null)
Thread Closing Reminder
Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.
If not yet resolved, please reply below to tell us what you still need.
(Note that if there is no reply for a few days, this thread will eventually close itself.)
@cosmic tide
I will be testing this in a few hours on that build
I believe that when I set this it is causing this exception in console on latest build
[01:12:37 INFO]: [Citizens] Exception while updating 19: Cannot invoke "net.citizensnpcs.trait.waypoint.WaypointProvider.isPaused()" because the return value of "net.citizensnpcs.trait.waypoint.Waypoints.getCurrentProvider()" is null.
[01:12:37 WARN]: java.lang.NullPointerException: Cannot invoke "net.citizensnpcs.trait.waypoint.WaypointProvider.isPaused()" because the return value of "net.citizensnpcs.trait.waypoint.Waypoints.getCurrentProvider()" is null
[01:12:37 WARN]: at Sentinel-2.9.2-SNAPSHOT-b529.jar//org.mcmonkey.sentinel.SentinelTrait.pauseWaypoints(SentinelTrait.java:1467)
[01:12:37 WARN]: at Sentinel-2.9.2-SNAPSHOT-b529.jar//org.mcmonkey.sentinel.SentinelTrait.runUpdate(SentinelTrait.java:1603)
[01:12:37 WARN]: at Sentinel-2.9.2-SNAPSHOT-b529.jar//org.mcmonkey.sentinel.SentinelTrait.run(SentinelTrait.java:1829)
[01:12:37 WARN]: at Citizens-2.0.41-b4040.jar//net.citizensnpcs.api.npc.AbstractNPC.update(AbstractNPC.java:484)
[01:12:37 WARN]: at Citizens-2.0.41-b4040.jar//net.citizensnpcs.npc.CitizensNPC.update(CitizensNPC.java:487)
[01:12:37 WARN]: at Citizens-2.0.41-b4040.jar//net.citizensnpcs.nms.v1_21_R7.entity.EntityHumanNPC.tick(EntityHumanNPC.java:385)
[01:12:37 WARN]: at net.minecraft.server.level.ServerLevel.tickNonPassenger(ServerLevel.java:1450)
[01:12:37 WARN]: at net.minecraft.world.level.Level.guardEntityTick(Level.java:1475)
[01:12:37 WARN]: at net.minecraft.server.level.ServerLevel.lambda$tick$4(ServerLevel.java:875)
[01:12:37 WARN]: at net.minecraft.world.level.entity.EntityTickList.forEach(EntityTickList.java:39)
[01:12:37 WARN]: at net.minecraft.server.level.ServerLevel.tick(ServerLevel.java:857)
...
Basically the issue was we took over pathfinding using the pathing library named "Pathetic" and to do so we disabled the wander of the NPC and setWaypointProvider("none") (and now null as you suggested). Then once done using our custom pathfinder we want to go back to wander mode and it caused the NPC to freeze in place like no matter what combo of setting waypoints or trying to nudge the NPC
We start by spawning NPC in with wander mode / waypoint provider wander + the behavior that triggers a pathfind when gets a new target. The behavior runs in parallel to wander and it works great until we set none/null and take over. Once we want to go back into wander it wont accept it
Do you think a temporary fix would be to just detect the NPC stopped moving and respawn them with behavior + wander? I am almost fully done updating to 1.21.11 it's exciting to be back
hmm. I think maybe asking in #1024101613905920052 would be good, I know it's an API breakage but I think we should accept nullability now
That error is now gone but the issue remains when I cancel navigator and useNewPathfinder and setWaypointProvider null in order to take over the NPC using setMoveDestination, once I want to go back into wander mode I try to getOrAddTrait() but it doesn't do anything. The NPC is stuck still
I also noticed useNewPathfinder(boolean) is deprecated now I wonder if I just am misusing the navigator. I have everything working to take over NPC pathing but just can't get it back into wander
Like maybe I need to set that false when I want to go back to using wander, or call it again?
@cosmic tide as I said I can't reproduce this with just commands, so maybe I need more context on your code
Can you give me a quick run down on like how to use setMoveDestination? I will assume there is no issue and my code is badly attempting to move the NPC. Like maybe I need to pause navigation not cancel it
So like pause nav (instead of cancel) -> getLocalParameters().useNewPathfinder(true) -> loop and use setMoveDestination(targetLoc) while we are pathing -> Now we want to go back to wander. So we unpause navigation (I used to call cancel here too), and call setWaypointProvider("wander")?
Like I bet my waypoint provider is trying to supply the navigator I cancelled, I will try again with the pause nav
setMoveDestination is called every tick by navigator
Right so when I take over I should cancel or pause it
I think that very step is where I lose my ability to put the npc back into wander, I'm firing up the server right now with the setPaused instead of cancelNav
When I stop calling setMoveDestination the navigator isnt taking back over, I setPaused(false) but also maybe useNewPathfinder() might be messing me up?
so setPaused(true) -> I start controlling using setMoveDestination() -> setPaused(false) but wander not taking back over even though I add the trait again
And of course on either side of that I am symmetrical about calling setWaypointProvider(null) and wander
I'm not using getNavigator().setTarget() because we are doing it every tick using the Pathfinding library that returns a nice list of points
I think I have tried things like setting navigator target to the npc location or nearby afterwards and it would run but wander wouldnt take over still
@cosmic tide maybe you could write a piece of minimal reproduction code because I am not able to debug your description of your codebase
Thank you for taking a look. I put a BehaviorGoalAdapter in pastebin, this basically has everything
https://pastebin.com/ZdJ6k27t
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Notable is where we have // --- TARGET ACQUIRED --- in which we setWaypointProvider null and then proceed to pathfind to target
Also this is using the A* library named 'Pathetic' so maybe you will end up writing this code yourself some day hehe the part where we do Node Progress Check
Combined with a DoorOpenBehavior and the sneaky teleport this is relatively unstoppable pathfinding
can you simplify it?
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
We set npc.getOrAddTrait(Waypoints.class).setWaypointProvider(null); where we acquire target otherwise the navigator will fight us
Remember that wandering also uses the behavior controller so its behavior won't run if yours is running
You can either make your own WanderGoal and run that if you want more control or finish your goal and let the wander provider run instead
@cosmic tide
Ah maybe that explains it. But while NPC was wandering around I am pretty sure my behavior run() was executing? But maybe it wasn't... So I should just return BehaviorStatus.SUCCESS when I find target invalid. The NPC will wander again. My behavior will no longer run, and should not contain search logic. The server can do the nearby radius search.. Thank you! Did I mistake anything in here?
that explains my behavior never relinquished control like my open door behavior either returns success/failure easily
Maybe I can contain search logic still I am not exactly sure, I guess since I kept returning BehaviorStatus.RUNNING I never gave control back to wander.
Alright well I have a mind bending tree to map out in my head but there is no issue so it will now be closed
Resolved
Thread closed as resolved.
Oh my goodness it was the local parameter range I set to 0.5f for the A* pathfinding. I did relinquish control to navigator correctly all along... So wander mode needs range of like 8.0f
Thread Reopened
Thread was manually reopened by @cosmic tide.
Do you have any recommendations on npc.getNavigator().getLocalParameters().range(float value)? I believe this is when an NPC considers itself "at" a target node. I set it to 0.5f to use the Pathing library.
Once I put the NPC back in wander mode it did not like 0.5F. It does like 8.0f but I have no idea really why it looks like a slightly different wander than original
So the stuck NPC is finally fixed due to that local parameter range goodness that was a lot
You should never change local parameters while the npc is not navigating that will change the default parameters
The default parameters are in the config, the range can be high like 64
The range is the pathfinding range not the distance margin
Ah so putting it to 0.5 didn't do what I thought it was doing? I could've sworn it was the thing that made it finally click but maybe I will remove all use of range and it should work
It is working great now thanks I removed the range and speed modifiers