Condition overhaul completed

This commit is contained in:
Vidal committed 2026-02-20 21:36:08 -03:00
1 parent a2e0bb50b9
commit 89e87b7656
9 files changed
+290 -292

No files matched your search

@@ -6,7 +6,6 @@ import kamkeel.npcs.controllers.data.ability.AbilityAction;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
import kamkeel.npcs.controllers.data.ability.Condition;
import kamkeel.npcs.controllers.data.ability.AbilityIconData;
import kamkeel.npcs.controllers.data.ability.IChainedAbilityFieldProvider;
import kamkeel.npcs.controllers.data.ability.UserType;
@@ -14,7 +13,6 @@ import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.builder.FieldDef;
import noppes.npcs.client.gui.builder.GuiFieldBuilder;
@@ -23,16 +21,12 @@ import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.GuiScrollWindow;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityAction;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import noppes.npcs.client.gui.util.*;
import java.util.ArrayList;
import noppes.npcs.client.gui.util.IChainedAbilityConfigCallback;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
@@ -94,7 +88,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
private List<FieldDef> fieldDefs;
private List<ChainedAbilityEntry> entries;
// private List<AbilityCondition> conditions;
private List<AbilityCondition> conditions;
// Dynamic tabs injected by field providers (e.g., "Icon")
private List<String> extraTabs = new ArrayList<>();
@@ -133,7 +127,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
this.readOnlyEntries = readOnlyEntries;
this.npcSlots = npcSlots;
this.entries = new ArrayList<>(chain.getEntries());
// this.conditions = new ArrayList<>(chain.getConditions());
this.conditions = new ArrayList<>(chain.getConditions());
buildFieldDefs();
@@ -429,50 +423,31 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
}
private int renderConditions(GuiScrollWindow sw, int y, int labelCounter) {
// y += 3;
// sw.addLabel(new GuiNpcLabel(labelCounter, "ability.conditions", L_LABEL_X, y + 2, 0xFFFF55));
// y += 15;
//
// for (int i = 0; i < conditions.size() && i < 3; i++) {
// Condition cond = conditions.get(i);
// String condName = getConditionDisplayName(cond);
// sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE, L_LABEL_X, y, 140, 20, condName));
// sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE + 1, L_LABEL_X + 145, y, 40, 20, "gui.edit"));
// sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE + 2, L_LABEL_X + 190, y, 20, 20, "X"));
// y += 22;
// }
//
// if (conditions.size() < 3) {
// sw.addButton(new GuiNpcButton(BTN_ADD_COND, L_LABEL_X, y, 50, 20, "gui.add"));
// y += ROW_H;
// }
y += 3;
sw.addLabel(new GuiNpcLabel(labelCounter, "ability.conditions", L_LABEL_X, y + 2, 0xFFFF55));
y += 15;
for (int i = 0; i < conditions.size() && i < 3; i++) {
AbilityCondition cond = conditions.get(i);
String condName = getConditionDisplayName(cond);
sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE, L_LABEL_X, y, 140, 20, condName));
sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE + 1, L_LABEL_X + 145, y, 40, 20, "gui.edit"));
sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE + 2, L_LABEL_X + 190, y, 20, 20, "X"));
y += 22;
}
if (conditions.size() < 3) {
sw.addButton(new GuiNpcButton(BTN_ADD_COND, L_LABEL_X, y, 50, 20, "gui.add"));
y += ROW_H;
}
return y;
}
private String getConditionDisplayName(Condition cond) {
private String getConditionDisplayName(AbilityCondition cond) {
if (cond == null) return "None";
String typeId = cond.getTypeId();
switch (typeId) {
case "hp_above":
return StatCollector.translateToLocal("condition.hp_above") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
case "hp_below":
return StatCollector.translateToLocal("condition.hp_below") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
case "target_hp_above":
return StatCollector.translateToLocal("condition.target_hp_above") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
case "target_hp_below":
return StatCollector.translateToLocal("condition.target_hp_below") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
case "hit_count":
Condition.ConditionHitCount hc = (Condition.ConditionHitCount) cond;
return StatCollector.translateToLocal("condition.hit_count") + ": " + hc.getRequiredHits() + "/" + hc.getWithinTicks() + "t";
default:
return typeId;
}
}
private float getConditionThreshold(Condition cond) {
NBTTagCompound nbt = cond.writeNBT();
return nbt.hasKey("threshold") ? nbt.getFloat("threshold") : 0.5f;
String name = cond.getName();
return StatCollector.translateToLocal(name);
}
// ═══════════════════════════════════════════════════════════════════════════
@@ -623,29 +598,29 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
}
private boolean handleConditionButton(int id) {
// if (id >= COND_BASE && id < COND_END) {
// int condIndex = (id - COND_BASE) / COND_STRIDE;
// int action = (id - COND_BASE) % COND_STRIDE;
// if (action == 0 || action == 1) {
// if (condIndex < conditions.size()) {
// editingConditionIndex = condIndex;
// setSubGui(new SubGuiConditionEdit(conditions.get(condIndex)));
// }
// } else if (action == 2) {
// if (condIndex < conditions.size()) {
// conditions.remove(condIndex);
// initGui();
// }
// }
// return true;
// }
// if (id == BTN_ADD_COND) {
// if (conditions.size() < 3) {
// editingConditionIndex = conditions.size();
// setSubGui(new SubGuiConditionEdit(null));
// }
// return true;
// }
if (id >= COND_BASE && id < COND_END) {
int condIndex = (id - COND_BASE) / COND_STRIDE;
int action = (id - COND_BASE) % COND_STRIDE;
if (action == 0 || action == 1) {
if (condIndex < conditions.size()) {
editingConditionIndex = condIndex;
setSubGui(new SubGuiConditionEdit(conditions.get(condIndex)));
}
} else if (action == 2) {
if (condIndex < conditions.size()) {
conditions.remove(condIndex);
initGui();
}
}
return true;
}
if (id == BTN_ADD_COND) {
if (conditions.size() < 3) {
editingConditionIndex = conditions.size();
setSubGui(new SubGuiConditionEdit(null));
}
return true;
}
return false;
}
@@ -850,14 +825,14 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
}
private void handleConditionEditClosed(SubGuiConditionEdit gui) {
// Condition result = gui.getResult();
// if (result != null && editingConditionIndex >= 0) {
// if (editingConditionIndex < conditions.size()) {
// conditions.set(editingConditionIndex, result);
// } else {
// conditions.add(result);
// }
// }
AbilityCondition result = gui.getResult();
if (result != null && editingConditionIndex >= 0) {
if (editingConditionIndex < conditions.size()) {
conditions.set(editingConditionIndex, result);
} else {
conditions.add(result);
}
}
editingConditionIndex = -1;
}
@@ -895,10 +870,10 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
}
// Conditions
// chain.getConditions().clear();
// for (Condition c : conditions) {
// chain.getConditions().add(c);
// }
chain.getConditions().clear();
for (AbilityCondition c : conditions) {
chain.getConditions().add(c);
}
// Remove consumed NPC slots (descending order to preserve indices)
if (npcSlots != null && !consumedSlotIndices.isEmpty()) {