mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-27 15:23:16 +00:00
* Use Recipe generics in more places * Use Recipe generics in even more places * Use Recipe generics for IMCHandler * Turns out I was wrong about the old enum names being used * More Recipe generics for getting recipes * Pass MachineType as constructor parameter up the chain * Minor readability cleanup * Use method to get block name while in external classes * Improve readability of some references to internal enum classes * More missed recipe generics to reduce number of casts * Make sure to check NBT for the recipes, and switch back to for loops from streams
67 lines
3.2 KiB
Java
67 lines
3.2 KiB
Java
package mekanism.common.integration;
|
|
|
|
import java.util.List;
|
|
import mekanism.common.Mekanism;
|
|
import mekanism.common.recipe.RecipeHandler;
|
|
import mekanism.common.recipe.RecipeHandler.Recipe;
|
|
import mekanism.common.recipe.inputs.MachineInput;
|
|
import mekanism.common.recipe.machines.MachineRecipe;
|
|
import mekanism.common.recipe.outputs.MachineOutput;
|
|
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
|
|
|
public class IMCHandler {
|
|
|
|
public void onIMCEvent(List<IMCMessage> messages) {
|
|
for (IMCMessage msg : messages) {
|
|
if (msg.isNBTMessage()) {
|
|
boolean found = false;
|
|
boolean delete = false;
|
|
|
|
String message = msg.key;
|
|
|
|
if (message.equals("ShapedMekanismRecipe") || message.equals("ShapelessMekanismRecipe") || message.equals("DeleteMekanismRecipes") ||
|
|
message.equals("RemoveMekanismRecipes")) {
|
|
Mekanism.logger.warn(msg.getSender() + " tried to send IMC " + message + " which has been deleted. Please notify the mod developer to use JSON recipes.");
|
|
found = true;
|
|
}
|
|
|
|
if (message.startsWith("Delete") || message.startsWith("Remove")) {
|
|
message = message.replace("Delete", "").replace("Remove", "");
|
|
delete = true;
|
|
}
|
|
|
|
for (Recipe<?, ?, ?> type : Recipe.values()) {
|
|
if (message.equalsIgnoreCase(type.getRecipeName() + "Recipe")) {
|
|
handleRecipe(type, msg, delete);
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
Mekanism.logger.error(msg.getSender() + " sent unknown IMC message with key '" + msg.key + ".'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private <INPUT extends MachineInput<INPUT>, OUTPUT extends MachineOutput<OUTPUT>, RECIPE extends MachineRecipe<INPUT, OUTPUT, RECIPE>>
|
|
void handleRecipe(Recipe<INPUT, OUTPUT, RECIPE> type, IMCMessage msg, boolean delete) {
|
|
INPUT input = type.createInput(msg.getNBTValue());
|
|
if (input != null && input.isValid()) {
|
|
RECIPE recipe = type.createRecipe(input, msg.getNBTValue());
|
|
if (recipe != null && recipe.recipeOutput != null) {
|
|
if (delete) {
|
|
RecipeHandler.removeRecipe(type, recipe);
|
|
Mekanism.logger.info(msg.getSender() + " removed recipe of type " + type.getRecipeName() + " from the recipe list.");
|
|
} else {
|
|
RecipeHandler.addRecipe(type, recipe);
|
|
Mekanism.logger.info(msg.getSender() + " added recipe of type " + type.getRecipeName() + " to the recipe list.");
|
|
}
|
|
} else {
|
|
Mekanism.logger.error(msg.getSender() + " attempted to " + (delete ? "remove" : "add") + " recipe of type " + type.getRecipeName() + " with an invalid output.");
|
|
}
|
|
} else {
|
|
Mekanism.logger.error(msg.getSender() + " attempted to " + (delete ? "remove" : "add") + " recipe of type " + type.getRecipeName() + " with an invalid input.");
|
|
}
|
|
}
|
|
} |