Fix some small issues
This commit is contained in:
@@ -16,30 +16,19 @@ public class IntelligencePotionEvents {
|
||||
public static void onBeneficialEffectAdded(MobEffectEvent.Added event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
if (player.level().isClientSide) return;
|
||||
|
||||
MobEffectInstance inst = event.getEffectInstance();
|
||||
if (inst == null) return;
|
||||
if (inst.getEffect().getCategory() != MobEffectCategory.BENEFICIAL) return;
|
||||
|
||||
// Avoid re-scaling already huge/custom durations.
|
||||
if (inst.getDuration() > 12000) return;
|
||||
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int intel = stats.getAttributeLevel("intelligence");
|
||||
if (intel <= 0) return;
|
||||
|
||||
int baseDuration = inst.getDuration();
|
||||
|
||||
// +0.5% duration per INT, up to +50%
|
||||
double durPerPoint = 0.005d;
|
||||
double durMax = 0.5d;
|
||||
double durBonus = Math.min(intel * durPerPoint, durMax);
|
||||
int newDuration = (int) (baseDuration * (1.0d + durBonus));
|
||||
|
||||
if (newDuration <= baseDuration) return; // nothing to do
|
||||
|
||||
// Replace effect: remove original, add scaled.
|
||||
// This will fire another Added event, but newDuration > 12000 guard prevents loops.
|
||||
if (newDuration <= baseDuration) return;
|
||||
player.removeEffect(inst.getEffect());
|
||||
player.addEffect(new MobEffectInstance(
|
||||
inst.getEffect(),
|
||||
|
||||
Reference in New Issue
Block a user