41 lines
1.8 KiB
Java
41 lines
1.8 KiB
Java
package net.fretux.ascend.api;
|
|
|
|
import net.fretux.ascend.api.event.PassiveAgilityEvent;
|
|
import net.fretux.ascend.player.AttributeScaling;
|
|
import net.fretux.ascend.player.PlayerStatsProvider;
|
|
import net.fretux.ascend.player.StatEffects;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
/** Public entry point for Ascend's passive Agility integration. */
|
|
public final class PassiveAgilityApi {
|
|
private PassiveAgilityApi() {}
|
|
|
|
/** Collects all passive Agility contributions registered for this player. */
|
|
public static int getPassiveAgility(Player player, int investedAgility) {
|
|
PassiveAgilityEvent event = new PassiveAgilityEvent(player, investedAgility);
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
return event.getPassiveAgility();
|
|
}
|
|
|
|
/** Returns invested and passive Agility, saturating safely at the integer limit. */
|
|
public static int getTotalAgility(Player player, int investedAgility) {
|
|
long total = (long) Math.max(0, investedAgility) + getPassiveAgility(player, investedAgility);
|
|
return (int) Math.min(Integer.MAX_VALUE, total);
|
|
}
|
|
|
|
/**
|
|
* Returns Agility normalized against the normal investment cap. Values may
|
|
* exceed {@code 1.0} when integrations supply passive points above that cap.
|
|
*/
|
|
public static double getNormalizedAgility(Player player, int investedAgility) {
|
|
return AttributeScaling.getExtendedNormalizedAttributeValue(getTotalAgility(player, investedAgility));
|
|
}
|
|
|
|
/** Recalculates the player's movement-speed modifier after passive Agility changes. */
|
|
public static void refresh(Player player) {
|
|
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats ->
|
|
StatEffects.applyAgility(player, stats.getAttributeLevel("agility")));
|
|
}
|
|
}
|