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 voidclearEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect) Removes the specified effect type from the entity.static voidclearEffects(net.minecraft.world.entity.LivingEntity entity) Removes all active effects from the entity.static booleanhasEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect) Checks if the specified entity currently has the given effect.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
-
hasEffect
public static boolean hasEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect) Checks if the specified entity currently has the given effect.- Parameters:
entity- The entity to check. May be null.effect- The effect to check for. May be null.- Returns:
- true if the entity has the effect, false otherwise or if either parameter 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. The existing effect is considered sufficient if it meets either condition:- The remaining duration is greater than
expiryThreshold, OR - The amplifier is equal to or higher than the new effect AND the remaining duration is 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.
- The remaining duration is greater than
-
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- Throws:
NullPointerException- if entity, effects, or any element in effects is null
-
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.
-
clearEffect
public static void clearEffect(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect) Removes the specified effect type from the entity. The effect to remove is identified by the effect type of the given effect instance. If the entity doesn't have this effect type, this method does nothing.- Parameters:
entity- The target entity. Must not be null.effect- The effect instance containing the effect type to remove. Must not be null.- Throws:
NullPointerException- if entity or effect is null.
-
clearEffects
public static void clearEffects(net.minecraft.world.entity.LivingEntity entity) Removes all active effects from the entity.- Parameters:
entity- The target entity. Must not be null.- Throws:
NullPointerException- if entity is null.
-