Skip to content

Implement tick rate options for OneShot behaviors#9946

Closed
froobynooby wants to merge 1 commit into
PaperMC:masterfrom
froobynooby:behaviour-tick-rate
Closed

Implement tick rate options for OneShot behaviors#9946
froobynooby wants to merge 1 commit into
PaperMC:masterfrom
froobynooby:behaviour-tick-rate

Conversation

@froobynooby
Copy link
Copy Markdown
Contributor

@froobynooby froobynooby commented Nov 14, 2023

TL;DR - 1.19.3 broke Paper's behaviour tick rate settings, this restores the settings' pre-1.19.3 functionality

Some entity AI behaviours were changed in 1.19.3 from having their own classes to becoming instances of the OneShot behaviour, including ValidateNearbyPoi. This caused the tick rate options to stop working for those behaviours, as the options use the class names as config keys.

This PR re-adds tick rate option support for the behaviours that were affected by the update.

All OneShot behaviours are created by a call to the BehaviorBuilder.create() method, which happens in a static method in that behaviour's class, for example ValidateNearbyPoi:

public class ValidateNearbyPoi {
    private static final int MAX_DISTANCE = 16;

    public static BehaviorControl<LivingEntity> create(Predicate<Holder<PoiType>> poiTypePredicate, MemoryModuleType<GlobalPos> poiPosModule) {
        return BehaviorBuilder.create((context) -> {
            // stuff
        }
    }
}

To get the config key for all the OneShot behaviours, I've modified the BehaviorBuilder.create() method to grab the calling class of the method from the stack trace, which is then used as the config key. In the case of the snippet above, that would be the ValidateNearbyPoi class. This maintains compatibility with configs before 1.19.3. Kind of an ugly way of doing it, not sure if I'm missing an easier way.

Fixes #9925

@froobynooby froobynooby requested a review from a team as a code owner November 14, 2023 10:51
@lynxplay
Copy link
Copy Markdown
Contributor

Near duplicate of #9946 unless I am understanding the diff wrong, just implemented on a different layer ?

@froobynooby
Copy link
Copy Markdown
Contributor Author

I could be reading #9916 wrong, but I think it is adding another setting to let you rate limit behaviours that require certain memories: jobsite, bed location, meeting point, etc. As any number of behaviours can depend on a given memory, this would rate limit a large of number of behaviours.

This PR just restores the pre-1.19.3 functionality of the existing behaviour rate limit settings, which let you rate limit individual behaviours

@lynxplay
Copy link
Copy Markdown
Contributor

Hmmm, possibly a nicer solution then. I mean the other PR just rate limits the try trigger on the pure memory rather than the consuming behaviour.

I'll have a longer look over this once home 👍 the mobile diff viewer isn't particularly great

@froobynooby
Copy link
Copy Markdown
Contributor Author

Rebased for 1.20.4

@Warriorrrr Warriorrrr moved this from Awaiting review to Waiting For Author in Paper PR Queue Mar 5, 2025
@kennytv kennytv added the pre-softspoon: never rebased Pre-hardfork pull requests that were not re-opened with the new main branch label Mar 23, 2025
@kennytv kennytv deleted the branch PaperMC:master March 23, 2025 19:15
@kennytv kennytv closed this Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pre-softspoon: never rebased Pre-hardfork pull requests that were not re-opened with the new main branch pre-softspoon

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Behavior Tick Rates aren't operating as designed

5 participants