diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java index 86a5e3794..1939304a9 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -450,17 +450,6 @@ public abstract class Ability implements IAbility { this::getActiveAnimationName, this::setActiveAnimationName) .tab("Effects")); - if (this instanceof AbilityGuard) { - defs.add(FieldDef.animSubGui("ability.counterAnimation", - () -> ((AbilityGuard) this).getCounterAnimationId(), - (id) -> ((AbilityGuard) this).setCounterAnimationId(id), - () -> ((AbilityGuard) this).getCounterAnimationName(), - (name) -> ((AbilityGuard) this).setCounterAnimationName(name)) - .tab("Effects") - .visibleWhen(() -> ((AbilityGuard) this).canCounter()) - ); - } - TelegraphType tType = getTelegraphType(); if (tType != null && tType != TelegraphType.NONE) { defs.add(FieldDef.section("ability.section.telegraph").tab("Effects") diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java index dcf43d530..eab84d138 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java @@ -58,7 +58,7 @@ public class AbilityGuard extends Ability implements IAbilityGuard { // No telegraph for guard - it's a defensive stance this.telegraphType = TelegraphType.NONE; this.showTelegraph = false; - this.windUpSound = "random.anvil_use"; + this.activeSound = "random.anvil_use"; this.allowedBy = UserType.BOTH; this.activeAnimationName = "Ability_Guard_Active"; @@ -128,11 +128,12 @@ public class AbilityGuard extends Ability implements IAbilityGuard { caster.setHealth(newHealth); - if (!canCounter || !counterEligible || counterTriggered) return; - if (!isDirectHit(source)) return; - - counterTriggered = true; - // Counter will be performed in onActiveTick - don't self-interrupt + if (!canCounter || !counterEligible || counterTriggered || !isDirectHit(source)) { + caster.setHealth(newHealth); + } else { + caster.setHealth(ValueUtil.clamp(caster.getHealth() + damage, 0, caster.getMaxHealth())); + counterTriggered = true; + } } private boolean isDirectHit(DamageSource source) { @@ -360,5 +361,18 @@ public class AbilityGuard extends Ability implements IAbilityGuard { AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects) )); + + FieldDef.insertAfter(defs, "ability.activeSound", + FieldDef.soundSubGui("ability.counterSound", this::getCounterSound, this::setCounterSound) + .tab("Effects").visibleWhen(this::canCounter)); + + FieldDef.insertAfter(defs, "ability.activeAnimation", + FieldDef.animSubGui("ability.counterAnimation", + this::getCounterAnimationId, this::setCounterAnimationId, + this::getCounterAnimationName, this::setCounterAnimationName) + .tab("Effects").visibleWhen(this::canCounter)); + + FieldDef.modifyVisibility(defs, "ability.windUpAnimation", () -> false); + FieldDef.modifyVisibility(defs, "ability.windUpSound", () -> false); } } diff --git a/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java b/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java index 6d9ee58ec..e013f4cb2 100644 --- a/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java +++ b/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java @@ -9,6 +9,7 @@ import noppes.npcs.client.gui.select.GuiAnimationSelection; import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.SubGuiInterface; +import java.util.List; import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Supplier; @@ -329,7 +330,7 @@ public class FieldDef { * @param newField The field to insert * @return true if the target was found and the field was inserted */ - public static boolean insertAfter(java.util.List fields, String targetLabel, FieldDef newField) { + public static boolean insertAfter(List fields, String targetLabel, FieldDef newField) { for (int i = 0; i < fields.size(); i++) { if (matchesLabel(fields.get(i), targetLabel)) { fields.add(i + 1, newField); @@ -339,6 +340,25 @@ public class FieldDef { return false; } + /** + * Modify the visibility condition of a field. + * Searches top-level labels and ROW children. + * + * @param fields The field list to modify + * @param targetLabel The label of the field to modify + * @param condition The condition to replace + * @return true if the target was found and the condition was modified + */ + public static boolean modifyVisibility(List fields, String targetLabel, BooleanSupplier condition) { + for (FieldDef field : fields) { + if (matchesLabel(field, targetLabel)) { + field.visibleWhen(condition); + return true; + } + } + return false; + } + private static boolean matchesLabel(FieldDef def, String targetLabel) { if (targetLabel.equals(def.label)) return true; if (def.type == FieldType.ROW) { diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index afa79dad0..ea433dc7e 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1644,6 +1644,7 @@ ability.conditions=Conditions # Effects Tab ability.windUpSound=Wind Up Sound ability.activeSound=Active Sound +ability.counterSound=Counter Sound ability.windUpAnimation=Wind Up Animation ability.activeAnimation=Active Animation ability.counterAnimation=Counter Animation