Skip to content

Ribbit pathfinding fixes - #73

Open
kvnmtz wants to merge 2 commits into
yungnickyoung:1.20.1from
kvnmtz:fix/1.20.1/ribbit-pathfinding
Open

Ribbit pathfinding fixes#73
kvnmtz wants to merge 2 commits into
yungnickyoung:1.20.1from
kvnmtz:fix/1.20.1/ribbit-pathfinding

Conversation

@kvnmtz

@kvnmtz kvnmtz commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

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:

/data modify @e[type=ribbits:ribbit,sort=nearest,limit=1] HomePosX 1000

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 RibbitGoHomeGoal to 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's Turtle.TurtleGoHomeGoal.

To make this work correctly, I also had to modify the navigation of the RibbitEntity a 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 standard AmphibiousPathNavigation because the door-related AI goals only work with GroundPathNavigation, 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 RibbitGoHomeGoal to 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 a getNavigation().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 dryPos which 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 set targetCropPos (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 for isInWater() now, so the ribbit will put away the umbrella and start floating naturally.

@kvnmtz kvnmtz closed this Dec 31, 2025
@kvnmtz kvnmtz changed the title fix/1.20.1/ribbit-pathfinding Ribbit pathfinding fixes Dec 31, 2025
@kvnmtz kvnmtz reopened this Dec 31, 2025
@kvnmtz
kvnmtz marked this pull request as ready for review December 31, 2025 12:52
@yungnickyoung

Copy link
Copy Markdown
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.

@kvnmtz

kvnmtz commented Mar 9, 2026

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ribbits attempting pathfinding despite new home set java.lang.Exception: Entity AI Task lag

2 participants