mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 17:14:08 +00:00
Added modifyVisibility to FieldDef
AbilityGuard tweaks
This commit is contained in:
1 parent
fd85215592
commit
c5822023a0
4 files changed
+42
-18
No files matched your search
@@ -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")
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<FieldDef> fields, String targetLabel, FieldDef newField) {
|
||||
public static boolean insertAfter(List<FieldDef> 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<FieldDef> 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) {
|
||||
|
||||
Reference in new issue
Block a user