Dragon-Mounts-Legacy
Dragon-Mounts-Legacy copied to clipboard
Give dragons a Brain
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.
- [x] Remove existing goal ai
- [x] Create core behaviors
- [x] Don't drown
- [x] Look at look target
- [x] Walk to walk target
- [x] Retaliate against attackers
- [x] Create idle behaviors
- [x] Breeding
- [x] Random strolls
- [x] Random looking
- [x] Doing nothing
- [x] Non-tame random targeting
- [x] Animals except other dragons
- [x] Create fight behaviors
- [x] Move to target
- [x] Attack target.
- [x] Need to confirm attack cooldown. Is currently 2 sec for adults and .75 sec for juveniles based on Hoglin ai, but that is basically placeholder.
- [x] Babies can't attack, juveniles and up can. Damage is based on the attribute, which is scaled by their age.
- [x] Stop attacking if the target is inaccessible (not existing behavior, but kinda needed for the Brain to move on eventually)
- [x] Create avoid behaviors
- [x] Flee from target if baby (not technically part of existing behavior but easy to implement to save babies)
- [x] Stop fleeing after timeout or becoming adult (same as Hoglin behavior)
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.
- [x] Extend core behaviors
- [x] Support flying movement. Half supported in vanilla move behavior since we update the dragon's path navigation.
- [x] Allow liftoff for walk targets in the air.
- [x] Aggro on owner attack target. This may need to go into the idle activity technically.
- [x] Don't aggro if owner attacks owned creature. Nothing in the vanilla behaviors checks for shared owner.
- [x] Aggro on owner attacker. This may need to go into the idle activity technically.
- [x] Extend idle behaviors
- [x] Follow owner
- [x] Teleport to owner
- [x] Water avoiding strolls. ~~It's possible this is built in to vanilla but not explicitly called out.~~ Already in random stroll behavior.
- [x] Create sit behaviors.
- [x] Transition into/out of sit activity
- [x] Prevent some aggro while sitting. owner attack/attacked. Maybe still aggro within 12 blocks like existing goal?
- [x] Probably still aggro when attacked? Transitions out of sitting? Separate activity for fighting while sitting? idk, something goes here.
- [x] Any final cleanup of ai lingering in TameableDragon class.
- [x] Any final cleanup of ai from custom goals.
- ❌ ~I'm not totally sure, but there may be forge hooks to integrate in the behaviors. (based on StartAttacking behavior's setAttackTarget) So yes this has forge hooks, but they're going to be much more invasive to implement for clearing a target because it's possible for that to happen entirely in the brain which would require us to reimplement that and check every memory set for being an attack target. This event is not implemented for any other mobs outside the StartAttacking behavior, so we actually have more compatibility than them at this point.~
- Supporting Forge Events for complex systems like this is a hassle to maintain and is Forge's job, not ours. Will also make it a nightmare to support when the eventual Multi-platform system is in place for DM:L, so this will be left out.
- [x] Remove aggro from dragons once they are tamed.
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.
- [ ] Random flying stroll
- [x] Prevent liftoff if there are blocks above the dragon.
- [x] LiftOff when dragon walk path can't get them to their target. (for example being on a floating set of blocks, or is too high off the ground.)
- In the navigator, the goal is to PREFER ground based movement unless we're already flying. Brain Behaviors can decide whether we want to begin strolling in flight or not (and vice versa).
- [ ] Maybe baby following adult.
- Can use a custom memory to switch between follow owner and follow parent.
- Or Follow owner if parent is sitting, and follow parent if not. The detail will be subtle but it is there.
- [ ] Make tamed dragons flee below a health threshold so they're less likely to die. Maybe run from everything except their owner.
- ❌ ~~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.~~
- BreathWeapon behaviors will be handled when the time to work on the features in general comes.
- [ ] Breed while flying, but better.
- [x] Allow owner control when aggressive. Probably just clear the attack target. We clear attack target when telling a dragon to sit.
- [x] Set a time or range limit on aggressive behavior.
- [ ] Actual swimming behavior for some dragons?
- [x] FlyerPathNavigator needs to be adapted for this.
- [ ] Aggro on attackers of children?
- [ ] Aggro on attackers of the owner's other dragons? (like the hoglin)
- [ ] Aggro all dragons with same owner on an attacked target? (like the hoglin)
- [ ] Increase breed range because the 3 from AnimalMakeLove is kinda short. Would need to make a custom behavior since that's hardcoded into the vanilla one. Could probably just extend the class and override the tick function. Fixes #203
- [x] Better ai handling while riding. Currently, the brain still runs as normal but all of the movement is overwritten. Could be a performance gain to stop ticking it while being ridden, but also lets us do ai like attacking while being ridden if we don't, so I left it. Maybe a separate activity, but that doesn't stop the core activities from running and wrapping all that in a check for riding feels wasteful.
- [x] Make the teleport to owner code less gross. I just copied the hacked together code from before, but there are probably more elegant ways to use the RandomPos util class that I didn't feel like messing with right now.
- [ ] Redesign the original "Catch owner if falling" feature from the original mod.
- [ ] How is multiple dragons handled? (Closest to owner makes the attempt, and tells the rest to ignore?)
- [ ] If too far from owner, ignore it.
- [ ] Should sitting dragons even bother? Probably not...
- [x] While the SIT activity is active, dragons should make priority to find ground if flying, or shore if swimming to immediately respond to owner's sit command.
- [ ] If the WalkTarget is far enough away, the dragon will liftoff to get to the location faster.
- The FlyingPathNavigater favors nodes that are WALKABLE, however, so nodes will have the dragon go back down to the ground. We could solve this by modifying how the MoveToTargetSink notifies the Navigator, with an upwards offset of the WalkTarget.