Open AnimalsWritingCode opened 1 year ago
Going to call this PR here for now. Reimplements all of the existing ai functionality using the Brain API plus a couple small QoL changes like timeouts on fighting. None of the "phase 3" things should really be all that difficult to do, but I'd rather not tightly couple their progress to the core transition at this point.
The only open questions are about juvenile vs adult attack behavior and whether we want to rigorously implement forge hooks for target changes. I've covered setting it to a real target, but not when it's cleared because that will be a pain and skipping it is not any less compatible than the vanilla mobs.
One of those forge hooks (just for optifine) is deprecated in 1.19.2 for performance and being removed in 1.20, but I don't see a replacement, so I am not making a separate 1.19.x PR to remove/replace it at this point. Happy to do (only 2 lines) if you'd rather take the performance bump.
Of course open to whatever comments or changes. Just figured I'd get the ai overhaul rolling. Was torn on whether to implement the ai class statically like the vanilla mobs or as an instance so we could cache the dragon and brain reference, but decided static is more appropriate since the brain is really the worker for all the logic and the ai class is basically util methods to configure it.
Finally got around to fixing conflicts on this and testing it. Probably going to want to clean up the dragon landing while following an owner on the ground, but also probably best to save that for when a rewrite of the flying pathing is done.
I'm going to mark this as the actual OFFICIAL AI revamp, considering how far and organized this has come!
I condemn your work on this and I'm happy with where it is headed right now. There's a few things I'd like to change myself but that's what reviews and collaboration is for anyway.
I'm marking this as a draft while progress continues on this. Draft status can be removed once everything is complete. Polishing up can be done after that.
Thanks again for your hard work!
It may actually be good to re-target this to a feature branch for the overhaul and get this PR to mvp then expand on the ai in that branch. Just to avoid one mega PR holding everything up or forcing every update to be co-dependent.
Also, I was actually thinking of replacing the static ai class with an instance that can be created in the dragon class. I did it statically since that's how it's done in vanilla but it hurt to do since that's terrible levels of coupling.
out of curiosity, but would the AI bits discussed here be configurable (ex: 'what counts as a dragon') for mod compatibility?
In theory, this PR will completely convert the dragon ai to using the Brain API. In practice, we'll see if I get that far.
Opening this as a draft PR because I suspect it will be pretty large and take a fair bit of time plus wanted to keep it open for comments in-flight. Some of this might be better to create as separate PRs, but whatever, shoot for the moon.
Todo list
Phase 1 - Basics
Implement current ai logic limited to vanilla activities and behaviors.
Phase 2 - Custom
Implement remaining ai logic with custom activities, behaviors, and memories. No vanilla mobs using the Brain API are tameable, flying, or rideable+controllable, so any activities, behaviors, or memories for those will be implemented here. At least in 1.18.2, but it's probably easier to maintain a set of custom classes than a separate ai system for each version.
It's possible this is built in to vanilla but not explicitly called out.Already in random stroll behavior.Phase 3 - Big Brain
Send these dragons to college. Do new things that are just easier with the Brain API so dragons are smarter. These are probably good candidates for other PRs if they're going to be done.
Fight with breath weapons. Maybe prefer breath weapons at range, but have a cooldown to force melee in between.Make sure any breath weapons wouldn't hit owner. Want to get ahead of dragons killing their owners.