mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-27 02:42:55 +00:00
Player Abilities
This commit is contained in:
1 parent
601b0d721e
commit
1b8ad4dd90
92 files changed
+2610
-1025
No files matched your search
@@ -340,7 +340,6 @@ public class CustomNpcs {
|
||||
new SpawnController();
|
||||
new LinkedNpcController();
|
||||
new AnimationController();
|
||||
new AbilityController();
|
||||
AbilityController.Instance.load();
|
||||
TelegraphController.init();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilitySlot;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
@@ -35,9 +36,9 @@ public class DataAbilities {
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* List of abilities this NPC can use
|
||||
* List of ability slots this NPC can use (inline or reference).
|
||||
*/
|
||||
private List<Ability> abilities = new ArrayList<>();
|
||||
private List<AbilitySlot> abilitySlots = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Whether the ability system is enabled for this NPC
|
||||
@@ -294,7 +295,7 @@ public class DataAbilities {
|
||||
* Check if an ability can be selected right now.
|
||||
*/
|
||||
public boolean canSelectAbility() {
|
||||
if (!enabled || abilities.isEmpty()) {
|
||||
if (!enabled || abilitySlots.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
@@ -314,7 +315,7 @@ public class DataAbilities {
|
||||
List<Ability> eligible = new ArrayList<>();
|
||||
int totalWeight = 0;
|
||||
|
||||
for (Ability ability : abilities) {
|
||||
for (Ability ability : getAbilities()) {
|
||||
if (isAbilityEligible(ability, target)) {
|
||||
eligible.add(ability);
|
||||
totalWeight += ability.getWeight();
|
||||
@@ -636,24 +637,24 @@ public class DataAbilities {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a preset ability on this NPC.
|
||||
* Execute an ability on this NPC by key (built-in name or custom UUID).
|
||||
* The NPC does NOT need to have this ability assigned.
|
||||
*
|
||||
* @param presetName The name of the saved ability preset
|
||||
* @param key The ability key (built-in name or custom UUID)
|
||||
* @param target The target entity (can be null for self-targeted abilities)
|
||||
* @return true if the ability was started successfully
|
||||
*/
|
||||
public boolean executePresetAbility(String presetName, EntityLivingBase target) {
|
||||
if (presetName == null || presetName.isEmpty() || npc.worldObj.isRemote) {
|
||||
public boolean executeAbility(String key, EntityLivingBase target) {
|
||||
if (key == null || key.isEmpty() || npc.worldObj.isRemote) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Ability preset = AbilityController.Instance.getSavedAbility(presetName);
|
||||
if (preset == null) {
|
||||
Ability resolved = AbilityController.Instance.resolveAbility(key);
|
||||
if (resolved == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return forceStartAbility(preset, target);
|
||||
return forceStartAbility(resolved, target);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -715,8 +716,8 @@ public class DataAbilities {
|
||||
// Roll cooldown so NPC doesn't immediately attack after reset
|
||||
rollCooldown();
|
||||
|
||||
// Reset execution state on all abilities
|
||||
for (Ability ability : abilities) {
|
||||
// Reset execution state on all resolved abilities
|
||||
for (Ability ability : getAbilities()) {
|
||||
ability.reset();
|
||||
}
|
||||
}
|
||||
@@ -737,39 +738,79 @@ public class DataAbilities {
|
||||
// ABILITY LIST MANAGEMENT
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Get resolved abilities from all slots, filtering out broken references.
|
||||
*/
|
||||
public List<Ability> getAbilities() {
|
||||
return abilities;
|
||||
List<Ability> resolved = new ArrayList<>();
|
||||
for (AbilitySlot slot : abilitySlots) {
|
||||
Ability a = slot.getAbility();
|
||||
if (a != null) {
|
||||
resolved.add(a);
|
||||
}
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
/** Get the raw slot list (for GUI access). */
|
||||
public List<AbilitySlot> getAbilitySlots() {
|
||||
return abilitySlots;
|
||||
}
|
||||
|
||||
/** Add an inline ability. */
|
||||
public void addAbility(Ability ability) {
|
||||
abilities.add(ability);
|
||||
abilitySlots.add(AbilitySlot.inline(ability));
|
||||
}
|
||||
|
||||
/** Add a reference ability by key (built-in name or custom UUID). */
|
||||
public void addAbilityReference(String key) {
|
||||
abilitySlots.add(AbilitySlot.reference(key));
|
||||
}
|
||||
|
||||
public void removeAbility(int index) {
|
||||
if (index >= 0 && index < abilities.size()) {
|
||||
abilities.remove(index);
|
||||
if (index >= 0 && index < abilitySlots.size()) {
|
||||
abilitySlots.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAbility(String id) {
|
||||
abilities.removeIf(a -> a.getId().equals(id));
|
||||
abilitySlots.removeIf(slot -> {
|
||||
if (slot.isReference()) {
|
||||
return slot.getReferenceId().equals(id);
|
||||
}
|
||||
Ability a = slot.getAbility();
|
||||
return a != null && a.getId().equals(id);
|
||||
});
|
||||
}
|
||||
|
||||
public Ability getAbility(String id) {
|
||||
for (Ability ability : abilities) {
|
||||
if (ability.getId().equals(id)) {
|
||||
return ability;
|
||||
for (AbilitySlot slot : abilitySlots) {
|
||||
Ability a = slot.getAbility();
|
||||
if (a != null && a.getId().equals(id)) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Check if a slot at a given index is a reference. */
|
||||
public boolean isSlotReference(int index) {
|
||||
if (index < 0 || index >= abilitySlots.size()) return false;
|
||||
return abilitySlots.get(index).isReference();
|
||||
}
|
||||
|
||||
/** Convert a reference slot to inline. Returns false if resolution fails. */
|
||||
public boolean convertToInline(int index) {
|
||||
if (index < 0 || index >= abilitySlots.size()) return false;
|
||||
return abilitySlots.get(index).convertToInline();
|
||||
}
|
||||
|
||||
public void clearAbilities() {
|
||||
abilities.clear();
|
||||
abilitySlots.clear();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return abilities.isEmpty();
|
||||
return abilitySlots.isEmpty();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -920,8 +961,8 @@ public class DataAbilities {
|
||||
compound.setInteger("AbilityMaxCooldown", maxCooldown);
|
||||
|
||||
NBTTagList abilityList = new NBTTagList();
|
||||
for (Ability ability : abilities) {
|
||||
abilityList.appendTag(ability.writeNBT());
|
||||
for (AbilitySlot slot : abilitySlots) {
|
||||
abilityList.appendTag(slot.writeNBT());
|
||||
}
|
||||
compound.setTag("Abilities", abilityList);
|
||||
|
||||
@@ -930,28 +971,16 @@ public class DataAbilities {
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
enabled = compound.getBoolean("AbilitiesEnabled");
|
||||
minCooldown = compound.getInteger("AbilityMinCooldown");
|
||||
maxCooldown = compound.getInteger("AbilityMaxCooldown");
|
||||
|
||||
// Support old globalCooldown for backwards compatibility
|
||||
if (compound.hasKey("AbilityMinCooldown")) {
|
||||
minCooldown = compound.getInteger("AbilityMinCooldown");
|
||||
maxCooldown = compound.getInteger("AbilityMaxCooldown");
|
||||
} else if (compound.hasKey("AbilityGlobalCooldown")) {
|
||||
// Migrate old single cooldown to min/max range
|
||||
int oldCooldown = compound.getInteger("AbilityGlobalCooldown");
|
||||
minCooldown = oldCooldown;
|
||||
maxCooldown = oldCooldown * 2; // Give some range
|
||||
} else {
|
||||
minCooldown = 20;
|
||||
maxCooldown = 60;
|
||||
}
|
||||
|
||||
abilities.clear();
|
||||
abilitySlots.clear();
|
||||
NBTTagList abilityList = compound.getTagList("Abilities", 10);
|
||||
for (int i = 0; i < abilityList.tagCount(); i++) {
|
||||
NBTTagCompound abilityNBT = abilityList.getCompoundTagAt(i);
|
||||
Ability ability = AbilityController.Instance.fromNBT(abilityNBT);
|
||||
if (ability != null) {
|
||||
abilities.add(ability);
|
||||
AbilitySlot slot = AbilitySlot.fromNBT(abilityNBT);
|
||||
if (slot != null) {
|
||||
abilitySlots.add(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ import noppes.npcs.scripted.event.RecipeScriptEvent;
|
||||
import noppes.npcs.scripted.event.player.CustomGuiEvent;
|
||||
import noppes.npcs.scripted.event.player.DialogEvent;
|
||||
import noppes.npcs.scripted.event.player.FactionEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerEvent.ChatEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerEvent.ContainerOpen;
|
||||
@@ -692,6 +693,11 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityHit(PlayerDataScript handler, PlayerAbilityEvent.HitEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_HIT, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerChangeDim(PlayerDataScript handler, IPlayer player, int fromDim, int toDim) {
|
||||
PlayerEvent.ChangedDimension event = new PlayerEvent.ChangedDimension(player, fromDim, toDim);
|
||||
handler.callScript(EnumScriptType.CHANGED_DIM, event);
|
||||
|
||||
@@ -785,16 +785,18 @@ public class NoppesUtilServer {
|
||||
sendScrollData(player, map, EnumScrollData.ABILITY_TYPES);
|
||||
}
|
||||
|
||||
public static void sendSavedAbilitiesData(EntityPlayerMP player) {
|
||||
public static void sendCustomAbilitiesData(EntityPlayerMP player) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
kamkeel.npcs.controllers.data.ability.AbilityController controller = kamkeel.npcs.controllers.data.ability.AbilityController.Instance;
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String name : controller.getSavedAbilityNames()) {
|
||||
map.put(name, index++);
|
||||
for (String uuid : controller.getCustomAbilityIds()) {
|
||||
String name = controller.getCustomAbilityName(uuid);
|
||||
if (name == null || name.isEmpty()) name = uuid;
|
||||
map.put(name + "\t" + uuid, index++);
|
||||
}
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.ABILITIES);
|
||||
sendScrollData(player, map, EnumScrollData.CUSTOM_ABILITIES);
|
||||
}
|
||||
|
||||
public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException {
|
||||
|
||||
@@ -97,6 +97,13 @@ public class ScriptPlayerEventHandler {
|
||||
if (PlayerDataController.Instance != null) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
playerData.actionManager.tick();
|
||||
playerData.abilityData.tick(player);
|
||||
|
||||
// Lock player movement during ability phases that require it
|
||||
if (playerData.abilityData.isMovementLocked()) {
|
||||
player.motionX = 0;
|
||||
player.motionZ = 0;
|
||||
}
|
||||
|
||||
if (playerData.updateClient) {
|
||||
SyncController.syncPlayerData((EntityPlayerMP) player, true);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
getTextField(18).setVisible(dialog.renderGradual);
|
||||
getLabel(18).enabled = dialog.renderGradual;
|
||||
|
||||
addTextField(new GuiNpcTextField(19, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch)));
|
||||
addTextField(new GuiNpcTextField(19, this, guiLeft + 125, y += 22, 40, 20, "" + dialog.textPitch));
|
||||
addLabel(new GuiNpcLabel(19, "dialog.textPitch", guiLeft + 4, y + 5));
|
||||
getTextField(19).floatsOnly = true;
|
||||
getTextField(19).setVisible(dialog.renderGradual);
|
||||
@@ -110,48 +110,48 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
addButton(new GuiNpcButton(24, guiLeft + 192, y, 50, 20, new String[]{"display.bottom", "display.top"}, dialog.alignment));
|
||||
addLabel(new GuiNpcLabel(27, "display.alignment", guiLeft + 126, y + 5));
|
||||
|
||||
addTextField(new GuiNpcTextField(11, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth)));
|
||||
addTextField(new GuiNpcTextField(12, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight)));
|
||||
addTextField(new GuiNpcTextField(11, this, guiLeft + 120, y += 25, 40, 20, "" + dialog.textWidth));
|
||||
addTextField(new GuiNpcTextField(12, this, guiLeft + 165, y, 40, 20, "" + dialog.textHeight));
|
||||
addLabel(new GuiNpcLabel(12, "gui.widthHeight", guiLeft + 4, y + 5));
|
||||
getTextField(11).integersOnly = true;
|
||||
getTextField(11).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
getTextField(12).integersOnly = true;
|
||||
getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
addTextField(new GuiNpcTextField(13, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX)));
|
||||
addTextField(new GuiNpcTextField(14, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY)));
|
||||
addTextField(new GuiNpcTextField(13, this, guiLeft + 120, y += 25, 40, 20, "" + dialog.textOffsetX));
|
||||
addTextField(new GuiNpcTextField(14, this, guiLeft + 165, y, 40, 20, "" + dialog.textOffsetY));
|
||||
addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5));
|
||||
getTextField(13).integersOnly = true;
|
||||
getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
getTextField(14).integersOnly = true;
|
||||
getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX)));
|
||||
addTextField(new GuiNpcTextField(16, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY)));
|
||||
addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 25, 40, 20, "" + dialog.titleOffsetX));
|
||||
addTextField(new GuiNpcTextField(16, this, guiLeft + 165, y, 40, 20, "" + dialog.titleOffsetY));
|
||||
addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5));
|
||||
getTextField(15).integersOnly = true;
|
||||
getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
getTextField(16).integersOnly = true;
|
||||
getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
addTextField(new GuiNpcTextField(17, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX)));
|
||||
addTextField(new GuiNpcTextField(18, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY)));
|
||||
addTextField(new GuiNpcTextField(17, this, guiLeft + 120, y += 25, 40, 20, "" + dialog.optionOffsetX));
|
||||
addTextField(new GuiNpcTextField(18, this, guiLeft + 165, y, 40, 20, "" + dialog.optionOffsetY));
|
||||
addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5));
|
||||
getTextField(17).integersOnly = true;
|
||||
getTextField(17).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
getTextField(18).integersOnly = true;
|
||||
getTextField(18).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
addTextField(new GuiNpcTextField(19, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX)));
|
||||
addTextField(new GuiNpcTextField(20, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY)));
|
||||
addTextField(new GuiNpcTextField(19, this, guiLeft + 120, y += 25, 40, 20, "" + dialog.optionSpaceX));
|
||||
addTextField(new GuiNpcTextField(20, this, guiLeft + 165, y, 40, 20, "" + dialog.optionSpaceY));
|
||||
addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5));
|
||||
getTextField(19).integersOnly = true;
|
||||
getTextField(19).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
getTextField(20).integersOnly = true;
|
||||
getTextField(20).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
addTextField(new GuiNpcTextField(21, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcOffsetX)));
|
||||
addTextField(new GuiNpcTextField(22, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.npcOffsetY)));
|
||||
addTextField(new GuiNpcTextField(21, this, guiLeft + 120, y += 25, 40, 20, "" + dialog.npcOffsetX));
|
||||
addTextField(new GuiNpcTextField(22, this, guiLeft + 165, y, 40, 20, "" + dialog.npcOffsetY));
|
||||
addLabel(new GuiNpcLabel(25, "dialog.npcOffset", guiLeft + 4, y + 5));
|
||||
getTextField(21).integersOnly = true;
|
||||
getTextField(21).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
@@ -161,7 +161,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
getTextField(22).setVisible(!dialog.hideNPC);
|
||||
getLabel(25).enabled = !dialog.hideNPC;
|
||||
|
||||
addTextField(new GuiNpcTextField(23, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcScale)));
|
||||
addTextField(new GuiNpcTextField(23, this, guiLeft + 120, y += 25, 40, 20, "" + dialog.npcScale));
|
||||
addLabel(new GuiNpcLabel(26, "dialog.npcScale", guiLeft + 4, y + 5));
|
||||
getTextField(23).floatsOnly = true;
|
||||
getTextField(23).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
@@ -182,30 +182,30 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
DialogImage dialogImage = getSelectedImage();
|
||||
addButton(new GuiNpcButton(2, guiLeft + xSize + 24, guiTop + 5, 20, 20, "-"));
|
||||
|
||||
addTextField(new GuiNpcTextField(10, this, guiLeft + 17, y += 25, 30, 20, String.valueOf(dialogImage.id)));
|
||||
addTextField(new GuiNpcTextField(10, this, guiLeft + 17, y += 25, 30, 20, "" + dialogImage.id));
|
||||
addTextField(new GuiNpcTextField(11, this, guiLeft + 92, y, 150, 20, dialogImage.texture));
|
||||
addLabel(new GuiNpcLabel(10, "gui.id", guiLeft + 4, y + 5));
|
||||
addLabel(new GuiNpcLabel(11, "display.texture", guiLeft + 50, y + 5));
|
||||
getTextField(10).integersOnly = true;
|
||||
|
||||
addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.x)));
|
||||
addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.y)));
|
||||
addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, "" + dialogImage.x));
|
||||
addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, "" + dialogImage.y));
|
||||
addLabel(new GuiNpcLabel(12, "gui.position", guiLeft + 4, y + 5));
|
||||
getTextField(12).integersOnly = true;
|
||||
getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
getTextField(13).integersOnly = true;
|
||||
getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.width)));
|
||||
addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.height)));
|
||||
addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, "" + dialogImage.width));
|
||||
addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, "" + dialogImage.height));
|
||||
addLabel(new GuiNpcLabel(13, "gui.widthHeight", guiLeft + 4, y + 5));
|
||||
getTextField(14).integersOnly = true;
|
||||
getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
getTextField(15).integersOnly = true;
|
||||
getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.textureX)));
|
||||
addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.textureY)));
|
||||
addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, "" + dialogImage.textureX));
|
||||
addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, "" + dialogImage.textureY));
|
||||
addLabel(new GuiNpcLabel(14, "dialog.textureOffset", guiLeft + 4, y + 5));
|
||||
getTextField(16).integersOnly = true;
|
||||
getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
@@ -229,9 +229,9 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
getButton(19).setVisible(dialogImage.imageType == 2);
|
||||
getLabel(16).enabled = dialogImage.imageType == 2;
|
||||
|
||||
addTextField(new GuiNpcTextField(20, this, guiLeft + 33, y += 25, 30, 20, String.valueOf(dialogImage.scale)));
|
||||
addTextField(new GuiNpcTextField(21, this, guiLeft + 102, y, 30, 20, String.valueOf(dialogImage.alpha)));
|
||||
addTextField(new GuiNpcTextField(22, this, guiLeft + 183, y, 45, 20, String.valueOf(dialogImage.rotation)));
|
||||
addTextField(new GuiNpcTextField(20, this, guiLeft + 33, y += 25, 30, 20, "" + dialogImage.scale));
|
||||
addTextField(new GuiNpcTextField(21, this, guiLeft + 102, y, 30, 20, "" + dialogImage.alpha));
|
||||
addTextField(new GuiNpcTextField(22, this, guiLeft + 183, y, 45, 20, "" + dialogImage.rotation));
|
||||
addLabel(new GuiNpcLabel(17, "model.scale", guiLeft + 4, y + 5));
|
||||
addLabel(new GuiNpcLabel(18, "display.alpha", guiLeft + 72, y + 5));
|
||||
addLabel(new GuiNpcLabel(19, "movement.rotation", guiLeft + 140, y + 5));
|
||||
@@ -306,13 +306,13 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
Collections.sort(ids);
|
||||
ArrayList<String> strings = new ArrayList<>();
|
||||
for (int i : ids) {
|
||||
strings.add(String.valueOf(i));
|
||||
strings.add("" + i);
|
||||
}
|
||||
imageScroll.setUnsortedList(strings);
|
||||
|
||||
if (changedId != -1) {
|
||||
selected = imageScroll.getList().indexOf(String.valueOf(changedId));
|
||||
imageScroll.setSelected(String.valueOf(changedId));
|
||||
selected = imageScroll.getList().indexOf("" + changedId);
|
||||
imageScroll.setSelected("" + changedId);
|
||||
changedId = -1;
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
|
||||
dialog.dialogImages.put(addId, new DialogImage(addId));
|
||||
updateScrollData();
|
||||
selected = imageScroll.getList().indexOf(String.valueOf(addId));
|
||||
selected = imageScroll.getList().indexOf("" + addId);
|
||||
}
|
||||
if (button.id == 2) {
|
||||
if (imageScroll.getSelected() != null) {
|
||||
@@ -598,8 +598,8 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
}
|
||||
|
||||
if (textfield.id == 10) {
|
||||
if (imageScroll.getList().contains(String.valueOf(textfield.getInteger()))) {
|
||||
textfield.setText(String.valueOf(dialogImage.id));
|
||||
if (imageScroll.getList().contains("" + textfield.getInteger())) {
|
||||
textfield.setText("" + dialogImage.id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SubGuiNpcPartyOptions extends SubGuiInterface implements ITextfield
|
||||
y += 23;
|
||||
//min party size - number field
|
||||
GuiNpcTextField minField = new GuiNpcTextField(21, this, guiLeft + 60, guiTop + 10 + y,
|
||||
30, 20, String.valueOf(options.minPartySize));
|
||||
30, 20, "" + options.minPartySize);
|
||||
minField.integersOnly = true;
|
||||
minField.setMinMaxDefault(1, Integer.MAX_VALUE, 1);
|
||||
addTextField(minField);
|
||||
@@ -79,7 +79,7 @@ public class SubGuiNpcPartyOptions extends SubGuiInterface implements ITextfield
|
||||
|
||||
//max party size - number field
|
||||
GuiNpcTextField maxField = new GuiNpcTextField(20, this, guiLeft + 160, guiTop + 10 + y,
|
||||
30, 20, String.valueOf(options.maxPartySize));
|
||||
30, 20, "" + options.maxPartySize);
|
||||
maxField.integersOnly = true;
|
||||
maxField.setMinMaxDefault(1, Integer.MAX_VALUE, 4);
|
||||
addTextField(maxField);
|
||||
|
||||
@@ -36,9 +36,9 @@ public class SubGuiSpawningOptions extends SubGuiInterface implements ITextfield
|
||||
addButton(new GuiNpcButtonYesNo(13, guiLeft + 120, y += 22, data.airSpawning));
|
||||
addLabel(new GuiNpcLabel(13, "spawning.airSpawning", guiLeft + 4, y + 5));
|
||||
|
||||
addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 22, 40, 20, String.valueOf(data.spawnHeightMin)));
|
||||
addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 22, 40, 20, "" + data.spawnHeightMin));
|
||||
addLabel(new GuiNpcLabel(14, "spawning.minHeight", guiLeft + 4, y + 5));
|
||||
addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 22, 40, 20, String.valueOf(data.spawnHeightMax)));
|
||||
addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 22, 40, 20, "" + data.spawnHeightMax));
|
||||
addLabel(new GuiNpcLabel(15, "spawning.maxHeight", guiLeft + 4, y + 5));
|
||||
getTextField(14).integersOnly = true;
|
||||
getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilitySlot;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
|
||||
@@ -46,8 +47,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
// Display name to typeId mapping for the available types scroll
|
||||
private final HashMap<String, String> displayNameToTypeId = new HashMap<>();
|
||||
|
||||
// NPC's current abilities
|
||||
private final List<Ability> npcAbilities = new ArrayList<>();
|
||||
// NPC's current ability slots
|
||||
private final List<AbilitySlot> npcSlots = new ArrayList<>();
|
||||
|
||||
// Settings
|
||||
private boolean abilitiesEnabled = false;
|
||||
@@ -75,13 +76,13 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
// Cooldown range: Min Cooldown and Max Cooldown (spaced apart more)
|
||||
addLabel(new GuiNpcLabel(101, "ability.minCooldown", guiLeft + 115, y + 5));
|
||||
GuiNpcTextField minField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 165, y, 40, 20, String.valueOf(minCooldown));
|
||||
GuiNpcTextField minField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 165, y, 40, 20, "" + minCooldown);
|
||||
minField.setIntegersOnly();
|
||||
minField.setMinMaxDefault(0, 10000, 20);
|
||||
addTextField(minField);
|
||||
|
||||
addLabel(new GuiNpcLabel(102, "ability.maxCooldown", guiLeft + 260, y + 5));
|
||||
GuiNpcTextField maxField = new GuiNpcTextField(102, this, fontRendererObj, guiLeft + 310, y, 40, 20, String.valueOf(maxCooldown));
|
||||
GuiNpcTextField maxField = new GuiNpcTextField(102, this, fontRendererObj, guiLeft + 310, y, 40, 20, "" + maxCooldown);
|
||||
maxField.setIntegersOnly();
|
||||
maxField.setMinMaxDefault(0, 10000, 60);
|
||||
addTextField(maxField);
|
||||
@@ -124,8 +125,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
addButton(new GuiNpcButton(75, centerX, y + 90, 40, 20, "gui.load"));
|
||||
|
||||
// On/Off toggle for selected ability (under Load button)
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
Ability selectedAbility = npcAbilities.get(selectedAbilityIndex);
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
Ability selectedAbility = npcSlots.get(selectedAbilityIndex).getAbility();
|
||||
GuiNpcButton toggleBtn = new GuiNpcButton(77, centerX, y + 112, 40, 20,
|
||||
new String[]{"gui.off", "gui.on"}, selectedAbility.isEnabled() ? 1 : 0);
|
||||
addButton(toggleBtn);
|
||||
@@ -139,7 +140,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
addButton(new GuiNpcButton(73, guiLeft + 270, y + 145, 20, 20, "<"));
|
||||
addButton(new GuiNpcButton(74, guiLeft + 292, y + 145, 20, 20, ">"));
|
||||
getButton(73).setEnabled(selectedAbilityIndex > 0);
|
||||
getButton(74).setEnabled(selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size() - 1);
|
||||
getButton(74).setEnabled(selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size() - 1);
|
||||
|
||||
// Save button (to the right of carrots, only enabled when ability is selected)
|
||||
addButton(new GuiNpcButton(76, guiLeft + 320, y + 145, 50, 20, "gui.save"));
|
||||
@@ -166,10 +167,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
// Don't set custom name - let it default to type name
|
||||
npcAbilities.add(newAbility);
|
||||
// Auto-select the newly added ability
|
||||
selectedAbilityIndex = npcAbilities.size() - 1;
|
||||
npcSlots.add(AbilitySlot.inline(newAbility));
|
||||
selectedAbilityIndex = npcSlots.size() - 1;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
@@ -182,8 +181,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
// Remove ability
|
||||
if (id == 71) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
npcAbilities.remove(selectedAbilityIndex);
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
npcSlots.remove(selectedAbilityIndex);
|
||||
selectedAbilityIndex = -1;
|
||||
updateNpcAbilitiesList();
|
||||
initGui();
|
||||
@@ -194,9 +193,17 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
// Edit ability
|
||||
if (id == 72) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
Ability ability = npcAbilities.get(selectedAbilityIndex);
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
AbilitySlot slot = npcSlots.get(selectedAbilityIndex);
|
||||
if (slot.isReference()) {
|
||||
// Reference slot - ask clone-and-modify vs modify-parent
|
||||
setSubGui(new SubGuiAbilityEditMode());
|
||||
} else {
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -204,9 +211,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
// Move up (carrot left = earlier in list)
|
||||
if (id == 73) {
|
||||
if (selectedAbilityIndex > 0) {
|
||||
Ability temp = npcAbilities.get(selectedAbilityIndex);
|
||||
npcAbilities.set(selectedAbilityIndex, npcAbilities.get(selectedAbilityIndex - 1));
|
||||
npcAbilities.set(selectedAbilityIndex - 1, temp);
|
||||
AbilitySlot temp = npcSlots.get(selectedAbilityIndex);
|
||||
npcSlots.set(selectedAbilityIndex, npcSlots.get(selectedAbilityIndex - 1));
|
||||
npcSlots.set(selectedAbilityIndex - 1, temp);
|
||||
selectedAbilityIndex--;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
@@ -218,10 +225,10 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
// Move down (carrot right = later in list)
|
||||
if (id == 74) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size() - 1) {
|
||||
Ability temp = npcAbilities.get(selectedAbilityIndex);
|
||||
npcAbilities.set(selectedAbilityIndex, npcAbilities.get(selectedAbilityIndex + 1));
|
||||
npcAbilities.set(selectedAbilityIndex + 1, temp);
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size() - 1) {
|
||||
AbilitySlot temp = npcSlots.get(selectedAbilityIndex);
|
||||
npcSlots.set(selectedAbilityIndex, npcSlots.get(selectedAbilityIndex + 1));
|
||||
npcSlots.set(selectedAbilityIndex + 1, temp);
|
||||
selectedAbilityIndex++;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
@@ -237,15 +244,16 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
return;
|
||||
}
|
||||
|
||||
// Save selected ability
|
||||
// Save selected ability as custom preset
|
||||
if (id == 76) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
Ability abilityToSave = npcAbilities.get(selectedAbilityIndex);
|
||||
if (abilityToSave.getName() == null || abilityToSave.getName().isEmpty()) {
|
||||
// Need a name to save - open edit dialog first
|
||||
setSubGui(abilityToSave.createConfigGui(this));
|
||||
} else {
|
||||
setSubGui(new SubGuiAbilitySaveConfirm(abilityToSave));
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
Ability abilityToSave = npcSlots.get(selectedAbilityIndex).getAbility();
|
||||
if (abilityToSave != null) {
|
||||
if (abilityToSave.getName() == null || abilityToSave.getName().isEmpty()) {
|
||||
setSubGui(abilityToSave.createConfigGui(this));
|
||||
} else {
|
||||
setSubGui(new SubGuiAbilitySaveConfirm(abilityToSave));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -253,13 +261,15 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
// Toggle selected ability on/off
|
||||
if (id == 77) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
Ability ability = npcAbilities.get(selectedAbilityIndex);
|
||||
ability.setEnabled(((GuiNpcButton) guibutton).getValue() == 1);
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
save();
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
Ability ability = npcSlots.get(selectedAbilityIndex).getAbility();
|
||||
if (ability != null) {
|
||||
ability.setEnabled(((GuiNpcButton) guibutton).getValue() == 1);
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
save();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -290,26 +300,20 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
abilitiesEnabled = compound.getBoolean("AbilitiesEnabled");
|
||||
|
||||
// Support old globalCooldown for backwards compatibility
|
||||
if (compound.hasKey("AbilityMinCooldown")) {
|
||||
minCooldown = compound.getInteger("AbilityMinCooldown");
|
||||
maxCooldown = compound.getInteger("AbilityMaxCooldown");
|
||||
} else if (compound.hasKey("AbilityGlobalCooldown")) {
|
||||
int oldCooldown = compound.getInteger("AbilityGlobalCooldown");
|
||||
minCooldown = oldCooldown;
|
||||
maxCooldown = oldCooldown * 2;
|
||||
} else {
|
||||
minCooldown = compound.getInteger("AbilityMinCooldown");
|
||||
maxCooldown = compound.getInteger("AbilityMaxCooldown");
|
||||
if (minCooldown == 0 && maxCooldown == 0) {
|
||||
minCooldown = 20;
|
||||
maxCooldown = 60;
|
||||
}
|
||||
|
||||
npcAbilities.clear();
|
||||
npcSlots.clear();
|
||||
NBTTagList abilityList = compound.getTagList("Abilities", 10);
|
||||
for (int i = 0; i < abilityList.tagCount(); i++) {
|
||||
NBTTagCompound abilityNBT = abilityList.getCompoundTagAt(i);
|
||||
Ability ability = AbilityController.Instance.fromNBT(abilityNBT);
|
||||
if (ability != null) {
|
||||
npcAbilities.add(ability);
|
||||
AbilitySlot slot = AbilitySlot.fromNBT(abilityNBT);
|
||||
if (slot != null) {
|
||||
npcSlots.add(slot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +356,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
private void updateNpcAbilitiesList() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < npcAbilities.size(); i++) {
|
||||
for (int i = 0; i < npcSlots.size(); i++) {
|
||||
list.add(getAbilityListEntry(i));
|
||||
}
|
||||
if (npcAbilitiesScroll != null) {
|
||||
@@ -361,26 +365,41 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the display entry for an ability in the list.
|
||||
* Format: "[●] 1. Custom Name (Type)" or "[●] 1. Type" if no custom name
|
||||
* Circle is green (§a) for enabled, red (§c) for disabled
|
||||
* Creates the display entry for an ability slot in the list.
|
||||
* Inline: "[●] 1. Custom Name (Type)" or "[●] 1. Type"
|
||||
* Reference: "[●] 1. > Name (Type)" in yellow
|
||||
* Broken: "[●] 1. > [Missing: id...]" in red
|
||||
*/
|
||||
private String getAbilityListEntry(int index) {
|
||||
Ability ability = npcAbilities.get(index);
|
||||
AbilitySlot slot = npcSlots.get(index);
|
||||
Ability ability = slot.getAbility();
|
||||
|
||||
if (ability == null) {
|
||||
// Broken reference
|
||||
String refId = slot.getReferenceId();
|
||||
String shortId = refId != null && refId.length() > 8 ? refId.substring(0, 8) + "..." : refId;
|
||||
return "\u00A7c\u25CF\u00A7r " + (index + 1) + ". \u00A7c> [Missing: " + shortId + "]\u00A7r";
|
||||
}
|
||||
|
||||
String typeName = getDisplayName(ability.getTypeId());
|
||||
String customName = ability.getName();
|
||||
|
||||
// Color prefix: green circle for enabled, red for disabled
|
||||
String colorPrefix = ability.isEnabled() ? "\u00A7a\u25CF\u00A7r " : "\u00A7c\u25CF\u00A7r ";
|
||||
|
||||
String nameDisplay;
|
||||
if (customName != null && !customName.isEmpty() && !customName.equals(typeName)) {
|
||||
return colorPrefix + (index + 1) + ". " + customName + " (" + typeName + ")";
|
||||
nameDisplay = customName + " (" + typeName + ")";
|
||||
} else {
|
||||
nameDisplay = typeName;
|
||||
}
|
||||
return colorPrefix + (index + 1) + ". " + typeName;
|
||||
|
||||
if (slot.isReference()) {
|
||||
return colorPrefix + (index + 1) + ". \u00A7e> " + nameDisplay + "\u00A7r";
|
||||
}
|
||||
return colorPrefix + (index + 1) + ". " + nameDisplay;
|
||||
}
|
||||
|
||||
private void selectAbilityByIndex(int index) {
|
||||
if (index >= 0 && index < npcAbilities.size()) {
|
||||
if (index >= 0 && index < npcSlots.size()) {
|
||||
String entry = getAbilityListEntry(index);
|
||||
if (npcAbilitiesScroll != null) {
|
||||
npcAbilitiesScroll.setSelected(entry);
|
||||
@@ -403,8 +422,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
compound.setInteger("AbilityMaxCooldown", maxCooldown);
|
||||
|
||||
NBTTagList abilityList = new NBTTagList();
|
||||
for (Ability ability : npcAbilities) {
|
||||
abilityList.appendTag(ability.writeNBT());
|
||||
for (AbilitySlot slot : npcSlots) {
|
||||
abilityList.appendTag(slot.writeNBT());
|
||||
}
|
||||
compound.setTag("Abilities", abilityList);
|
||||
|
||||
@@ -412,15 +431,29 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from SubGuiAbilityLoad when a saved ability is loaded.
|
||||
* Adds the ability to the NPC's ability list.
|
||||
* Called from SubGuiAbilityLoad when a cloned ability is loaded.
|
||||
* Adds as an inline slot.
|
||||
*/
|
||||
public void loadAbility(Ability loadedAbility) {
|
||||
if (loadedAbility != null) {
|
||||
loadedAbility.setId(UUID.randomUUID().toString());
|
||||
npcAbilities.add(loadedAbility);
|
||||
// Auto-select the newly added ability
|
||||
selectedAbilityIndex = npcAbilities.size() - 1;
|
||||
npcSlots.add(AbilitySlot.inline(loadedAbility));
|
||||
selectedAbilityIndex = npcSlots.size() - 1;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from SubGuiAbilityLoad when a reference is loaded.
|
||||
* Adds as a reference slot.
|
||||
*/
|
||||
public void loadAbilityReference(String referenceId) {
|
||||
if (referenceId != null && !referenceId.isEmpty()) {
|
||||
npcSlots.add(AbilitySlot.reference(referenceId));
|
||||
selectedAbilityIndex = npcSlots.size() - 1;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
@@ -460,9 +493,16 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll == npcAbilitiesScroll && selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
Ability ability = npcAbilities.get(selectedAbilityIndex);
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
if (scroll == npcAbilitiesScroll && selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
AbilitySlot slot = npcSlots.get(selectedAbilityIndex);
|
||||
if (slot.isReference()) {
|
||||
setSubGui(new SubGuiAbilityEditMode());
|
||||
} else {
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,8 +529,32 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiAbilityConfig) {
|
||||
// Ability was saved in the SubGui, refresh list
|
||||
if (subgui instanceof SubGuiAbilityEditMode) {
|
||||
int mode = ((SubGuiAbilityEditMode) subgui).getResult();
|
||||
if (mode < 0) return; // cancelled
|
||||
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
AbilitySlot slot = npcSlots.get(selectedAbilityIndex);
|
||||
if (mode == SubGuiAbilityEditMode.MODE_CLONE_MODIFY) {
|
||||
// Convert reference to inline, then edit
|
||||
if (slot.convertToInline()) {
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
ability.setId(UUID.randomUUID().toString());
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
updateNpcAbilitiesList();
|
||||
save();
|
||||
}
|
||||
} else if (mode == SubGuiAbilityEditMode.MODE_MODIFY_PARENT) {
|
||||
// Edit the resolved ability directly (changes propagate to controller)
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (subgui instanceof SubGuiAbilityConfig) {
|
||||
updateNpcAbilitiesList();
|
||||
save();
|
||||
}
|
||||
@@ -500,8 +564,15 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
* Called from SubGuiAbilityConfig when ability is saved.
|
||||
*/
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
npcAbilities.set(selectedAbilityIndex, ability);
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
AbilitySlot slot = npcSlots.get(selectedAbilityIndex);
|
||||
if (slot.isReference()) {
|
||||
// For reference slots, save back to controller
|
||||
// (The resolved copy was edited in-place)
|
||||
} else {
|
||||
// For inline slots, replace with the updated ability
|
||||
npcSlots.set(selectedAbilityIndex, AbilitySlot.inline(ability));
|
||||
}
|
||||
updateNpcAbilitiesList();
|
||||
save();
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
// Row 2: Weight + Lock Movement
|
||||
addLabel(new GuiNpcLabel(4, "ability.weight", col1LabelX, y + 5));
|
||||
GuiNpcTextField weightField = new GuiNpcTextField(3, this, fontRendererObj, col1FieldX, y, 40, 20, String.valueOf(weight));
|
||||
GuiNpcTextField weightField = new GuiNpcTextField(3, this, fontRendererObj, col1FieldX, y, 40, 20, "" + weight);
|
||||
weightField.setIntegersOnly();
|
||||
weightField.setMinMaxDefault(1, 1000, 10);
|
||||
addTextField(weightField);
|
||||
@@ -271,7 +271,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
// Only show dazed ticks if interruptible is enabled
|
||||
if (interruptible) {
|
||||
addLabel(new GuiNpcLabel(12, "ability.dazed", col2LabelX, y + 5));
|
||||
GuiNpcTextField dazedField = new GuiNpcTextField(13, this, fontRendererObj, col2FieldX, y, 40, 20, String.valueOf(dazedTicks));
|
||||
GuiNpcTextField dazedField = new GuiNpcTextField(13, this, fontRendererObj, col2FieldX, y, 40, 20, "" + dazedTicks);
|
||||
dazedField.setIntegersOnly();
|
||||
dazedField.setMinMaxDefault(0, 1000, 80);
|
||||
addTextField(dazedField);
|
||||
@@ -291,13 +291,13 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
// Only show windup textbox if sync is off or no animation selected
|
||||
if (!syncWindupWithAnimation || !hasWindupAnimation) {
|
||||
GuiNpcTextField windupField = new GuiNpcTextField(11, this, fontRendererObj, col1FieldX, y, 40, 20, String.valueOf(windUpTicks));
|
||||
GuiNpcTextField windupField = new GuiNpcTextField(11, this, fontRendererObj, col1FieldX, y, 40, 20, "" + windUpTicks);
|
||||
windupField.setIntegersOnly();
|
||||
windupField.setMinMaxDefault(0, 1000, 20);
|
||||
addTextField(windupField);
|
||||
} else {
|
||||
// Show calculated value as label when synced
|
||||
addLabel(new GuiNpcLabel(11, String.valueOf(windUpTicks), col1FieldX + 5, y + 5));
|
||||
addLabel(new GuiNpcLabel(11, "" + windUpTicks, col1FieldX + 5, y + 5));
|
||||
}
|
||||
|
||||
// Sync toggle button - only show if windup animation is selected
|
||||
@@ -309,7 +309,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
}
|
||||
|
||||
addLabel(new GuiNpcLabel(13, "ability.cooldown", col2LabelX, y + 5));
|
||||
GuiNpcTextField cooldownField = new GuiNpcTextField(10, this, fontRendererObj, col2FieldX, y, 40, 20, String.valueOf(cooldownTicks));
|
||||
GuiNpcTextField cooldownField = new GuiNpcTextField(10, this, fontRendererObj, col2FieldX, y, 40, 20, "" + cooldownTicks);
|
||||
cooldownField.setIntegersOnly();
|
||||
cooldownField.setMinMaxDefault(0, 10000, 0);
|
||||
addTextField(cooldownField);
|
||||
@@ -399,13 +399,13 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
// Row 1: Min Range + Max Range
|
||||
addLabel(new GuiNpcLabel(20, "ability.minRange", col1LabelX, y + 5));
|
||||
GuiNpcTextField minRangeField = new GuiNpcTextField(5, this, fontRendererObj, col1FieldX, y, 40, 20, String.valueOf((int) minRange));
|
||||
GuiNpcTextField minRangeField = new GuiNpcTextField(5, this, fontRendererObj, col1FieldX, y, 40, 20, "" + (int) minRange);
|
||||
minRangeField.setIntegersOnly();
|
||||
minRangeField.setMinMaxDefault(0, 100, 0);
|
||||
addTextField(minRangeField);
|
||||
|
||||
addLabel(new GuiNpcLabel(21, "ability.maxRange", col2LabelX, y + 5));
|
||||
GuiNpcTextField maxRangeField = new GuiNpcTextField(6, this, fontRendererObj, col2FieldX, y, 40, 20, String.valueOf((int) maxRange));
|
||||
GuiNpcTextField maxRangeField = new GuiNpcTextField(6, this, fontRendererObj, col2FieldX, y, 40, 20, "" + (int) maxRange);
|
||||
maxRangeField.setIntegersOnly();
|
||||
maxRangeField.setMinMaxDefault(1, 100, 20);
|
||||
addTextField(maxRangeField);
|
||||
@@ -1039,7 +1039,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
* Creates an integer text field for type-specific settings.
|
||||
*/
|
||||
protected GuiNpcTextField createIntField(int id, int x, int y, int width, int value) {
|
||||
GuiNpcTextField field = new GuiNpcTextField(id, this, fontRendererObj, x, y, width, 20, String.valueOf(value));
|
||||
GuiNpcTextField field = new GuiNpcTextField(id, this, fontRendererObj, x, y, width, 20, "" + value);
|
||||
field.setIntegersOnly();
|
||||
return field;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilityRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityRemovePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -51,7 +51,7 @@ public class SubGuiAbilityDeleteConfirm extends SubGuiInterface {
|
||||
|
||||
if (id == 0) {
|
||||
// Delete the ability via packet
|
||||
PacketClient.sendClient(new SavedAbilityRemovePacket(abilityName));
|
||||
PacketClient.sendClient(new CustomAbilityRemovePacket(abilityName));
|
||||
if (onDeleted != null) {
|
||||
onDeleted.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
/**
|
||||
* Dialog asking the user whether to clone-and-modify (convert to inline) or modify the parent ability.
|
||||
*/
|
||||
public class SubGuiAbilityEditMode extends SubGuiInterface {
|
||||
|
||||
public static final int MODE_CLONE_MODIFY = 0;
|
||||
public static final int MODE_MODIFY_PARENT = 1;
|
||||
|
||||
private int result = -1;
|
||||
|
||||
public SubGuiAbilityEditMode() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 90;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
addLabel(new GuiNpcLabel(0, "ability.edit.mode", guiLeft + 10, y));
|
||||
|
||||
y += 25;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 95, 20, "ability.cloneModify"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 115, y, 95, 20, "ability.modifyParent"));
|
||||
|
||||
y += 25;
|
||||
addButton(new GuiNpcButton(2, guiLeft + 65, y, 90, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
result = MODE_CLONE_MODIFY;
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
result = MODE_MODIFY_PARENT;
|
||||
close();
|
||||
} else if (guibutton.id == 2) {
|
||||
result = -1;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package noppes.npcs.client.gui.advanced;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
@@ -13,28 +13,34 @@ import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.client.gui.util.IScrollData;
|
||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.constants.EnumScrollData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Dialog for loading a saved ability preset.
|
||||
* Uses packet-based communication for proper client-server architecture.
|
||||
* Shows custom abilities from the server, then asks Clone/Reference via SubGuiAbilityLoadMode.
|
||||
*/
|
||||
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener, IScrollData, IGuiData {
|
||||
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener, IScrollData, IGuiData, ISubGuiListener {
|
||||
|
||||
private final SubGuiAbilityConfig parentConfig;
|
||||
private final GuiNPCAbilities parentAbilities;
|
||||
private String selectedName = null;
|
||||
private HashMap<String, Integer> abilityData = new HashMap<>();
|
||||
private String selectedDisplayName = null;
|
||||
private String selectedUuid = null;
|
||||
|
||||
/** Maps display name -> UUID for custom abilities. */
|
||||
private final HashMap<String, String> displayToUuid = new HashMap<>();
|
||||
private HashMap<String, Integer> rawData = new HashMap<>();
|
||||
private GuiCustomScroll scroll;
|
||||
|
||||
// Track if we're waiting for a load
|
||||
private boolean waitingForLoad = false;
|
||||
private int pendingLoadMode = -1;
|
||||
|
||||
public SubGuiAbilityLoad(SubGuiAbilityConfig parentConfig) {
|
||||
this.parentConfig = parentConfig;
|
||||
@@ -44,8 +50,7 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
xSize = 220;
|
||||
ySize = 180;
|
||||
|
||||
// Request ability list from server
|
||||
PacketClient.sendClient(new SavedAbilitiesGetPacket());
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
}
|
||||
|
||||
public SubGuiAbilityLoad(GuiNPCAbilities parentAbilities) {
|
||||
@@ -56,8 +61,7 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
xSize = 220;
|
||||
ySize = 180;
|
||||
|
||||
// Request ability list from server
|
||||
PacketClient.sendClient(new SavedAbilitiesGetPacket());
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +73,6 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
addLabel(new GuiNpcLabel(0, "ability.load.select", guiLeft + 10, y));
|
||||
y += 14;
|
||||
|
||||
// Scroll list of saved abilities
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.setSize(200, 110);
|
||||
@@ -77,42 +80,70 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
scroll.guiLeft = guiLeft + 10;
|
||||
scroll.guiTop = y;
|
||||
scroll.setList(getFilteredList());
|
||||
if (selectedName != null && abilityData.containsKey(selectedName)) {
|
||||
scroll.setSelected(selectedName);
|
||||
if (selectedDisplayName != null) {
|
||||
scroll.setSelected(selectedDisplayName);
|
||||
}
|
||||
addScroll(scroll);
|
||||
|
||||
y += 115;
|
||||
|
||||
// Buttons
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 95, 20, "gui.load"));
|
||||
addButton(new GuiNpcButton(2, guiLeft + 115, y, 95, 20, "gui.cancel"));
|
||||
|
||||
// Disable load if nothing selected
|
||||
getButton(0).setEnabled(selectedName != null && !selectedName.isEmpty());
|
||||
getButton(0).setEnabled(selectedUuid != null);
|
||||
}
|
||||
|
||||
private List<String> getFilteredList() {
|
||||
return new ArrayList<>(abilityData.keySet());
|
||||
return new ArrayList<>(displayToUuid.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 0 && selectedName != null) {
|
||||
// Request ability data from server
|
||||
waitingForLoad = true;
|
||||
PacketClient.sendClient(new SavedAbilityGetPacket(selectedName));
|
||||
if (id == 0 && selectedUuid != null) {
|
||||
if (parentAbilities != null) {
|
||||
// From NPC abilities GUI - ask clone/reference
|
||||
setSubGui(new SubGuiAbilityLoadMode());
|
||||
} else {
|
||||
// From config GUI - always clone
|
||||
waitingForLoad = true;
|
||||
pendingLoadMode = SubGuiAbilityLoadMode.MODE_CLONE;
|
||||
PacketClient.sendClient(new CustomAbilityGetPacket(selectedUuid));
|
||||
}
|
||||
} else if (id == 2) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiAbilityLoadMode) {
|
||||
int mode = ((SubGuiAbilityLoadMode) subgui).getResult();
|
||||
if (mode < 0) return; // cancelled
|
||||
|
||||
if (mode == SubGuiAbilityLoadMode.MODE_REFERENCE) {
|
||||
// Reference mode - just pass the reference ID
|
||||
if (parentAbilities != null && selectedUuid != null) {
|
||||
parentAbilities.loadAbilityReference(selectedUuid);
|
||||
}
|
||||
close();
|
||||
} else {
|
||||
// Clone mode - request full data
|
||||
waitingForLoad = true;
|
||||
pendingLoadMode = SubGuiAbilityLoadMode.MODE_CLONE;
|
||||
PacketClient.sendClient(new CustomAbilityGetPacket(selectedUuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0) {
|
||||
selectedName = scroll.getSelected();
|
||||
selectedDisplayName = scroll.getSelected();
|
||||
if (selectedDisplayName != null) {
|
||||
selectedUuid = displayToUuid.get(selectedDisplayName);
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
@@ -120,22 +151,40 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
|
||||
// Double-click to load - request from server
|
||||
selectedName = selection;
|
||||
waitingForLoad = true;
|
||||
PacketClient.sendClient(new SavedAbilityGetPacket(selection));
|
||||
selectedDisplayName = selection;
|
||||
selectedUuid = displayToUuid.get(selectedDisplayName);
|
||||
if (selectedUuid != null) {
|
||||
if (parentAbilities != null) {
|
||||
setSubGui(new SubGuiAbilityLoadMode());
|
||||
} else {
|
||||
waitingForLoad = true;
|
||||
pendingLoadMode = SubGuiAbilityLoadMode.MODE_CLONE;
|
||||
PacketClient.sendClient(new CustomAbilityGetPacket(selectedUuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.ABILITIES) {
|
||||
String name = scroll != null ? scroll.getSelected() : null;
|
||||
this.abilityData = data;
|
||||
if (type == EnumScrollData.CUSTOM_ABILITIES) {
|
||||
displayToUuid.clear();
|
||||
rawData = data;
|
||||
for (String key : data.keySet()) {
|
||||
// key format: "displayName\tUUID"
|
||||
int tabIndex = key.indexOf('\t');
|
||||
if (tabIndex > 0) {
|
||||
String displayName = key.substring(0, tabIndex);
|
||||
String uuid = key.substring(tabIndex + 1);
|
||||
displayToUuid.put(displayName, uuid);
|
||||
} else {
|
||||
displayToUuid.put(key, key);
|
||||
}
|
||||
}
|
||||
if (scroll != null) {
|
||||
scroll.setList(getFilteredList());
|
||||
if (name != null && abilityData.containsKey(name)) {
|
||||
scroll.setSelected(name);
|
||||
if (selectedDisplayName != null && displayToUuid.containsKey(selectedDisplayName)) {
|
||||
scroll.setSelected(selectedDisplayName);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
@@ -144,11 +193,15 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
// Received ability data from server
|
||||
if (waitingForLoad) {
|
||||
waitingForLoad = false;
|
||||
Ability loaded = AbilityController.Instance.fromNBT(compound);
|
||||
if (loaded != null) {
|
||||
if (pendingLoadMode == SubGuiAbilityLoadMode.MODE_CLONE) {
|
||||
// Give it a new UUID so it's a unique inline copy
|
||||
loaded.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
if (parentConfig != null) {
|
||||
parentConfig.loadAbility(loaded);
|
||||
} else if (parentAbilities != null) {
|
||||
@@ -161,7 +214,7 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
this.selectedName = selected;
|
||||
this.selectedDisplayName = selected;
|
||||
if (scroll != null) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
/**
|
||||
* Dialog asking the user whether to Clone (inline copy) or Reference the loaded ability.
|
||||
*/
|
||||
public class SubGuiAbilityLoadMode extends SubGuiInterface {
|
||||
|
||||
public static final int MODE_CLONE = 0;
|
||||
public static final int MODE_REFERENCE = 1;
|
||||
|
||||
private int result = -1;
|
||||
|
||||
public SubGuiAbilityLoadMode() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 90;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
addLabel(new GuiNpcLabel(0, "ability.load.mode", guiLeft + 10, y));
|
||||
|
||||
y += 25;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 15, y, 80, 20, "ability.clone"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 105, y, 80, 20, "ability.reference"));
|
||||
|
||||
y += 25;
|
||||
addButton(new GuiNpcButton(2, guiLeft + 55, y, 90, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
result = MODE_CLONE;
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
result = MODE_REFERENCE;
|
||||
close();
|
||||
} else if (guibutton.id == 2) {
|
||||
result = -1;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilitySavePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -53,7 +53,7 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
|
||||
|
||||
if (id == 0) {
|
||||
// Save the ability via packet
|
||||
PacketClient.sendClient(new SavedAbilitySavePacket(ability.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
if (callback != null) {
|
||||
callback.onAbilitySaved(ability);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SubGuiConditionEdit extends SubGuiInterface implements ITextfieldLi
|
||||
if (typeId.equals("hit_count")) {
|
||||
// Hit count fields
|
||||
addLabel(new GuiNpcLabel(2, "condition.hits", labelX, y + 5));
|
||||
GuiNpcTextField hitsField = new GuiNpcTextField(2, this, fontRendererObj, fieldX, y, 40, 20, String.valueOf(requiredHits));
|
||||
GuiNpcTextField hitsField = new GuiNpcTextField(2, this, fontRendererObj, fieldX, y, 40, 20, "" + requiredHits);
|
||||
hitsField.setIntegersOnly();
|
||||
hitsField.setMinMaxDefault(1, 100, 3);
|
||||
hitsField.setHoverText("condition.hover.hits");
|
||||
@@ -106,7 +106,7 @@ public class SubGuiConditionEdit extends SubGuiInterface implements ITextfieldLi
|
||||
y += 24;
|
||||
|
||||
addLabel(new GuiNpcLabel(3, "condition.within", labelX, y + 5));
|
||||
GuiNpcTextField ticksField = new GuiNpcTextField(3, this, fontRendererObj, fieldX, y, 40, 20, String.valueOf(withinTicks));
|
||||
GuiNpcTextField ticksField = new GuiNpcTextField(3, this, fontRendererObj, fieldX, y, 40, 20, "" + withinTicks);
|
||||
ticksField.setIntegersOnly();
|
||||
ticksField.setMinMaxDefault(1, 1200, 60);
|
||||
ticksField.setHoverText("condition.hover.within");
|
||||
@@ -115,7 +115,7 @@ public class SubGuiConditionEdit extends SubGuiInterface implements ITextfieldLi
|
||||
// HP threshold field (as percentage)
|
||||
addLabel(new GuiNpcLabel(2, "condition.percent", labelX, y + 5));
|
||||
int percent = (int) (threshold * 100);
|
||||
GuiNpcTextField thresholdField = new GuiNpcTextField(4, this, fontRendererObj, fieldX, y, 40, 20, String.valueOf(percent));
|
||||
GuiNpcTextField thresholdField = new GuiNpcTextField(4, this, fontRendererObj, fieldX, y, 40, 20, "" + percent);
|
||||
thresholdField.setIntegersOnly();
|
||||
thresholdField.setMinMaxDefault(1, 99, 50);
|
||||
thresholdField.setHoverText("condition.hover.threshold");
|
||||
|
||||
@@ -122,7 +122,7 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 1: Anchor Point
|
||||
addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5));
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), disc.getAnchorPointEnum().getId());
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), disc.getAnchorPointEnum().ordinal());
|
||||
anchorBtn.setHoverText("ability.hover.anchorPoint");
|
||||
addButton(anchorBtn);
|
||||
|
||||
@@ -182,12 +182,12 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 6: Density + Radius
|
||||
addLabel(new GuiNpcLabel(207, "ability.lightningDensity", labelX, y + 5));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(207, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(disc.getLightningDensity()));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(207, this, fontRendererObj, fieldX, y, 55, 18, "" + disc.getLightningDensity());
|
||||
densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f);
|
||||
addTextField(densityField);
|
||||
|
||||
addLabel(new GuiNpcLabel(208, "ability.lightningRadius", col2LabelX, y + 5));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(208, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(disc.getLightningRadius()));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(208, this, fontRendererObj, col2FieldX, y, 55, 18, "" + disc.getLightningRadius());
|
||||
radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f);
|
||||
addTextField(radiusField);
|
||||
}
|
||||
@@ -236,7 +236,7 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig {
|
||||
initGui();
|
||||
break;
|
||||
case 210:
|
||||
disc.setAnchorPointEnum(AnchorPoint.fromId(value));
|
||||
disc.setAnchorPointEnum(AnchorPoint.fromOrdinal(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class SubGuiAbilityEffects extends SubGuiInterface implements ITextfieldL
|
||||
|
||||
// Duration text field
|
||||
GuiNpcTextField durField = new GuiNpcTextField(baseId + 1, this, fontRendererObj,
|
||||
guiLeft + 112, y, 50, 20, String.valueOf(effect.getDurationTicks()));
|
||||
guiLeft + 112, y, 50, 20, "" + effect.getDurationTicks());
|
||||
durField.setIntegersOnly();
|
||||
durField.setMinMaxDefault(1, 12000, 60);
|
||||
durField.setHoverText("effect.hover.duration");
|
||||
@@ -89,7 +89,7 @@ public class SubGuiAbilityEffects extends SubGuiInterface implements ITextfieldL
|
||||
// Amplifier selector (0-10)
|
||||
String[] ampValues = new String[11];
|
||||
for (int a = 0; a <= 10; a++) {
|
||||
ampValues[a] = String.valueOf(a);
|
||||
ampValues[a] = "" + a;
|
||||
}
|
||||
GuiNpcButton ampBtn = new GuiNpcButton(baseId + 2, guiLeft + 168, y, 40, 20, ampValues, effect.getAmplifier());
|
||||
ampBtn.setHoverText("effect.hover.amplifier");
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 1: Anchor Point
|
||||
addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5));
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), beam.getAnchorPointEnum().getId());
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), beam.getAnchorPointEnum().ordinal());
|
||||
anchorBtn.setHoverText("ability.hover.anchorPoint");
|
||||
addButton(anchorBtn);
|
||||
|
||||
@@ -175,12 +175,12 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 5: Density + Radius
|
||||
addLabel(new GuiNpcLabel(207, "ability.lightningDensity", labelX, y + 5));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(207, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(beam.getLightningDensity()));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(207, this, fontRendererObj, fieldX, y, 55, 18, "" + beam.getLightningDensity());
|
||||
densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f);
|
||||
addTextField(densityField);
|
||||
|
||||
addLabel(new GuiNpcLabel(208, "ability.lightningRadius", col2LabelX, y + 5));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(208, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(beam.getLightningRadius()));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(208, this, fontRendererObj, col2FieldX, y, 55, 18, "" + beam.getLightningRadius());
|
||||
radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f);
|
||||
addTextField(radiusField);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig {
|
||||
initGui();
|
||||
break;
|
||||
case 210:
|
||||
beam.setAnchorPointEnum(AnchorPoint.fromId(value));
|
||||
beam.setAnchorPointEnum(AnchorPoint.fromOrdinal(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,12 +144,12 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 4: Density + Radius
|
||||
addLabel(new GuiNpcLabel(206, "ability.lightningDensity", labelX, y + 5));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(206, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(laser.getLightningDensity()));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(206, this, fontRendererObj, fieldX, y, 55, 18, "" + laser.getLightningDensity());
|
||||
densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f);
|
||||
addTextField(densityField);
|
||||
|
||||
addLabel(new GuiNpcLabel(207, "ability.lightningRadius", col2LabelX, y + 5));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(207, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(laser.getLightningRadius()));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(207, this, fontRendererObj, col2FieldX, y, 55, 18, "" + laser.getLightningRadius());
|
||||
radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f);
|
||||
addTextField(radiusField);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 1: Anchor Point
|
||||
addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5));
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), orb.getAnchorPointEnum().getId());
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), orb.getAnchorPointEnum().ordinal());
|
||||
anchorBtn.setHoverText("ability.hover.anchorPoint");
|
||||
addButton(anchorBtn);
|
||||
|
||||
@@ -163,12 +163,12 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 61: Density + Radius
|
||||
addLabel(new GuiNpcLabel(207, "ability.lightningDensity", labelX, y + 5));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(207, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(orb.getLightningDensity()));
|
||||
GuiNpcTextField densityField = new GuiNpcTextField(207, this, fontRendererObj, fieldX, y, 55, 18, "" + orb.getLightningDensity());
|
||||
densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f);
|
||||
addTextField(densityField);
|
||||
|
||||
addLabel(new GuiNpcLabel(208, "ability.lightningRadius", col2LabelX, y + 5));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(208, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(orb.getLightningRadius()));
|
||||
GuiNpcTextField radiusField = new GuiNpcTextField(208, this, fontRendererObj, col2FieldX, y, 55, 18, "" + orb.getLightningRadius());
|
||||
radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f);
|
||||
addTextField(radiusField);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig {
|
||||
initGui();
|
||||
break;
|
||||
case 210:
|
||||
orb.setAnchorPointEnum(AnchorPoint.fromId(value));
|
||||
orb.setAnchorPointEnum(AnchorPoint.fromOrdinal(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,21 +338,21 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
|
||||
// Health
|
||||
label = StatCollector.translateToLocal("stats.health") + ": ";
|
||||
value = String.valueOf(npc.stats.maxHealth);
|
||||
value = "" + npc.stats.maxHealth;
|
||||
fontRendererObj.drawString(label, xLabel, y, 0x29d6b9, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
|
||||
// Damage (using getAttackStrength)
|
||||
label = StatCollector.translateToLocal("stats.meleestrength") + ": ";
|
||||
value = String.valueOf(npc.stats.getAttackStrength());
|
||||
value = "" + npc.stats.getAttackStrength();
|
||||
fontRendererObj.drawString(label, xLabel, y, 0xff5714, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
|
||||
// Attack Speed
|
||||
label = StatCollector.translateToLocal("stats.meleespeed") + ": ";
|
||||
value = String.valueOf(npc.stats.attackSpeed);
|
||||
value = "" + npc.stats.attackSpeed;
|
||||
fontRendererObj.drawString(label, xLabel, y, 0xf7ca28, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
@@ -381,7 +381,7 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
|
||||
// Walk Speed
|
||||
label = StatCollector.translateToLocal("stats.speed") + ": ";
|
||||
value = String.valueOf(npc.ais.getWalkingSpeed());
|
||||
value = "" + npc.ais.getWalkingSpeed();
|
||||
fontRendererObj.drawString(label, xLabel, y, 0xffae0d, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
@@ -415,7 +415,7 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
|
||||
// Version
|
||||
label = StatCollector.translateToLocal("display.version") + ": ";
|
||||
value = String.valueOf(linkedItem.version);
|
||||
value = "" + linkedItem.version;
|
||||
fontRendererObj.drawString(label, xLabel, y, labelColor, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
@@ -423,7 +423,7 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
// Max Stack Size
|
||||
labelColor = 0xff5714;
|
||||
label = StatCollector.translateToLocal("display.maxStack") + ": ";
|
||||
value = String.valueOf(linkedItem.stackSize);
|
||||
value = "" + linkedItem.stackSize;
|
||||
fontRendererObj.drawString(label, xLabel, y, labelColor, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
@@ -431,7 +431,7 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
// Dig Speed
|
||||
labelColor = 0xf7ca28;
|
||||
label = StatCollector.translateToLocal("display.digSpeed") + ": ";
|
||||
value = String.valueOf(linkedItem.digSpeed);
|
||||
value = "" + linkedItem.digSpeed;
|
||||
fontRendererObj.drawString(label, xLabel, y, labelColor, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
@@ -498,14 +498,14 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
labelColor = 0x7cff54;
|
||||
// isTool
|
||||
label = StatCollector.translateToLocal("display.isTool") + ": ";
|
||||
value = String.valueOf(linkedItem.isTool).toUpperCase();
|
||||
value = ("" + linkedItem.isTool).toUpperCase();
|
||||
fontRendererObj.drawString(label, xLabel, y, labelColor, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
|
||||
// isNormalItem
|
||||
label = StatCollector.translateToLocal("display.isNormalItem") + ": ";
|
||||
value = String.valueOf(linkedItem.isNormalItem).toUpperCase();
|
||||
value = ("" + linkedItem.isNormalItem).toUpperCase();
|
||||
fontRendererObj.drawString(label, xLabel, y, labelColor, false);
|
||||
fontRendererObj.drawString(value, xValue, y, valueColor, false);
|
||||
y += 15;
|
||||
|
||||
@@ -5,10 +5,10 @@ import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilityRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilitySavePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
@@ -53,7 +53,10 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
// ==================== DATA ====================
|
||||
private GuiCustomScroll scroll;
|
||||
private HashMap<String, Integer> abilityData = new HashMap<>();
|
||||
/** Maps display name -> UUID for custom abilities */
|
||||
private final HashMap<String, String> displayToUuid = new HashMap<>();
|
||||
private String selected = null;
|
||||
private String selectedUuid = null;
|
||||
private String search = "";
|
||||
private Ability selectedAbility = null;
|
||||
|
||||
@@ -73,7 +76,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
previewExecutor.setParentGui(this);
|
||||
|
||||
// Request ability data from server
|
||||
PacketClient.sendClient(new SavedAbilitiesGetPacket());
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
|
||||
// Enable animation data
|
||||
AnimationData data = npc.display.animationData;
|
||||
@@ -90,7 +93,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
// Remove button
|
||||
addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 30, 45, 20, "gui.remove"));
|
||||
getButton(1).setEnabled(selected != null && !selected.isEmpty() && abilityData.containsKey(selected));
|
||||
getButton(1).setEnabled(selected != null && !selected.isEmpty() && displayToUuid.containsKey(selected));
|
||||
|
||||
// Scroll list of saved abilities (right side)
|
||||
if (scroll == null) {
|
||||
@@ -103,7 +106,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
// Update scroll list
|
||||
scroll.setList(getSearchList());
|
||||
if (selected != null && abilityData.containsKey(selected)) {
|
||||
if (selected != null && displayToUuid.containsKey(selected)) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
|
||||
@@ -144,10 +147,10 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
private List<String> getSearchList() {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(abilityData.keySet());
|
||||
return new ArrayList<>(displayToUuid.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : abilityData.keySet()) {
|
||||
for (String name : displayToUuid.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
}
|
||||
@@ -208,8 +211,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 1 && selected != null && abilityData.containsKey(selected)) {
|
||||
// Remove - show confirmation
|
||||
if (id == 1 && selected != null && selectedUuid != null) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, selected, StatCollector.translateToLocal("gui.delete"), 1);
|
||||
displayGuiScreen(guiyesno);
|
||||
} else if (id == 100 && selectedAbility != null) {
|
||||
@@ -254,12 +256,13 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
if (scroll.id == 0) {
|
||||
String newSelection = scroll.getSelected();
|
||||
if (newSelection != null && !newSelection.equals(selected)) {
|
||||
// Stop any playing preview
|
||||
previewExecutor.stop();
|
||||
|
||||
selected = newSelection;
|
||||
// Request ability data from server
|
||||
PacketClient.sendClient(new SavedAbilityGetPacket(selected));
|
||||
selectedUuid = displayToUuid.get(selected);
|
||||
if (selectedUuid != null) {
|
||||
PacketClient.sendClient(new CustomAbilityGetPacket(selectedUuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,13 +280,25 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.ABILITIES) {
|
||||
String name = scroll != null ? scroll.getSelected() : null;
|
||||
if (type == EnumScrollData.CUSTOM_ABILITIES) {
|
||||
String prevSelected = scroll != null ? scroll.getSelected() : null;
|
||||
this.abilityData = data;
|
||||
displayToUuid.clear();
|
||||
for (String key : data.keySet()) {
|
||||
// key format: "displayName\tUUID"
|
||||
int tabIndex = key.indexOf('\t');
|
||||
if (tabIndex > 0) {
|
||||
String displayName = key.substring(0, tabIndex);
|
||||
String uuid = key.substring(tabIndex + 1);
|
||||
displayToUuid.put(displayName, uuid);
|
||||
} else {
|
||||
displayToUuid.put(key, key);
|
||||
}
|
||||
}
|
||||
if (scroll != null) {
|
||||
scroll.setList(getSearchList());
|
||||
if (name != null && abilityData.containsKey(name)) {
|
||||
scroll.setSelected(name);
|
||||
if (prevSelected != null && displayToUuid.containsKey(prevSelected)) {
|
||||
scroll.setSelected(prevSelected);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
@@ -322,11 +337,11 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
NoppesUtil.openGUI(player, this);
|
||||
if (!result) return;
|
||||
|
||||
if (id == 1 && selected != null && abilityData.containsKey(selected)) {
|
||||
// Delete ability via packet
|
||||
PacketClient.sendClient(new SavedAbilityRemovePacket(selected));
|
||||
if (id == 1 && selected != null && selectedUuid != null) {
|
||||
PacketClient.sendClient(new CustomAbilityRemovePacket(selectedUuid));
|
||||
scroll.clear();
|
||||
selected = null;
|
||||
selectedUuid = null;
|
||||
selectedAbility = null;
|
||||
initGui();
|
||||
}
|
||||
@@ -334,8 +349,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
// Save the edited ability via packet
|
||||
PacketClient.sendClient(new SavedAbilitySavePacket(ability.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -90,7 +90,7 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
Set<Integer> keySet = this.spawn.spawnCompounds.keySet();
|
||||
for (int i : keySet) {
|
||||
list.add(String.valueOf(i));
|
||||
list.add("" + i);
|
||||
}
|
||||
this.spawnEntryScroll.setList(list);
|
||||
addScroll(this.spawnEntryScroll);
|
||||
@@ -99,7 +99,7 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
|
||||
if (this.spawnEntryScroll.hasSelected()) {
|
||||
int selected = Integer.parseInt(this.spawnEntryScroll.getSelected());
|
||||
addButton(new GuiNpcButton(22, guiLeft + 32, y, 20, 20, "-"));
|
||||
GuiNpcTextField num = new GuiNpcTextField(25, this, guiLeft + 60, y += 10, 30, 20, String.valueOf(selected));
|
||||
GuiNpcTextField num = new GuiNpcTextField(25, this, guiLeft + 60, y += 10, 30, 20, "" + selected);
|
||||
num.integersOnly = true;
|
||||
addTextField(num);
|
||||
addButton(new GuiNpcButton(26, guiLeft + 92, y, 100, 20, this.getTitle(this.spawn.spawnCompounds.get(selected))));
|
||||
@@ -215,8 +215,8 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
|
||||
}
|
||||
if (textfield.id == 25 && this.spawnEntryScroll.hasSelected()) {
|
||||
int selected = Integer.parseInt(spawnEntryScroll.getSelected());
|
||||
if (spawnEntryScroll.getList().contains(String.valueOf(textfield.getInteger()))) {
|
||||
textfield.setText(String.valueOf(selected));
|
||||
if (spawnEntryScroll.getList().contains("" + textfield.getInteger())) {
|
||||
textfield.setText("" + selected);
|
||||
return;
|
||||
}
|
||||
NBTTagCompound compound = spawn.spawnCompounds.get(selected);
|
||||
|
||||
@@ -192,7 +192,7 @@ public class AuctionTooltipHandler {
|
||||
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocal("auction.claim.expiresSoon"));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.claim.expires")
|
||||
.replace("%s", String.valueOf(daysLeft)));
|
||||
.replace("%s", "" + daysLeft));
|
||||
}
|
||||
|
||||
tooltip.add("");
|
||||
@@ -238,7 +238,7 @@ public class AuctionTooltipHandler {
|
||||
return amount + " " + AuctionClientConfig.getCurrencyName();
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = String.valueOf(amount);
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) {
|
||||
|
||||
@@ -237,7 +237,7 @@ public class GuiAnvilRecipes extends GuiNPCInterface {
|
||||
fontRendererObj.drawString(percentText, percentTextX, percentTextY, CustomNpcResourceListener.DefaultTextColor);
|
||||
// Add text overlay for percentage with the full unrounded value.
|
||||
if (func_146978_c(percentTextX - guiLeft, percentTextY - guiTop, percentWidth, fontRendererObj.FONT_HEIGHT, mouseX, mouseY)) {
|
||||
textOverlays.add(new TextOverlayData(percentTextX, percentTextY, percentWidth, fontRendererObj.FONT_HEIGHT, String.valueOf(recipe.getRepairPercentage())));
|
||||
textOverlays.add(new TextOverlayData(percentTextX, percentTextY, percentWidth, fontRendererObj.FONT_HEIGHT, "" + recipe.getRepairPercentage()));
|
||||
}
|
||||
|
||||
if (!recipe.availability.isDefault()) {
|
||||
@@ -303,7 +303,7 @@ public class GuiAnvilRecipes extends GuiNPCInterface {
|
||||
int xpBoxWidth = scaledTextWidth;
|
||||
int xpBoxHeight = fontRendererObj.FONT_HEIGHT;
|
||||
if (func_146978_c(xpTextX - guiLeft, xpTextY - guiTop, xpBoxWidth, xpBoxHeight, mouseX, mouseY)) {
|
||||
textOverlays.add(new TextOverlayData(xpTextX, xpTextY, xpBoxWidth, xpBoxHeight, String.valueOf(recipe.getXpCost())));
|
||||
textOverlays.add(new TextOverlayData(xpTextX, xpTextY, xpBoxWidth, xpBoxHeight, "" + recipe.getXpCost()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ public class GuiAnvilRecipes extends GuiNPCInterface {
|
||||
|
||||
private String formatXpCost(int xp) {
|
||||
if (xp < 1000) {
|
||||
return String.valueOf(xp);
|
||||
return "" + xp;
|
||||
}
|
||||
double xpK = xp / 1000.0;
|
||||
if (xpK == (int) xpK) {
|
||||
|
||||
@@ -255,7 +255,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
String bidCountLabel = StatCollector.translateToLocal("auction.info.bidCount");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + bidCountLabel, x, y, 0xFFFFFF);
|
||||
|
||||
label = String.valueOf(listing.bidCount);
|
||||
label = "" + listing.bidCount;
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.WHITE + label, xRight - length, y, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@@ -196,9 +196,9 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
|
||||
/** Format currency with commas (e.g., 1000 -> "1,000") */
|
||||
protected String formatCurrency(long amount) {
|
||||
if (amount < 1000) return String.valueOf(amount);
|
||||
if (amount < 1000) return "" + amount;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = String.valueOf(amount);
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
|
||||
|
||||
@@ -67,7 +67,7 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
// Starting Price label and field
|
||||
addLabel(new GuiNpcLabel(1, "auction.sell.startingPrice", guiLeft + contentX, y + 5, 0xFFFFFF));
|
||||
GuiNpcTextField startingField = new GuiNpcTextField(txtStartingPriceId, this, fontRendererObj,
|
||||
guiLeft + contentX + 80, y, 80, 18, startingPrice > 0 ? String.valueOf(startingPrice) : "");
|
||||
guiLeft + contentX + 80, y, 80, 18, startingPrice > 0 ? "" + startingPrice : "");
|
||||
startingField.setIntegersOnly();
|
||||
addTextField(startingField);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
addLabel(lblBuyout);
|
||||
|
||||
txtBuyout = new GuiNpcTextField(txtBuyoutPriceId, this, fontRendererObj,
|
||||
guiLeft + contentX + 80, y, 80, 18, buyoutPrice > 0 ? String.valueOf(buyoutPrice) : "");
|
||||
guiLeft + contentX + 80, y, 80, 18, buyoutPrice > 0 ? "" + buyoutPrice : "");
|
||||
txtBuyout.setIntegersOnly();
|
||||
addTextField(txtBuyout);
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ public class GuiNPCTrader extends GuiContainerNPCInterface implements IGuiData {
|
||||
|
||||
// Draw stock count to the RIGHT of the trade (after output slot)
|
||||
if (stockEnabled && availableStock[slotIdx] < Integer.MAX_VALUE) {
|
||||
String stockText = String.valueOf(availableStock[slotIdx]);
|
||||
String stockText = "" + availableStock[slotIdx];
|
||||
int stockColor = availableStock[slotIdx] > 0 ? 0x00AA00 : 0xAA0000;
|
||||
fontRendererObj.drawString(stockText, x + OUTPUT_OFFSET + 20, y + 5, stockColor);
|
||||
}
|
||||
@@ -317,10 +317,10 @@ public class GuiNPCTrader extends GuiContainerNPCInterface implements IGuiData {
|
||||
*/
|
||||
private String formatCurrency(long amount) {
|
||||
if (amount < 1000) {
|
||||
return String.valueOf(amount);
|
||||
return "" + amount;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = String.valueOf(amount);
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
// Bid amount field
|
||||
addLabel(new GuiNpcLabel(3, "auction.bid.yourBid", guiLeft + 15, y + 4));
|
||||
GuiNpcTextField bidField = new GuiNpcTextField(txtBidId, this, fontRendererObj,
|
||||
guiLeft + 80, y, 100, 18, String.valueOf(minimumBid));
|
||||
guiLeft + 80, y, 100, 18, "" + minimumBid);
|
||||
bidField.setIntegersOnly();
|
||||
addTextField(bidField);
|
||||
y += 28;
|
||||
@@ -146,9 +146,9 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
}
|
||||
|
||||
private String formatCurrency(long amount) {
|
||||
if (amount < 1000) return String.valueOf(amount);
|
||||
if (amount < 1000) return "" + amount;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = String.valueOf(amount);
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
|
||||
|
||||
@@ -107,9 +107,9 @@ public class SubGuiAuctionBuyNow extends SubGuiInterface {
|
||||
}
|
||||
|
||||
private String formatCurrency(long amount) {
|
||||
if (amount < 1000) return String.valueOf(amount);
|
||||
if (amount < 1000) return "" + amount;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = String.valueOf(amount);
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
|
||||
|
||||
@@ -180,7 +180,7 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC
|
||||
|
||||
if (slot.isTemporary()) {
|
||||
label = StatCollector.translateToLocal("profile.temporary");
|
||||
result = (String.valueOf(slot.isTemporary())).toUpperCase();
|
||||
result = ("" + slot.isTemporary()).toUpperCase();
|
||||
labelColor = 0xfc60dd;
|
||||
resultColor = 0x35fc81;
|
||||
fontRendererObj.drawString(label, xLabel, y, labelColor, false);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
int x = guiLeft + i % 3 * 130 + 15; // First position after "$" label
|
||||
int y = guiTop + i / 3 * 22 + 14;
|
||||
long cost = role.getCurrencyCost(i);
|
||||
GuiNpcTextField field = new GuiNpcTextField(CURRENCY_FIELD_ID_START + i, this, x, y, 36, 16, cost > 0 ? String.valueOf(cost) : "");
|
||||
GuiNpcTextField field = new GuiNpcTextField(CURRENCY_FIELD_ID_START + i, this, x, y, 36, 16, cost > 0 ? "" + cost : "");
|
||||
field.setMaxStringLength(8);
|
||||
field.setIntegersOnly();
|
||||
addTextField(field);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class SubGuiNpcTraderStock extends SubGuiInterface implements ISubGuiList
|
||||
return "-1"; // Mixed values, return unlimited
|
||||
}
|
||||
}
|
||||
return String.valueOf(first);
|
||||
return "" + first;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SubGuiNpcTraderStockSlots extends SubGuiInterface implements ITextf
|
||||
|
||||
// Max stock textfield
|
||||
int maxStock = role.stock.maxStock[i];
|
||||
String value = maxStock < 0 ? "-1" : String.valueOf(maxStock);
|
||||
String value = maxStock < 0 ? "-1" : "" + maxStock;
|
||||
GuiNpcTextField field = new GuiNpcTextField(i, this, fontRendererObj, x + 42, y, 32, 18, value);
|
||||
field.setIntegersOnly();
|
||||
field.setMinMaxDefault(-1, Integer.MAX_VALUE, -1);
|
||||
|
||||
@@ -169,7 +169,7 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
// Move to NPC render position on screen
|
||||
GL11.glTranslatef(npcScreenX, npcScreenY, 50F);
|
||||
GL11.glTranslatef(npcScreenX, npcScreenY, 300F);
|
||||
|
||||
// Apply zoom (scale)
|
||||
GL11.glScalef(-CAMERA_ZOOM, CAMERA_ZOOM, CAMERA_ZOOM);
|
||||
|
||||
@@ -477,7 +477,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
// Dynamically calculate gutter width based on line count digits
|
||||
if (container != null && container.linesCount > 0) {
|
||||
int maxLineNum = container.linesCount;
|
||||
String maxLineStr = String.valueOf(maxLineNum);
|
||||
String maxLineStr = "" + maxLineNum;
|
||||
int digitWidth = ClientProxy.Font.width(maxLineStr);
|
||||
LINE_NUMBER_GUTTER_WIDTH = digitWidth + 10; // 10px total padding (5px left + 5px right)
|
||||
}
|
||||
@@ -645,7 +645,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
// Render LINE GUTTER numbers
|
||||
for (int i = renderStart; i <= renderEnd; i++) {
|
||||
int posY = y + (i - scroll.getScrolledLine()) * container.lineHeight + stringYOffset;
|
||||
String lineNum = String.valueOf(i + 1);
|
||||
String lineNum = "" + (i + 1);
|
||||
int lineNumWidth = ClientProxy.Font.width(lineNum);
|
||||
int lineNumX = x + LINE_NUMBER_GUTTER_WIDTH - lineNumWidth - 5; // right-align with 5px padding
|
||||
int lineNumY = posY + 1;
|
||||
|
||||
@@ -361,7 +361,7 @@ public class OverlayKeyPresetViewer {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
GL11.glTranslatef(letterX / scale, nameY / scale, 1);
|
||||
font.drawStringWithShadow(String.valueOf(letter), 0, 0, isDefault ? 0xff8a8a8a : 0xffffffff);
|
||||
font.drawStringWithShadow("" + letter, 0, 0, isDefault ? 0xff8a8a8a : 0xffffffff);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
////////////////////////////////////////////
|
||||
|
||||
@@ -470,7 +470,7 @@ public class GoToLineDialog {
|
||||
// Type character - only allow digits and colon
|
||||
if (ChatAllowedCharacters.isAllowedCharacter(c)) {
|
||||
if (Character.isDigit(c) || c == ':') {
|
||||
insertText(String.valueOf(c));
|
||||
insertText("" + c);
|
||||
markActivity();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ public class RenameRefactorHandler {
|
||||
if (isValidIdentifierChar(c, isFirstChar)) {
|
||||
if (hasSelection) {
|
||||
// Replace entire selection with this character
|
||||
currentWord = String.valueOf(c);
|
||||
currentWord = "" + c;
|
||||
applyLiveRename();
|
||||
callback.setCursorPosition(primaryOccurrenceStart + 1);
|
||||
sel.setSelection(0, 0); // Clear selection
|
||||
|
||||
@@ -7,7 +7,7 @@ public enum EnumScrollData {
|
||||
DIALOG_GROUP,
|
||||
QUEST_GROUP,
|
||||
ABILITY_TYPES,
|
||||
ABILITIES,
|
||||
CUSTOM_ABILITIES,
|
||||
ANIMATIONS,
|
||||
BUILTIN_ANIMATIONS
|
||||
}
|
||||
@@ -0,0 +1,503 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.UserType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Manages player ability data - unlocked abilities, selection, cooldowns, and execution.
|
||||
* Players reference abilities by key (built-in keys or preset names), never customized copies.
|
||||
* <p>
|
||||
* Key differences from NPC DataAbilities:
|
||||
* - Universal cooldown (shared across all abilities)
|
||||
* - Player manually selects ability (no weighted random)
|
||||
* - Conditions requiring a target are skipped
|
||||
* - Uses ability's base cooldownTicks only
|
||||
*/
|
||||
public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
private final PlayerData playerData;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONFIGURATION (saved to NBT)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* List of unlocked ability keys (preset names or built-in keys).
|
||||
* Order matters - determines selection index.
|
||||
*/
|
||||
private List<String> unlockedAbilities = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Currently selected ability index in the unlocked list.
|
||||
*/
|
||||
private int selectedIndex = 0;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// RUNTIME STATE (not saved)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Universal cooldown end time (shared across all abilities).
|
||||
*/
|
||||
private transient long cooldownEndTime = 0;
|
||||
|
||||
/**
|
||||
* Currently executing ability instance (null if none).
|
||||
*/
|
||||
private transient Ability currentAbility;
|
||||
|
||||
/**
|
||||
* Current ability's key (for cooldown tracking after completion).
|
||||
*/
|
||||
private transient String currentAbilityKey;
|
||||
|
||||
/**
|
||||
* Target for the current ability (can be null for self-targeting).
|
||||
*/
|
||||
private transient EntityLivingBase currentTarget;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONSTRUCTOR
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public PlayerAbilityData(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// TICK - Called from player tick handler
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Main tick method - handles ability execution.
|
||||
* Should be called every server tick.
|
||||
*/
|
||||
public void tick(EntityPlayer player) {
|
||||
if (player.worldObj.isRemote || player.isDead) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
tickCurrentAbility(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick the currently executing ability.
|
||||
*/
|
||||
private void tickCurrentAbility(EntityPlayer player) {
|
||||
AbilityPhase oldPhase = currentAbility.getPhase();
|
||||
|
||||
// Tick advances time and possibly changes phase
|
||||
boolean phaseChanged = currentAbility.tick();
|
||||
|
||||
switch (currentAbility.getPhase()) {
|
||||
case WINDUP:
|
||||
currentAbility.onWindUpTick(player, currentTarget, player.worldObj, currentAbility.getCurrentTick());
|
||||
break;
|
||||
|
||||
case ACTIVE:
|
||||
if (phaseChanged && oldPhase == AbilityPhase.WINDUP) {
|
||||
// Just entered ACTIVE phase
|
||||
TelegraphInstance telegraph = currentAbility.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
telegraph.lockPosition();
|
||||
}
|
||||
removeTelegraph(currentAbility, player);
|
||||
|
||||
// Play active sound and animation
|
||||
playAbilitySound(player, currentAbility.getActiveSound());
|
||||
playAbilityAnimation(currentAbility.getActiveAnimation());
|
||||
|
||||
// Call onExecute
|
||||
currentAbility.onExecute(player, currentTarget, player.worldObj);
|
||||
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
currentAbility.onActiveTick(player, currentTarget, player.worldObj, currentAbility.getCurrentTick());
|
||||
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(player);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case DAZED:
|
||||
// Player is dazed - just wait
|
||||
break;
|
||||
|
||||
case IDLE:
|
||||
handleAbilityCompletion(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ability completion.
|
||||
*/
|
||||
private void handleAbilityCompletion(EntityPlayer player) {
|
||||
if (currentAbility == null) return;
|
||||
|
||||
currentAbility.onComplete(player, currentTarget);
|
||||
|
||||
// Apply universal cooldown (using base cooldownTicks only, not min/max random)
|
||||
if (!currentAbility.isIgnoreCooldown()) {
|
||||
cooldownEndTime = player.worldObj.getTotalWorldTime() + currentAbility.getCooldownTicks();
|
||||
}
|
||||
|
||||
// Stop animation
|
||||
stopAbilityAnimation();
|
||||
|
||||
currentAbility = null;
|
||||
currentAbilityKey = null;
|
||||
currentTarget = null;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ABILITY ACTIVATION - Called on Special Key press
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Activate the currently selected ability.
|
||||
* Called when the player presses the Special Key.
|
||||
*
|
||||
* @param player The player
|
||||
* @return true if the ability was started
|
||||
*/
|
||||
public boolean activateAbility(EntityPlayer player) {
|
||||
if (player.worldObj.isRemote) return false;
|
||||
if (unlockedAbilities.isEmpty()) return false;
|
||||
if (selectedIndex < 0 || selectedIndex >= unlockedAbilities.size()) return false;
|
||||
|
||||
String key = unlockedAbilities.get(selectedIndex);
|
||||
return activateAbility(player, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a specific ability by key.
|
||||
*
|
||||
* @param player The player
|
||||
* @param key The ability key (built-in or preset name)
|
||||
* @return true if the ability was started
|
||||
*/
|
||||
public boolean activateAbility(EntityPlayer player, String key) {
|
||||
if (player.worldObj.isRemote || key == null || key.isEmpty()) return false;
|
||||
|
||||
// Can't activate if already executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) return false;
|
||||
|
||||
// Resolve ability from controller
|
||||
if (AbilityController.Instance == null) return false;
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
if (ability == null) return false;
|
||||
|
||||
// Check user type allows player
|
||||
if (!ability.getAllowedBy().allowsPlayer()) return false;
|
||||
|
||||
// Check universal cooldown
|
||||
if (!ability.isIgnoreCooldown() && isOnCooldown(player)) return false;
|
||||
|
||||
// Check conditions (skip target-requiring ones)
|
||||
if (!ability.checkConditionsForPlayer(player)) return false;
|
||||
|
||||
// Start the ability
|
||||
currentAbility = ability;
|
||||
currentAbilityKey = key;
|
||||
currentTarget = null; // Players don't have auto-targets
|
||||
ability.start(null);
|
||||
|
||||
// Spawn telegraph
|
||||
spawnTelegraph(ability, player, null);
|
||||
|
||||
// Play wind up sound and animation
|
||||
playAbilitySound(player, ability.getWindUpSound());
|
||||
playAbilityAnimation(ability.getWindUpAnimation());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CLIENT SYNC
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Sync ability data to the client.
|
||||
* Called when abilities change (unlock/lock/select) and on login.
|
||||
*/
|
||||
public void syncToClient() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
PlayerAbilitySyncPacket.sendToPlayer((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SELECTION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return selectedIndex;
|
||||
}
|
||||
|
||||
public void setSelectedIndex(int index) {
|
||||
if (index >= 0 && index < unlockedAbilities.size()) {
|
||||
this.selectedIndex = index;
|
||||
syncToClient();
|
||||
}
|
||||
}
|
||||
|
||||
public void selectNext() {
|
||||
if (unlockedAbilities.isEmpty()) return;
|
||||
selectedIndex = (selectedIndex + 1) % unlockedAbilities.size();
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
public void selectPrevious() {
|
||||
if (unlockedAbilities.isEmpty()) return;
|
||||
selectedIndex = (selectedIndex - 1 + unlockedAbilities.size()) % unlockedAbilities.size();
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
public String getSelectedAbilityKey() {
|
||||
if (unlockedAbilities.isEmpty() || selectedIndex < 0 || selectedIndex >= unlockedAbilities.size()) {
|
||||
return null;
|
||||
}
|
||||
return unlockedAbilities.get(selectedIndex);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// UNLOCKED ABILITIES
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public List<String> getUnlockedAbilityList() {
|
||||
return unlockedAbilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUnlockedAbilities() {
|
||||
return unlockedAbilities.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public void setUnlockedAbilities(List<String> abilities) {
|
||||
this.unlockedAbilities = abilities != null ? new ArrayList<>(abilities) : new ArrayList<>();
|
||||
// Clamp selected index
|
||||
if (selectedIndex >= unlockedAbilities.size()) {
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
public void unlockAbility(String key) {
|
||||
if (key != null && !key.isEmpty() && !unlockedAbilities.contains(key)) {
|
||||
unlockedAbilities.add(key);
|
||||
syncToClient();
|
||||
}
|
||||
}
|
||||
|
||||
public void lockAbility(String key) {
|
||||
unlockedAbilities.remove(key);
|
||||
if (selectedIndex >= unlockedAbilities.size()) {
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
public boolean hasUnlockedAbility(String key) {
|
||||
return unlockedAbilities.contains(key);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// COOLDOWNS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public boolean isOnCooldown(EntityPlayer player) {
|
||||
return player.worldObj.getTotalWorldTime() < cooldownEndTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a specific ability key is on cooldown.
|
||||
* Currently uses universal cooldown (same for all abilities).
|
||||
*/
|
||||
public boolean isOnCooldown(String key, EntityPlayer player) {
|
||||
return isOnCooldown(player);
|
||||
}
|
||||
|
||||
public long getRemainingCooldown(EntityPlayer player) {
|
||||
long remaining = cooldownEndTime - player.worldObj.getTotalWorldTime();
|
||||
return remaining > 0 ? remaining : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset cooldown for a specific ability key.
|
||||
* Currently resets the universal cooldown.
|
||||
*/
|
||||
public void resetCooldown(String key) {
|
||||
cooldownEndTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cooldowns.
|
||||
*/
|
||||
public void resetAllCooldowns() {
|
||||
cooldownEndTime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateAbility() {
|
||||
return activateAbility(playerData.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateAbility(String key) {
|
||||
return activateAbility(playerData.player, key);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// STATE QUERIES
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public boolean isExecutingAbility() {
|
||||
return currentAbility != null && currentAbility.isExecuting();
|
||||
}
|
||||
|
||||
public Ability getCurrentAbility() {
|
||||
return currentAbility;
|
||||
}
|
||||
|
||||
public void interruptCurrentAbility() {
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
currentAbility.interrupt();
|
||||
stopAbilityAnimation();
|
||||
currentAbility = null;
|
||||
currentAbilityKey = null;
|
||||
currentTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnCooldown() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return isOnCooldown(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnCooldown(String key) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return isOnCooldown(key, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetCooldown() {
|
||||
cooldownEndTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player's movement should be locked due to an executing ability.
|
||||
* Used by the tick handler to restrict player movement during ability phases.
|
||||
*/
|
||||
public boolean isMovementLocked() {
|
||||
return currentAbility != null && currentAbility.isExecuting()
|
||||
&& currentAbility.isMovementLockedForCurrentPhase();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// TELEGRAPH
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
private void spawnTelegraph(Ability ability, EntityPlayer player, EntityLivingBase target) {
|
||||
TelegraphInstance telegraph = ability.createTelegraph(player, target);
|
||||
if (telegraph != null) {
|
||||
ability.setTelegraphInstance(telegraph);
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
TelegraphSpawnPacket.sendToTracking(telegraph, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeTelegraph(Ability ability, EntityPlayer player) {
|
||||
TelegraphInstance telegraph = ability.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
TelegraphRemovePacket.sendToTracking(telegraph.getInstanceId(), player);
|
||||
}
|
||||
ability.setTelegraphInstance(null);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ANIMATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
private void playAbilityAnimation(Animation animation) {
|
||||
if (animation == null || AnimationController.Instance == null) return;
|
||||
playerData.animationData.setEnabled(true);
|
||||
playerData.animationData.setAnimation(animation);
|
||||
playerData.animationData.updateClient();
|
||||
}
|
||||
|
||||
private void stopAbilityAnimation() {
|
||||
playerData.animationData.setAnimation(null);
|
||||
playerData.animationData.updateClient();
|
||||
}
|
||||
|
||||
private void playAbilitySound(EntityPlayer player, String sound) {
|
||||
if (sound != null && !sound.isEmpty()) {
|
||||
player.worldObj.playSoundAtEntity(player, sound, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT SERIALIZATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (String key : unlockedAbilities) {
|
||||
list.appendTag(new NBTTagString(key));
|
||||
}
|
||||
compound.setTag("PlayerAbilities", list);
|
||||
compound.setInteger("PlayerAbilitySelected", selectedIndex);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
unlockedAbilities.clear();
|
||||
if (compound.hasKey("PlayerAbilities")) {
|
||||
NBTTagList list = compound.getTagList("PlayerAbilities", 8); // 8 = string tag
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
String key = list.getStringTagAt(i);
|
||||
if (key != null && !key.isEmpty()) {
|
||||
unlockedAbilities.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
selectedIndex = compound.getInteger("PlayerAbilitySelected");
|
||||
if (selectedIndex >= unlockedAbilities.size()) {
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.IPlayerBankData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
@@ -65,6 +66,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
// Trade data (currency + auction claims) - shared across all profile slots
|
||||
public PlayerTradeData tradeData = new PlayerTradeData(this);
|
||||
|
||||
public PlayerAbilityData abilityData = new PlayerAbilityData(this);
|
||||
public ActionManager actionManager = new ActionManager();
|
||||
public PlayerDataScript scriptData;
|
||||
|
||||
@@ -108,6 +110,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
if (!controller.playerEffects.containsKey(playerID)) {
|
||||
controller.playerEffects.put(playerID, effectData.getEffects());
|
||||
}
|
||||
|
||||
// Sync player ability data to client
|
||||
abilityData.syncToClient();
|
||||
}
|
||||
|
||||
public void onLogout() {
|
||||
@@ -137,6 +142,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
effectData.readFromNBT(data);
|
||||
magicData.readToNBT(data);
|
||||
tradeData.readFromNBT(data);
|
||||
abilityData.readFromNBT(data);
|
||||
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -180,6 +186,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
effectData.writeToNBT(compound);
|
||||
magicData.writeToNBT(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
abilityData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
@@ -411,6 +418,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
public IPlayerAbilityData getAbilityData() {
|
||||
return abilityData;
|
||||
}
|
||||
|
||||
public synchronized void save() {
|
||||
// Don't Save this is a Modification of a Profile's PlayerData
|
||||
Profile profile = ProfileController.Instance.getProfile(UUID.fromString(uuid));
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package noppes.npcs.scripted.event.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.event.IPlayerAbilityEvent;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
/**
|
||||
* Events fired during player ability execution lifecycle.
|
||||
*/
|
||||
public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEvent {
|
||||
protected final Ability ability;
|
||||
protected final IEntityLivingBase target;
|
||||
|
||||
public PlayerAbilityEvent(IPlayer player, Ability ability, EntityLivingBase target) {
|
||||
super(player);
|
||||
this.ability = ability;
|
||||
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getAbility() {
|
||||
return ability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "playerAbilityEvent";
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a player's ability hits an entity with damage.
|
||||
* Canceling prevents the damage from being applied.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class HitEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.HitEvent {
|
||||
private final IEntityLivingBase hitEntity;
|
||||
private float damage;
|
||||
private float knockback;
|
||||
private float knockbackUp;
|
||||
|
||||
public HitEvent(IPlayer player, Ability ability, EntityLivingBase target,
|
||||
EntityLivingBase hitEntity, float damage, float knockback, float knockbackUp) {
|
||||
super(player, ability, target);
|
||||
this.hitEntity = hitEntity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(hitEntity) : null;
|
||||
this.damage = damage;
|
||||
this.knockback = knockback;
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getHitEntity() {
|
||||
return hitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockback() {
|
||||
return knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockback(float knockback) {
|
||||
this.knockback = knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackUp() {
|
||||
return knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockbackUp(float knockbackUp) {
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_HIT.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,11 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAbilityReference(String key) {
|
||||
data.addAbilityReference(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAbility(String abilityId) {
|
||||
data.removeAbility(abilityId);
|
||||
@@ -58,6 +63,33 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
return data.getAbility(abilityId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbilityReference(String abilityId) {
|
||||
List<kamkeel.npcs.controllers.data.ability.AbilitySlot> slots = data.getAbilitySlots();
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
kamkeel.npcs.controllers.data.ability.AbilitySlot slot = slots.get(i);
|
||||
if (slot.isReference()) {
|
||||
if (slot.getReferenceId().equals(abilityId)) return true;
|
||||
} else {
|
||||
Ability a = slot.getAbility();
|
||||
if (a != null && a.getId().equals(abilityId)) return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean convertToInline(String abilityId) {
|
||||
List<kamkeel.npcs.controllers.data.ability.AbilitySlot> slots = data.getAbilitySlots();
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
kamkeel.npcs.controllers.data.ability.AbilitySlot slot = slots.get(i);
|
||||
if (slot.isReference() && slot.getReferenceId().equals(abilityId)) {
|
||||
return data.convertToInline(i);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAbilities() {
|
||||
data.clearAbilities();
|
||||
@@ -117,17 +149,14 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executePresetAbility(String presetName) {
|
||||
return executePresetAbility(presetName, null);
|
||||
public boolean executeAbility(String key) {
|
||||
return executeAbility(key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executePresetAbility(String presetName, Object target) {
|
||||
// Resolve target
|
||||
public boolean executeAbility(String key, Object target) {
|
||||
EntityLivingBase targetEntity = resolveTarget(target);
|
||||
|
||||
// Use the direct preset execution method
|
||||
return data.executePresetAbility(presetName, targetEntity);
|
||||
return data.executeAbility(key, targetEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package noppes.npcs.scripted.wrapper;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.controllers.data.PlayerAbilityData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
/**
|
||||
* Script wrapper for PlayerAbilityData providing API access to player abilities.
|
||||
*/
|
||||
public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
private final PlayerAbilityData data;
|
||||
private final PlayerData playerData;
|
||||
|
||||
public ScriptPlayerAbilityData(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
this.data = playerData.abilityData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUnlockedAbilities() {
|
||||
return data.getUnlockedAbilities().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlockAbility(String key) {
|
||||
data.unlockAbility(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockAbility(String key) {
|
||||
data.lockAbility(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnlockedAbility(String key) {
|
||||
return data.hasUnlockedAbility(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSelectedIndex() {
|
||||
return data.getSelectedIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedIndex(int index) {
|
||||
data.setSelectedIndex(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedAbilityKey() {
|
||||
return data.getSelectedAbilityKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectNext() {
|
||||
data.selectNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPrevious() {
|
||||
data.selectPrevious();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExecutingAbility() {
|
||||
return data.isExecutingAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getCurrentAbility() {
|
||||
return data.getCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interruptCurrentAbility() {
|
||||
data.interruptCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnCooldown(String key) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return data.isOnCooldown(key, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetCooldown(String key) {
|
||||
data.resetCooldown(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetAllCooldowns() {
|
||||
data.resetAllCooldowns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateAbility() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return data.activateAbility(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateAbility(String key) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return data.activateAbility(player, key);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user