Skip to content

Commit

Permalink
Rename handlerID to handler in IMC catalyst registration
Browse files Browse the repository at this point in the history
This now matches the CSV column
  • Loading branch information
wlhlm committed Jul 2, 2023
1 parent 601e6e2 commit 13b8054
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Again, this needs additional metadata work, either provided by mods themselves,

(values are strings if not specified otherwise)

- **handlerID:** id of the recipe handler for which this catalyst can be used; it's the fully-qualified handler class name in most cases; *required*
- **handler:** id of the recipe handler for which this catalyst can be used; it's the fully-qualified handler class name in most cases; *required*
- **itemName:**, and **nbtInfo:** actual catalyst item; *required*
- **modId:** modid of the mod which includes the catalyst
- **modRequired:** whether the mod specified in `modId` needs to be present in order for NEI to load the catalyst (boolean value; `TRUE`/`FALSE` in CSV)
Expand All @@ -146,7 +146,7 @@ Our version of NEI adds a range of IMC messages for registering handler metadata
The following messages are available:
- **registerHandlerInfo:** NBT IMC message; allowed keys are specified in the handler metadata section
- **removeHandlerInfo:** NBT IMC message; required key: `handler`, ID string of the handler to be removed (usually the fully-qualified name of the handler class)
- **registerCatalystInfo:** NBT IMC message; allowed keys are specified in the catalyst metadata section
- **registerCatalystInfo:** NBT IMC message; allowed keys are specified in the catalyst metadata section; previously, this accepted the tag `handlerID`, which has been renamed to `handler` to unify it with the CSV column name, the old name has been deprecated
- **removeCatalystInfo:** NBT IMC message; required keys: `handlerID` (usually the fully-qualified name of the handler class), `itemName` (optionally specify `nbtInfo` if necessary)

Here is an example of how to send the handler and catalyst metadata via IMC:
Expand Down
47 changes: 31 additions & 16 deletions src/main/java/codechicken/nei/config/IMCHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,17 @@ private static void handleRegisterCatalystInfo(IMCMessage message) {
processedCatalystSenders.add(message.getSender());
}
final NBTTagCompound tag = message.getNBTValue();
final String handlerID = tag.getString("handlerID");
if (handlerID.isEmpty()) {
NEIClientConfig.logger.warn("Missing handlerID for registerCatalystInfo!");
final String handler;
if (tag.hasKey("handlerID")) {
NEIClientConfig.logger.warn(
"Received 'handlerID' for registerCatalystInfo IMC from %s, this is deprecated, please use 'handler' instead",
message.getSender());
handler = tag.getString("handlerID");
} else {
handler = tag.getString("handler");
}
if (handler.isEmpty()) {
NEIClientConfig.logger.warn("Missing handler in registerCatalystInfo IMC from %s!", message.getSender());
return;
}
final String modId = tag.hasKey("modId") ? tag.getString("modId") : null;
Expand All @@ -145,7 +153,7 @@ private static void handleRegisterCatalystInfo(IMCMessage message) {
final String itemName = tag.getString("itemName");
final String nbtInfo = tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null;
if (itemName.isEmpty()) {
NEIClientConfig.logger.warn(String.format("Missing itemName for registerCatalystInfo in `%s`!", handlerID));
NEIClientConfig.logger.warn(String.format("Missing itemName in registerCatalystInfo IMC for %s!", handler));
return;
}
final ItemStack itemStack = NEIServerUtils.getModdedItem(itemName, nbtInfo);
Expand All @@ -155,10 +163,9 @@ private static void handleRegisterCatalystInfo(IMCMessage message) {
}
final int priority = tag.getInteger("priority");

RecipeCatalysts
.addOrPut(RecipeCatalysts.catalystsAdderFromIMC, handlerID, new CatalystInfo(itemStack, priority));
RecipeCatalysts.addOrPut(RecipeCatalysts.catalystsAdderFromIMC, handler, new CatalystInfo(itemStack, priority));
NEIClientConfig.logger
.info(String.format("Added catalyst `%s` to handler %s", itemStack.getDisplayName(), handlerID));
.info(String.format("Added catalyst `%s` to handler %s", itemStack.getDisplayName(), handler));
}

private static void handleRemoveCatalystInfo(IMCMessage message) {
Expand All @@ -169,15 +176,24 @@ private static void handleRemoveCatalystInfo(IMCMessage message) {

NEIClientConfig.logger.info("Processing removeCatalystInfo from " + message.getSender());
final NBTTagCompound tag = message.getNBTValue();
final String handlerID = tag.getString("handlerID");
if (handlerID.isEmpty()) {
NEIClientConfig.logger.warn("Missing handlerID for registerCatalystInfo!");
final String handler;
if (tag.hasKey("handlerID")) {
NEIClientConfig.logger.warn(
"Received 'handlerID' for removeCatalystInfo IMC from %s, this is deprecated, please use 'handler' instead",
message.getSender());
handler = tag.getString("handlerID");
} else {
handler = tag.getString("handler");
}
if (handler.isEmpty()) {
NEIClientConfig.logger.warn("Missing handler in removeCatalystInfo IMC from %s!", message.getSender());
return;
}
final String itemName = tag.getString("itemName");
final String nbtInfo = tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null;
if (itemName.isEmpty()) {
NEIClientConfig.logger.warn(String.format("Missing itemName for removeCatalystInfo in `%s`!", handlerID));
NEIClientConfig.logger
.warn(String.format("Missing 'itemName' in removeCatalystInfo IMC for handler %s!", handler));
return;
}
final ItemStack itemStack = NEIServerUtils.getModdedItem(itemName, nbtInfo);
Expand All @@ -186,14 +202,13 @@ private static void handleRemoveCatalystInfo(IMCMessage message) {
return;
}

if (RecipeCatalysts.catalystsRemoverFromIMC.containsKey(handlerID)) {
RecipeCatalysts.catalystsRemoverFromIMC.get(handlerID).add(itemStack);
if (RecipeCatalysts.catalystsRemoverFromIMC.containsKey(handler)) {
RecipeCatalysts.catalystsRemoverFromIMC.get(handler).add(itemStack);
} else {
RecipeCatalysts.catalystsRemoverFromIMC
.put(handlerID, new ArrayList<>(Collections.singletonList(itemStack)));
RecipeCatalysts.catalystsRemoverFromIMC.put(handler, new ArrayList<>(Collections.singletonList(itemStack)));
}
NEIClientConfig.logger
.info(String.format("Removed catalyst `%s` from handler %s", itemStack.getDisplayName(), handlerID));
.info(String.format("Removed catalyst `%s` from handler %s", itemStack.getDisplayName(), handler));
}

private static void logInvalidMessage(FMLInterModComms.IMCMessage message, String type) {
Expand Down

0 comments on commit 13b8054

Please sign in to comment.