Merge branch 'dev' into syntax-highlighter-unified

This commit is contained in:
Kam committed 2026-03-06 22:03:52 -05:00
commit 5669fe2fda
19 files changed
+529 -16

No files matched your search

@@ -25,6 +25,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -657,6 +658,18 @@ public class CustomEffectController implements ICustomEffectHandler {
return map;
}
public HashMap<String, HashSet<UUID>> getItemTagMapForCategory(int catId) {
HashMap<String, HashSet<UUID>> tagMap = new HashMap<>();
List<Integer> itemIds = categoryManager.getItemsInCategory(catId, getCustomEffects().keySet());
for (int itemId : itemIds) {
CustomEffect effect = getCustomEffects().get(itemId);
if (effect != null && !effect.tagUUIDs.isEmpty()) {
tagMap.put(effect.name, effect.tagUUIDs);
}
}
return tagMap;
}
@Override
public ICustomEffect saveEffect(ICustomEffect customEffect) {
if (customEffect.getID() < 0) {
@@ -668,6 +681,7 @@ public class CustomEffectController implements ICustomEffectHandler {
while (hasOther(customEffect.getName(), customEffect.getID()))
customEffect.setName(customEffect.getName() + "_");
TagController.validateTagUUIDs(((CustomEffect) customEffect).tagUUIDs);
getCustomEffects().remove(customEffect.getID());
getCustomEffects().put(customEffect.getID(), (CustomEffect) customEffect);
@@ -20,8 +20,10 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
public class LinkedItemController implements ILinkedItemHandler {
@@ -215,6 +217,7 @@ public class LinkedItemController implements ILinkedItemHandler {
while (hasOther(linkedItem.getName(), linkedItem.getId()))
linkedItem.setName(linkedItem.getName() + "_");
TagController.validateTagUUIDs(((LinkedItem) linkedItem).tagUUIDs);
linkedItems.remove(linkedItem.getId());
linkedItems.put(linkedItem.getId(), (LinkedItem) linkedItem);
saveLinkedItemsMap();
@@ -387,4 +390,16 @@ public class LinkedItemController implements ILinkedItemHandler {
}
return map;
}
public HashMap<String, HashSet<UUID>> getItemTagMapForCategory(int catId) {
HashMap<String, HashSet<UUID>> tagMap = new HashMap<>();
List<Integer> itemIds = categoryManager.getItemsInCategory(catId, linkedItems.keySet());
for (int itemId : itemIds) {
LinkedItem item = linkedItems.get(itemId);
if (item != null && !item.tagUUIDs.isEmpty()) {
tagMap.put(item.name, item.tagUUIDs);
}
}
return tagMap;
}
}
@@ -1,5 +1,8 @@
package noppes.npcs.controllers;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -9,6 +12,9 @@ import noppes.npcs.api.handler.ITagHandler;
import noppes.npcs.api.handler.data.ITag;
import noppes.npcs.controllers.data.Tag;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
@@ -18,6 +24,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -234,4 +241,69 @@ public class TagController implements ITagHandler {
public HashSet<Tag> getAllTags() {
return new HashSet<Tag>(this.tags.values());
}
/**
* Write a set of tag UUIDs to an NBT compound under the given key.
*/
public static void writeTagUUIDs(NBTTagCompound compound, String key, HashSet<UUID> tagUUIDs) {
if (tagUUIDs != null && !tagUUIDs.isEmpty()) {
NBTTagList list = new NBTTagList();
for (UUID uuid : tagUUIDs) {
list.appendTag(new NBTTagString(uuid.toString()));
}
compound.setTag(key, list);
}
}
/**
* Read a set of tag UUIDs from an NBT compound under the given key.
*/
public static HashSet<UUID> readTagUUIDs(NBTTagCompound compound, String key) {
HashSet<UUID> uuids = new HashSet<>();
if (compound.hasKey(key)) {
NBTTagList list = compound.getTagList(key, 8);
for (int i = 0; i < list.tagCount(); i++) {
try {
uuids.add(UUID.fromString(list.getStringTagAt(i)));
} catch (IllegalArgumentException ignored) {}
}
}
return uuids;
}
/**
* Remove invalid tag UUIDs (those not in the tag registry).
*/
public static void validateTagUUIDs(HashSet<UUID> tagUUIDs) {
TagController tc = getInstance();
if (tc == null) return;
tagUUIDs.removeIf(uuid -> tc.getTagFromUUID(uuid) == null);
}
/**
* Build and send a CategoryTagMap GuiData packet for a set of items.
* @param player the target player
* @param itemTags map of item name -> tag UUIDs (only validated tags are sent)
*/
public static void sendCategoryTagMap(EntityPlayerMP player, HashMap<String, HashSet<UUID>> itemTags) {
NBTTagCompound compound = new NBTTagCompound();
NBTTagList entries = new NBTTagList();
TagController tc = getInstance();
for (Map.Entry<String, HashSet<UUID>> entry : itemTags.entrySet()) {
HashSet<UUID> valid = new HashSet<>();
for (UUID uuid : entry.getValue()) {
if (tc != null && tc.getTagFromUUID(uuid) != null) {
valid.add(uuid);
}
}
if (!valid.isEmpty()) {
NBTTagCompound itemEntry = new NBTTagCompound();
itemEntry.setString("Name", entry.getKey());
writeTagUUIDs(itemEntry, "Tags", valid);
entries.appendTag(itemEntry);
}
}
compound.setTag("CategoryTagMap", entries);
GuiDataPacket.sendGuiData(player, compound);
}
}
@@ -9,8 +9,11 @@ import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.data.ICustomEffect;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.TagController;
import noppes.npcs.scripted.event.player.PlayerEvent;
import java.util.HashSet;
import java.util.UUID;
import java.util.function.Consumer;
public class CustomEffect implements ICustomEffect {
@@ -36,6 +39,8 @@ public class CustomEffect implements ICustomEffect {
public int index = 0;
public HashSet<UUID> tagUUIDs = new HashSet<>();
public CustomEffect() {
}
@@ -261,6 +266,8 @@ public class CustomEffect implements ICustomEffect {
compound.setInteger("iconFrameCount", frameCount);
compound.setInteger("iconFrameTime", frametime);
TagController.writeTagUUIDs(compound, "TagUUIDs", tagUUIDs);
if (saveScripts) {
NBTTagCompound scriptData = new NBTTagCompound();
EffectScript handler = getScriptHandler();
@@ -309,6 +316,8 @@ public class CustomEffect implements ICustomEffect {
if (compound.hasKey("iconFrameTime"))
frametime = Math.max(1, compound.getInteger("iconFrameTime"));
tagUUIDs = TagController.readTagUUIDs(compound, "TagUUIDs");
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
EffectScript handler = new EffectScript();
handler.readFromNBT(compound.getCompoundTag("ScriptData"));
@@ -8,9 +8,13 @@ import noppes.npcs.EventHooks;
import noppes.npcs.api.handler.data.ILinkedItem;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.TagController;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.item.ScriptLinkedItem;
import java.util.HashSet;
import java.util.UUID;
public class LinkedItem implements ILinkedItem {
public static final String LINKED_VERSION_VERSION_TAG = "LinkedVersion";
public static final String LINKED_DATA_NBT_TAG = "LinkedData";
@@ -33,6 +37,8 @@ public class LinkedItem implements ILinkedItem {
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 3: Fits in Head -> Boots slot respectively
public int enchantability;
public HashSet<UUID> tagUUIDs = new HashSet<>();
public LinkedItem() {
this("New");
}
@@ -67,6 +73,8 @@ public class LinkedItem implements ILinkedItem {
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
compound.setInteger("ItemUseAction", this.itemUseAction);
TagController.writeTagUUIDs(compound, "TagUUIDs", tagUUIDs);
if (saveScripts) {
NBTTagCompound scriptData = new NBTTagCompound();
LinkedItemScript handler = getScriptHandler();
@@ -97,6 +105,8 @@ public class LinkedItem implements ILinkedItem {
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
this.itemUseAction = compound.getInteger("ItemUseAction");
tagUUIDs = TagController.readTagUUIDs(compound, "TagUUIDs");
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
LinkedItemScript handler = new LinkedItemScript();
handler.readFromNBT(compound.getCompoundTag("ScriptData"));