Completed Tag Support for Auras, Forms, Outlines, Effects, Linked Items, Abilities

This commit is contained in:
Kam committed 2026-03-06 22:03:26 -05:00
1 parent 0eeeec5d22
commit 111156da5a
15 files changed
+503 -5

No files matched your search

@@ -15,6 +15,8 @@ import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.GuiScrollWindow;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.SubGuiTagSelect;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.controllers.data.CustomEffect;
@@ -63,12 +65,14 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
guiTop += 7;
int y = guiTop + 7;
int x = guiLeft + 4 + 4;
addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, x + 36, y, 280, 20, effect.name));
addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, x + 36, y, 210, 20, effect.name));
getTextField(1).setMaxStringLength(40);
addLabel(new GuiNpcLabel(1, "gui.name", x, y + 5));
addLabel(new GuiNpcLabel(-1, "ID", x + 320, y + 1));
addLabel(new GuiNpcLabel(-2, effect.id + "", x + 320, y + 11));
addLabel(new GuiNpcLabel(-1, "ID", x + 250, y + 1));
addLabel(new GuiNpcLabel(-2, effect.id + "", x + 250, y + 11));
addButton(new GuiNpcButton(40, getTextField(1).xPosition + getTextField(1).width + 30, y, 70, 20, "gui.tags"));
y += 23;
@@ -243,6 +247,10 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
PacketClient.sendClient(new EffectSavePacket(effect.writeToNBT(false), originalName));
GuiScriptInterface.open(parent, new EffectScript(effect.id));
}
if (id == 40) {
setSubGui(new SubGuiTagSelect(effect.tagUUIDs));
return;
}
if (id == 10) {
GuiNpcButtonYesNo button = (GuiNpcButtonYesNo) guibutton;
effect.lossOnDeath = button.getBoolean();
@@ -0,0 +1,169 @@
package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.tags.TagsGetPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.IScrollData;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.controllers.TagController;
import noppes.npcs.controllers.data.Tag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
/**
* Reusable SubGui for selecting tags on any taggable object.
* Pass in the current tagUUIDs, get back the modified set on close.
*/
public class SubGuiTagSelect extends SubGuiInterface implements IScrollData, ICustomScrollListener, ITextfieldListener {
private GuiCustomScroll scrollAllTags;
private GuiCustomScroll scrollSelectedTags;
private final ArrayList<String> allTagNames = new ArrayList<>();
private final ArrayList<String> selectedTagNames = new ArrayList<>();
private final HashSet<UUID> tagUUIDs;
private String search = "";
public SubGuiTagSelect(HashSet<UUID> tagUUIDs) {
this.tagUUIDs = tagUUIDs;
setBackground("menubg.png");
xSize = 430;
ySize = 220;
// Populate selected tag names from UUIDs
TagController tc = TagController.getInstance();
if (tc != null) {
for (UUID uuid : tagUUIDs) {
Tag tag = tc.getTagFromUUID(uuid);
if (tag != null) {
selectedTagNames.add(tag.name);
}
}
}
PacketClient.sendClient(new TagsGetPacket());
}
public void initGui() {
super.initGui();
addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.allTags"), guiLeft + 22, guiTop + 11));
if (scrollAllTags == null) {
scrollAllTags = new GuiCustomScroll(this, 0);
scrollAllTags.setSize(150, 155);
}
scrollAllTags.guiLeft = guiLeft + 20;
scrollAllTags.guiTop = guiTop + 24;
this.addScroll(scrollAllTags);
addTextField(new GuiNpcTextField(4, this, fontRendererObj, guiLeft + 20, guiTop + 24 + 160, 150, 20, search));
addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 252, guiTop + 11));
if (scrollSelectedTags == null) {
scrollSelectedTags = new GuiCustomScroll(this, 1);
scrollSelectedTags.setSize(150, 180);
}
scrollSelectedTags.guiLeft = guiLeft + 250;
scrollSelectedTags.guiTop = guiTop + 24;
scrollSelectedTags.setList(selectedTagNames);
this.addScroll(scrollSelectedTags);
addButton(new GuiNpcButton(10, guiLeft + 185, guiTop + 90, 55, 20, ">"));
addButton(new GuiNpcButton(11, guiLeft + 185, guiTop + 112, 55, 20, "<"));
addButton(new GuiNpcButton(12, guiLeft + 185, guiTop + 140, 55, 20, ">>"));
addButton(new GuiNpcButton(13, guiLeft + 185, guiTop + 162, 55, 20, "<<"));
}
@Override
public void buttonEvent(GuiButton guibutton) {
if (guibutton.id == 10 && scrollAllTags.hasSelected() && !selectedTagNames.contains(scrollAllTags.getSelected())) {
selectedTagNames.add(scrollAllTags.getSelected());
}
if (guibutton.id == 12) {
selectedTagNames.clear();
selectedTagNames.addAll(allTagNames);
}
if (guibutton.id == 11 && scrollSelectedTags.hasSelected()) {
selectedTagNames.remove(scrollSelectedTags.getSelected());
}
if (guibutton.id == 13) {
selectedTagNames.clear();
}
initGui();
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
allTagNames.clear();
allTagNames.addAll(data.keySet());
allTagNames.sort(String.CASE_INSENSITIVE_ORDER);
scrollAllTags.setList(getSearchList());
initGui();
}
@Override
public void save() {
tagUUIDs.clear();
TagController tc = TagController.getInstance();
if (tc != null) {
for (String name : selectedTagNames) {
Tag tag = tc.getTagFromName(name);
if (tag != null) {
tagUUIDs.add(tag.uuid);
}
}
}
}
public void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
if (k == 0 && scrollAllTags != null)
scrollAllTags.mouseClicked(i, j, k);
}
@Override
public void setSelected(String selected) {
if (scrollAllTags != null)
scrollAllTags.setSelected(selected);
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
}
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(4) != null) {
if (search.equals(getTextField(4).getText()))
return;
search = getTextField(4).getText().toLowerCase();
scrollAllTags.setList(getSearchList());
}
}
@Override
public void unFocused(GuiNpcTextField guiNpcTextField) {
}
private List<String> getSearchList() {
if (search.isEmpty()) {
return new ArrayList<>(allTagNames);
}
List<String> list = new ArrayList<>();
for (String name : allTagNames) {
if (name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
}
@@ -8,6 +8,7 @@ import noppes.npcs.controllers.data.AbilityScript;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.SubGuiTagSelect;
import noppes.npcs.client.gui.builder.FieldDef;
import noppes.npcs.client.gui.util.GuiMenuTopButton;
import noppes.npcs.client.gui.util.GuiNpcButton;
@@ -193,6 +194,11 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
}
}
// Tags button on general tab
if (activeTab == TAB_GENERAL) {
sw.addButton(new GuiNpcButton(40, sw.clipWidth - 95, 5, 80, 20, "gui.tags"));
}
// Conditions on target tab — appended after field defs
if (activeTab == TAB_TARGET) {
int condY = renderConditions(sw, builder.getLastBuildY(), builder.getNextLabelId());
@@ -323,6 +329,10 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
GuiScriptInterface.open(parent, new AbilityScript(ability.getId()));
return;
}
if (id == 40) {
setSubGui(new SubGuiTagSelect(ability.getTagUUIDs()));
return;
}
if (id == -1000) {
close();
return;
@@ -12,6 +12,7 @@ import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.CustomNpcResourceListener;
import noppes.npcs.client.renderer.AnimationHelper;
import noppes.npcs.client.gui.SubGuiColorSelector;
import noppes.npcs.client.gui.SubGuiTagSelect;
import net.minecraft.client.gui.GuiScreen;
import noppes.npcs.client.gui.script.GuiScriptInterface;
import noppes.npcs.client.gui.util.GuiButtonBiDirectional;
@@ -159,6 +160,8 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
}
GuiButtonBiDirectional useActionButton = new GuiButtonBiDirectional(6, x + 120, y, 100, 20, useActions, useActionIndex);
addButton(useActionButton);
addButton(new GuiNpcButton(40, x + 230, y, 100, 20, "gui.tags"));
y += spacing;
// Armor Type: BiDirectional button (None, All, Head, Chestplate, Leggings, Boots)
@@ -336,6 +339,9 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
PacketClient.sendClient(new LinkedItemSavePacket(linkedItem.writeToNBT(false), originalName));
GuiScriptInterface.open(this.parent, new LinkedItemScript(linkedItem.id));
return;
} else if (id == 40) {
setSubGui(new SubGuiTagSelect(linkedItem.tagUUIDs));
return;
} else if (id == 20) {
// Open confirmation for version bump.
GuiYesNo guiyesno = new GuiYesNo(this, "Confirm", "Bump version and update all linked items?", 20);
@@ -0,0 +1,102 @@
package noppes.npcs.client.gui.util;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.StatCollector;
import noppes.npcs.controllers.TagController;
import noppes.npcs.controllers.data.Tag;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
/**
* Scroll list that renders CNPC tags next to item names.
* Used in directory/fullscreen GUIs for Forms, Auras, Outlines, etc.
*/
public class GuiCustomScrollTagged extends GuiCustomScroll {
private HashMap<String, HashSet<UUID>> itemTagMap = new HashMap<>();
private boolean showTags = true;
public GuiCustomScrollTagged(GuiScreen parent, int id) {
super(parent, id);
}
public void setItemTagMap(HashMap<String, HashSet<UUID>> tagMap) {
this.itemTagMap = tagMap != null ? tagMap : new HashMap<>();
}
public HashMap<String, HashSet<UUID>> getItemTagMap() {
return itemTagMap;
}
public void setShowTags(boolean show) {
this.showTags = show;
}
@Override
protected void drawItems() {
for (int i = 0; i < list.size(); i++) {
int j = 4;
int k = (14 * i + 4) - scrollY;
if (k >= 4 && k + 12 < ySize) {
int xOffset = scrollHeight < ySize - 8 ? 0 : 10;
String rawEntry = list.get(i);
String displayString = StatCollector.translateToLocal(rawEntry);
String text = "";
float maxWidth = showTags && itemTagMap.containsKey(rawEntry)
? (xSize + xOffset - 8) * 0.5f
: (xSize + xOffset - 8) * 0.8f;
if (fontRendererObj.getStringWidth(displayString) > maxWidth) {
for (int h = 0; h < displayString.length(); h++) {
char c = displayString.charAt(h);
text += c;
if (fontRendererObj.getStringWidth(text) > maxWidth)
break;
}
if (displayString.length() > text.length())
text += "...";
} else {
text = displayString;
}
Integer customColor = colors.get(rawEntry);
if (customColor != null) {
if (!text.isEmpty())
fontRendererObj.drawString(text, j, k, customColor);
} else if ((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
drawVerticalLine(j - 2, k - 4, k + 10, 0xffffffff);
drawVerticalLine(j + xSize - 18 + xOffset, k - 4, k + 10, 0xffffffff);
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k - 3, 0xffffffff);
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k + 10, 0xffffffff);
fontRendererObj.drawString(text, j, k, 0xffffff);
} else if (i == hover) {
fontRendererObj.drawString(text, j, k, 0x00ff00);
} else {
fontRendererObj.drawString(text, j, k, 0xffffff);
}
// Draw tags after item name
if (showTags && itemTagMap.containsKey(rawEntry)) {
int tagStartX = j + fontRendererObj.getStringWidth(text) + 3;
int maxX = j + xSize - 18 + xOffset;
HashSet<UUID> tagUUIDs = itemTagMap.get(rawEntry);
TagController tc = TagController.getInstance();
if (tc != null && tagUUIDs != null) {
for (UUID uuid : tagUUIDs) {
Tag tag = tc.getTagFromUUID(uuid);
if (tag != null && !tag.hideTag) {
String tagText = "[" + tag.name + "]";
int tagWidth = fontRendererObj.getStringWidth(tagText);
if (tagStartX + tagWidth > maxX) break;
fontRendererObj.drawString(tagText, tagStartX, k, tag.color);
tagStartX += tagWidth + 3;
}
}
}
}
}
}
}
}
@@ -1,7 +1,9 @@
package noppes.npcs.client.gui.util;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.controllers.TagController;
import noppes.npcs.controllers.data.Category;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
@@ -20,6 +22,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
/**
@@ -32,7 +35,7 @@ public abstract class GuiDirectoryCategorized extends GuiDirectory
// ========== Scrolls ==========
protected GuiCustomScrollIcons catScroll = new GuiCustomScrollIcons(this, 2);
protected GuiCustomScroll itemScroll = new GuiCustomScroll(this, 0);
protected GuiCustomScrollTagged itemScroll = new GuiCustomScrollTagged(this, 0);
// ========== Data ==========
protected HashMap<String, Integer> catData = new HashMap<>();
@@ -463,8 +466,24 @@ public abstract class GuiDirectoryCategorized extends GuiDirectory
if (selectedCatId < 0) return new ArrayList<>();
if (itemSearch.isEmpty()) return new ArrayList<>(itemData.keySet());
List<String> list = new ArrayList<>();
HashMap<String, HashSet<UUID>> tagMap = itemScroll.getItemTagMap();
for (String name : itemData.keySet()) {
if (name.toLowerCase().contains(itemSearch)) list.add(name);
if (name.toLowerCase().contains(itemSearch)) {
list.add(name);
} else if (tagMap != null && tagMap.containsKey(name)) {
// Search by tag name — match [tagname] or just tagname
HashSet<UUID> uuids = tagMap.get(name);
TagController tc = TagController.getInstance();
if (tc != null) {
for (UUID uuid : uuids) {
noppes.npcs.controllers.data.Tag tag = tc.getTagFromUUID(uuid);
if (tag != null && tag.name.toLowerCase().contains(itemSearch.replace("[", "").replace("]", ""))) {
list.add(name);
break;
}
}
}
}
}
return list;
}
@@ -693,6 +712,21 @@ public abstract class GuiDirectoryCategorized extends GuiDirectory
@Override
public void setGuiData(NBTTagCompound compound) {
if (compound.hasKey("CategoryTagMap")) {
// Tag map for category items
HashMap<String, HashSet<UUID>> tagMap = new HashMap<>();
NBTTagList entries = compound.getTagList("CategoryTagMap", 10);
for (int i = 0; i < entries.tagCount(); i++) {
NBTTagCompound entry = entries.getCompoundTagAt(i);
String itemName = entry.getString("Name");
HashSet<UUID> uuids = TagController.readTagUUIDs(entry, "Tags");
if (!uuids.isEmpty()) {
tagMap.put(itemName, uuids);
}
}
itemScroll.setItemTagMap(tagMap);
return;
}
onItemReceived(compound);
if (pendingNewItemCatId > 0 && hasSelectedItem() && getSelectedItemId() >= 0) {
sendMovePacket(getSelectedItemId(), pendingNewItemCatId);