Player Abilities

This commit is contained in:
Kam committed 2026-01-30 05:01:54 -05:00
1 parent 601b0d721e
commit 1b8ad4dd90
92 files changed
+2610 -1025

No files matched your search

@@ -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);
}