Ribbit pathfinding fixes - #73
Open
kvnmtz wants to merge 2 commits into
Open
Conversation
Owner
|
Hey, sorry it's taken me so long to look at this. I tried testing the long-range return to home goal with a nitwit by dragging him far away with a lead during the day and then setting time to night, but he just stands there. It appears the GoHome goal no longer works at long range. |
Contributor
Author
|
Not a problem at all :) That seems weird--I actually tested this quite a lot, I'll definitely have a look at it again when I get the chance |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #16 and fixes #42.
Performance issues
I confirmed the performance issues from #16 by creating a superflat singleplayer world, spawning a ribbit in a fenced-in area, and running this command to set the home position to a place ~1000 blocks away:
The ms/ticks value on the F3 menu increased from 1-2 ms/tick to ~40 ms/tick after running the command.
I suspect this happened because the navigation calculates the whole path to the home position every tick, as the navigation stopped immediately because of the fence.
I fixed this by reworking
RibbitGoHomeGoalto select a random position 16-24 blocks away in the general direction of the home position and navigating to that (so it doesn't calculate the whole path at once, just a small part). For this, I adapted the logic from vanilla'sTurtle.TurtleGoHomeGoal.To make this work correctly, I also had to modify the navigation of the
RibbitEntitya bit so water blocks are treated as valid targets (ribbits could get stuck in large bodies of water otherwise). I couldn't just use the standardAmphibiousPathNavigationbecause the door-related AI goals only work withGroundPathNavigation, so I had to extend and modify it accordingly.In my testing, it worked well, but you may want to test it yourself to confirm it works correctly.
For distances <= 16 blocks, the goal switches to direct navigation as in the previous logic.
Pathfinding to old home despite new home being set
#42 was a bit tough to figure out, but I confirmed it as well. I suspected
RibbitGoHomeGoalto be the culprit here too because the navigation was never manually stopped when the home was reset. However, it seems like that happened automatically a few seconds later. Still, I added agetNavigation().stop()call when setting a new home just to be safe.After a bit more testing, I figured out the real issue: the profession-specific goals. The ribbits weren't actually pathfinding to their old home position, but to their "objectives" near the old home. Fisherman ribbits, for example, tried to pathfind to a previously determined
dryPoswhich could be thousands of blocks away (RibbitFishGoal). Nitwits would wander off to their potential master ribbit (RibbitPlayMusicGoal), and gardeners would try to find their way back to a previously settargetCropPos(RibbitWaterCropsGoal).I added methods that reset these goals, which are called when a new home is set.
Small bonus issue
While testing the navigation, I found that ribbits would continue to fall to the bottom of the sea when their umbrella was out because the check only accounted for
onGround(). I made it also account forisInWater()now, so the ribbit will put away the umbrella and start floating naturally.