diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 34bd9f107..2a44c51ff 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -476,7 +476,6 @@ public static void bootNEI(World world) { RecipeInfo.load(); LayoutManager.load(); NEIController.load(); - RecipeCatalysts.loadCatalystInfo(); BookmarkContainerInfo.load(); mainNEIConfigLoaded = true; @@ -502,6 +501,8 @@ public void run() { } } + RecipeCatalysts.loadCatalystInfo(); + // Set pluginNEIConfigLoaded here before posting the NEIConfigsLoadedEvent. This used to be the other // way around, but apparently if your modpack includes 800 mods the event poster might not return in // time and cause issues when loading a world for a second time as configLoaded is still false. This may diff --git a/src/main/java/codechicken/nei/recipe/CatalystInfoList.java b/src/main/java/codechicken/nei/recipe/CatalystInfoList.java index 255dec19a..219c52fa5 100644 --- a/src/main/java/codechicken/nei/recipe/CatalystInfoList.java +++ b/src/main/java/codechicken/nei/recipe/CatalystInfoList.java @@ -10,10 +10,8 @@ import com.google.common.collect.ForwardingList; -import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIServerUtils; -// Do not directly extend ArrayList, see Effective Java Item 16 public class CatalystInfoList extends ForwardingList { private final String handlerID; @@ -34,16 +32,21 @@ protected List delegate() { } @Override - public boolean add(@Nonnull CatalystInfo catalystInfo) { - if (contains(catalystInfo)) { - NEIClientConfig.logger.info( - String.format( - "catalyst %s is already registered to handler %s", - catalystInfo.getStack().getDisplayName(), - handlerID)); - return false; + public boolean add(@Nonnull CatalystInfo element) { + return doAdd(element); + } + + public boolean add(@Nonnull CatalystInfo catalystInfo, boolean overwrite) { + if (overwrite || !contains(catalystInfo)) { + return add(catalystInfo); } - super.add(catalystInfo); + return false; + } + + private boolean doAdd(@Nonnull CatalystInfo catalystInfo) { + catalystInfoList + .removeIf(c -> NEIServerUtils.areStacksSameTypeCraftingWithNBT(c.getStack(), catalystInfo.getStack())); + catalystInfoList.add(catalystInfo); return true; } diff --git a/src/main/java/codechicken/nei/recipe/RecipeCatalysts.java b/src/main/java/codechicken/nei/recipe/RecipeCatalysts.java index 883d500c0..bd0fb605f 100644 --- a/src/main/java/codechicken/nei/recipe/RecipeCatalysts.java +++ b/src/main/java/codechicken/nei/recipe/RecipeCatalysts.java @@ -132,6 +132,8 @@ public static void loadCatalystInfo() { recipeCatalystMap.clear(); URL handlerUrl = RecipeCatalysts.class.getResource("/assets/nei/csv/catalysts.csv"); + resolveAdderQueue(); + URL url; if (fromJar) { url = handlerUrl; @@ -208,13 +210,23 @@ public static void loadCatalystInfo() { handlerID = handler; } - addOrPut(recipeCatalystMap, handlerID, catalystInfo); + // Prefer info added by API if we're using default jar config. + // If not, user config overwrites it. + addOrPut(recipeCatalystMap, handlerID, catalystInfo, !fromJar); } } catch (Exception e) { NEIClientConfig.logger.warn("Error parsing CSV"); e.printStackTrace(); } + if (fromJar) { + resolveRemoverQueue(); + } + + updatePosition(getHeight(), true); + } + + private static void resolveAdderQueue() { for (Map.Entry entry : catalystsAdderFromAPI.entrySet()) { String handlerID = entry.getKey(); for (CatalystInfo catalyst : entry.getValue()) { @@ -243,6 +255,9 @@ public static void loadCatalystInfo() { } }); } + } + + private static void resolveRemoverQueue() { for (Map.Entry> entry : catalystsRemoverFromAPI.entrySet()) { String handlerID = entry.getKey(); if (recipeCatalystMap.containsKey(handlerID)) { @@ -258,8 +273,6 @@ public static void loadCatalystInfo() { entry.getValue().forEach(catalysts::remove); } } - - updatePosition(getHeight(), true); } /** @@ -275,8 +288,13 @@ public static String getRecipeID(IRecipeHandler handler) { } public static void addOrPut(Map map, String handlerID, CatalystInfo catalyst) { + addOrPut(map, handlerID, catalyst, false); + } + + public static void addOrPut(Map map, String handlerID, CatalystInfo catalyst, + boolean overwrite) { if (map.containsKey(handlerID)) { - map.get(handlerID).add(catalyst); + map.get(handlerID).add(catalyst, overwrite); } else { map.put(handlerID, new CatalystInfoList(handlerID, catalyst)); }