From f483fb6ea863841a29eb3935fa7db7c354db8aaf Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 8 Apr 2023 23:46:54 -0400 Subject: [PATCH] Remove duplicate item entries This filters items by name and ID. --- .../java/emu/grasscutter/tools/Dumpers.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/tools/Dumpers.java b/src/main/java/emu/grasscutter/tools/Dumpers.java index 405ea3027..b437a5691 100644 --- a/src/main/java/emu/grasscutter/tools/Dumpers.java +++ b/src/main/java/emu/grasscutter/tools/Dumpers.java @@ -140,13 +140,25 @@ public interface Dumpers { Language.loadTextMaps(); // Convert all known items to an item map. - var dump = new HashMap(); - GameData.getItemDataMap().forEach((id, item) -> dump.put(id, new ItemData( + var originalDump = new ArrayList(); + GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemData(id, Language.getTextMapKey(item.getNameTextMapHash()).get(locale), Quality.from(item.getRankLevel()), item.getItemType(), item.getIcon().length() > 0 ? item.getIcon().substring(3) : "" ))); + // Create a new dump with filtered duplicates. + var names = new ArrayList(); + var dump = new HashMap(); + originalDump.forEach(item -> { + // Validate the item. + if (names.contains(item.name)) return; + if (dump.containsKey(item.id)) return; + // Add the item to the dump. + names.add(item.name); + dump.put(item.id, item); + }); + try { // Create a file for the dump. var file = new File("items.csv"); @@ -185,6 +197,7 @@ public interface Dumpers { @AllArgsConstructor class ItemData { + public Integer id; public String name; public Quality quality; public ItemType type;