Patbox / ouch

Customisable, server side damage indicator! For Fabric
GNU Lesser General Public License v3.0
7 stars 1 forks source link

Add Event API to Default Configuration Modification #1

Closed FirstMegaGame4 closed 2 months ago

FirstMegaGame4 commented 2 months ago

You told me to done this via mixins, but I honestly felt it'd be better with an official api.

This PR proposes two new events: DefautDisplayEvents#APPEND_DISPLAY_LOGIC and DefaultDisplayEvents#MODIFY_DISPLAY_LOGIC.

Explanations (same as in the javadocs):

DefautDisplayEvents#APPEND_DISPLAY_LOGIC allows to append a format applied on one or more DamageType for the default configuration. Example:

DefaultDisplayEvents.APPEND_DISPLAY_LOGIC.register((lookup, logics) -> {
    logics.add(firstDamageFormat, firstDamageTypes...);
    logics.add(secondDamageFormat, secondDamageTypes...);
    logics.add(thirdDamageFormat, thirdDamageTypes...);
    return logics;
});

DefaultDisplayEvents#MODIFY_DISPLAY_LOGIC allows to modify a format applied on one or more DamageType for the default configuration. Example:

DefaultDisplayEvents.MODIFY_DISPLAY_LOGIC.register((lookup, types, format) -> {
    if (types.contains(DamageTypes.OUT_OF_WORLD)) {
        return yourModifiedFormat;
    }
    return format;
});