Skip to content

Commit

Permalink
Prevented creating item instances of existing identifiers by checking…
Browse files Browse the repository at this point in the history
… for duplicates internally
  • Loading branch information
wothers committed Jun 29, 2023
1 parent dbb2aee commit ebfa6ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/wothers/ift/ItemRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ private ItemRegistry() {
fuelMap = new HashMap<>();
}

public static boolean internalContains(String namespaceName, String itemName) {
return Registry.ITEM.containsId(new Identifier(namespaceName, itemName));
}

public void register(String namespaceName, String itemName, ItemProvider item, String displayName, Boolean isHandheld) {
if (registeredItems.containsKey(namespaceName + ":item/" + itemName)) throw new ItemLoadException(namespaceName, itemName, "Duplicate item");
Registry.register(Registry.ITEM, new Identifier(namespaceName, itemName), item.getItem());
namespaces.add(namespaceName);
registeredItems.put(namespaceName + ":item/" + itemName, isHandheld ? "handheld" : "generated");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/wothers/ift/ItemsFromText.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private void loadItems(File dir) {
String itemName = file.getName().replace(".txt", "");

try {
if (ItemRegistry.internalContains(namespaceName, itemName)) throw new ItemLoadException(namespaceName, itemName, "Duplicate item");
ItemProperties ip = ItemPropertiesFactory.create(newProperties(file), namespaceName, itemName, LOGGER);
ItemProvider item = parseItem(ip);
registerItem(item, ip, namespaceName, itemName, new File(dir, itemName + ".png").getAbsoluteFile());
Expand Down

0 comments on commit ebfa6ab

Please sign in to comment.