Package net.xun.lib.common.api.util
Class MobEffectUtils
java.lang.Object
net.xun.lib.common.api.util.MobEffectUtils
Utility class for applying mob effects to entities with various strategies and conditions.
Works in conjunction with
EffectStackingStrategy to determine how effects interact.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyEffectsWithStrategy(net.minecraft.world.entity.LivingEntity entity, List<net.minecraft.world.effect.MobEffectInstance> effects, EffectStackingStrategy strategy) Applies effects to an entity using a specifiedEffectStackingStrategy.static voidapplySingleEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect, int expiryThreshold, boolean forceAdd) Applies a single effect to the entity if conditions are met or if forced.static voidapplySmartEffects(net.minecraft.world.entity.LivingEntity entity, List<net.minecraft.world.effect.MobEffectInstance> effects, int expiryThreshold, boolean forceAdd) Applies effects to an entity only if they are not sufficiently present or if forced.static booleanhasSufficientEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect, int expiryThreshold) Checks if the entity has a sufficient version of the given effect.
-
Method Details
-
applyEffectsWithStrategy
public static void applyEffectsWithStrategy(net.minecraft.world.entity.LivingEntity entity, List<net.minecraft.world.effect.MobEffectInstance> effects, EffectStackingStrategy strategy) Applies effects to an entity using a specifiedEffectStackingStrategy.- Parameters:
entity- Target entity (must not be null)effects- List of effects to apply (must not contain null elements)strategy- Application strategy fromEffectStackingStrategy
-
applySmartEffects
public static void applySmartEffects(net.minecraft.world.entity.LivingEntity entity, List<net.minecraft.world.effect.MobEffectInstance> effects, int expiryThreshold, boolean forceAdd) Applies effects to an entity only if they are not sufficiently present or if forced. Each effect is checked individually: ifforceAddis true, the effect is always applied. Otherwise, it is applied only if the entity does not already have a sufficient version.- Parameters:
entity- The target entity. Must not be null.effects- The list of effects to apply. Must not be null and must not contain null elements.expiryThreshold- The minimum remaining duration (in ticks) an existing effect must have to be considered sufficient.forceAdd- If true, applies effects regardless of existing ones.- Throws:
NullPointerException- if entity, effects, or any effect in the list is null.
-
applySingleEffect
public static void applySingleEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect, int expiryThreshold, boolean forceAdd) Applies a single effect to the entity if conditions are met or if forced.- Parameters:
entity- The target entity. Must not be null.effect- The effect to apply. Must not be null.expiryThreshold- The minimum remaining duration (in ticks) for an existing effect to be considered sufficient.forceAdd- If true, applies the effect regardless of existing ones.- Throws:
NullPointerException- if entity or effect is null.
-
hasSufficientEffect
public static boolean hasSufficientEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect, int expiryThreshold) Checks if the entity has a sufficient version of the given effect. A sufficient effect has:- Remaining duration greater than
expiryThreshold - Amplifier equal to or higher than the new effect
- Remaining duration equal to or longer than the new effect's duration
- Parameters:
entity- The entity to check. Must not be null.effect- The effect to check for. Must not be null.expiryThreshold- The threshold for remaining duration (in ticks).- Returns:
- true if the entity has a sufficient effect, false otherwise.
- Throws:
NullPointerException- if entity or effect is null.
- Remaining duration greater than
-