Component Bonuses
Components are flexible as they are, however sometimes you might want a little more flexibility by temporarily or permanently add modifiers to the values these components work with, bonuses come in play here.
Not all components currently have a bonus manager, and many will never need it due to their nature, make sure the component you wish to use supports bonuses if you need this functionality.
These bonus managers are already implemented in the component itself, and all that's left is for the modder to use them by adding modifiers (similar to how attribute modifiers work).
A minimal example using CooldownComponent which has a 50% chance to double the cooldown.
public static final UUID COOLDOWN_BONUS = UUID.fromString("6d311e6b-84b8-4c9d-b67b-f93116bbc397");
this.cooldownComponent.getBonusManager().removeBonus(COOLDOWN_BONUS);
if(entity.getRandom().nextBoolean()) {
this.cooldownComponent.getBonusManager().addBonus(COOLDOWN_BONUS, "Cooldown Bonus", BonusOperation.MUL, 2.0f);
}
Bonuses are not automatically removed! However they are stored as a map, so if you're constantly reusing the same id you can skip removing it and just overwrite the old one. If you don't always need this bonus, such as in the above example, make sure you don't forget to remove the bonus first!