mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-12 08:27:37 +00:00
Improve the way catalyst info is loaded via API (#434)
This commit is contained in:
1 parent
0c5af2b892
commit
bc7efcfce5
3 files changed
+38
-16
No files matched your search
@@ -476,7 +476,6 @@ public class NEIClientConfig {
|
||||
RecipeInfo.load();
|
||||
LayoutManager.load();
|
||||
NEIController.load();
|
||||
RecipeCatalysts.loadCatalystInfo();
|
||||
BookmarkContainerInfo.load();
|
||||
mainNEIConfigLoaded = true;
|
||||
|
||||
@@ -502,6 +501,8 @@ public class NEIClientConfig {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -10,10 +10,8 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
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<CatalystInfo> {
|
||||
|
||||
private final String handlerID;
|
||||
@@ -34,16 +32,21 @@ public class CatalystInfoList extends ForwardingList<CatalystInfo> {
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +132,8 @@ public class RecipeCatalysts {
|
||||
recipeCatalystMap.clear();
|
||||
URL handlerUrl = RecipeCatalysts.class.getResource("/assets/nei/csv/catalysts.csv");
|
||||
|
||||
resolveAdderQueue();
|
||||
|
||||
URL url;
|
||||
if (fromJar) {
|
||||
url = handlerUrl;
|
||||
@@ -208,13 +210,23 @@ public class RecipeCatalysts {
|
||||
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<String, CatalystInfoList> entry : catalystsAdderFromAPI.entrySet()) {
|
||||
String handlerID = entry.getKey();
|
||||
for (CatalystInfo catalyst : entry.getValue()) {
|
||||
@@ -243,6 +255,9 @@ public class RecipeCatalysts {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void resolveRemoverQueue() {
|
||||
for (Map.Entry<String, List<ItemStack>> entry : catalystsRemoverFromAPI.entrySet()) {
|
||||
String handlerID = entry.getKey();
|
||||
if (recipeCatalystMap.containsKey(handlerID)) {
|
||||
@@ -258,8 +273,6 @@ public class RecipeCatalysts {
|
||||
entry.getValue().forEach(catalysts::remove);
|
||||
}
|
||||
}
|
||||
|
||||
updatePosition(getHeight(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,8 +288,13 @@ public class RecipeCatalysts {
|
||||
}
|
||||
|
||||
public static void addOrPut(Map<String, CatalystInfoList> map, String handlerID, CatalystInfo catalyst) {
|
||||
addOrPut(map, handlerID, catalyst, false);
|
||||
}
|
||||
|
||||
public static void addOrPut(Map<String, CatalystInfoList> 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));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user