Merge pull request #15 from Fretuks/fix-waxweaver-effect-during-knocked-state

Add option to clear potion effects while knocked
This commit is contained in:
2026-01-20 10:10:05 +01:00
committed by GitHub
2 changed files with 21 additions and 3 deletions
@@ -226,14 +226,27 @@ public class KnockedManager {
private static void applyKnockedEffects(Player player) {
List<? extends String> configured = Config.COMMON.knockedPotionEffects.get();
if (configured.isEmpty()) {
return;
}
Map<MobEffect, MobEffectInstance> desiredEffects = new HashMap<>();
for (String entry : configured) {
MobEffectInstance instance = parseEffect(entry);
if (instance == null) {
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();
MobEffectInstance existing = player.getEffect(effect);
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.ConfigValue<List<? extends String>> mobExecutionAllowlist;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> knockedPotionEffects;
public final ForgeConfigSpec.BooleanValue removeOtherPotionEffectsWhileKnocked;
public Common(ForgeConfigSpec.Builder builder) {
builder.push("general");
@@ -49,6 +50,10 @@ public class Config {
"Example: [\"minecraft:slowness,200,1\", \"minecraft:weakness,200,0,true,false,false\"]")
.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");
totemPreventsKnockdown = builder