Add option to clear potion effects while knocked

This commit is contained in:
2026-01-20 10:09:16 +01:00
parent e59c049566
commit 846466d1bd
2 changed files with 21 additions and 3 deletions
@@ -226,14 +226,27 @@ public class KnockedManager {
private static void applyKnockedEffects(Player player) { private static void applyKnockedEffects(Player player) {
List<? extends String> configured = Config.COMMON.knockedPotionEffects.get(); List<? extends String> configured = Config.COMMON.knockedPotionEffects.get();
if (configured.isEmpty()) { Map<MobEffect, MobEffectInstance> desiredEffects = new HashMap<>();
return;
}
for (String entry : configured) { for (String entry : configured) {
MobEffectInstance instance = parseEffect(entry); MobEffectInstance instance = parseEffect(entry);
if (instance == null) { if (instance == null) {
continue; continue;
} }
MobEffect effect = instance.getEffect();
MobEffectInstance existing = desiredEffects.get(effect);
if (existing == null || existing.getAmplifier() < instance.getAmplifier()) {
desiredEffects.put(effect, instance);
}
}
if (Config.COMMON.removeOtherPotionEffectsWhileKnocked.get()) {
for (MobEffectInstance current : new ArrayList<>(player.getActiveEffects())) {
MobEffect currentEffect = current.getEffect();
if (!desiredEffects.containsKey(currentEffect)) {
player.removeEffect(currentEffect);
}
}
}
for (MobEffectInstance instance : desiredEffects.values()) {
MobEffect effect = instance.getEffect(); MobEffect effect = instance.getEffect();
MobEffectInstance existing = player.getEffect(effect); MobEffectInstance existing = player.getEffect(effect);
if (existing == null || existing.getDuration() < 20 || existing.getAmplifier() < instance.getAmplifier()) { if (existing == null || existing.getDuration() < 20 || existing.getAmplifier() < instance.getAmplifier()) {
@@ -21,6 +21,7 @@ public class Config {
public final ForgeConfigSpec.BooleanValue totemPreventsKnockdown; public final ForgeConfigSpec.BooleanValue totemPreventsKnockdown;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> mobExecutionAllowlist; public final ForgeConfigSpec.ConfigValue<List<? extends String>> mobExecutionAllowlist;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> knockedPotionEffects; public final ForgeConfigSpec.ConfigValue<List<? extends String>> knockedPotionEffects;
public final ForgeConfigSpec.BooleanValue removeOtherPotionEffectsWhileKnocked;
public Common(ForgeConfigSpec.Builder builder) { public Common(ForgeConfigSpec.Builder builder) {
builder.push("general"); builder.push("general");
@@ -49,6 +50,10 @@ public class Config {
"Example: [\"minecraft:slowness,200,1\", \"minecraft:weakness,200,0,true,false,false\"]") "Example: [\"minecraft:slowness,200,1\", \"minecraft:weakness,200,0,true,false,false\"]")
.defineListAllowEmpty("knockedPotionEffects", List.of(), o -> o instanceof String); .defineListAllowEmpty("knockedPotionEffects", List.of(), o -> o instanceof String);
removeOtherPotionEffectsWhileKnocked = builder
.comment("If true, remove any potion effects not listed in knockedPotionEffects while knocked. Default: false.")
.define("removeOtherPotionEffectsWhileKnocked", false);
builder.pop().push("damage_behavior"); builder.pop().push("damage_behavior");
totemPreventsKnockdown = builder totemPreventsKnockdown = builder