Added handling of recipe ICM messages.

This commit is contained in:
RedmenNL 2013-11-23 13:40:44 +01:00
parent fa1d7b2839
commit 63d38ceffd
2 changed files with 58 additions and 1 deletions

View file

@ -0,0 +1,37 @@
package com.pahimar.ee3.api;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.pahimar.ee3.item.CustomWrappedStack;
public class RecipeMapping
{
private static Gson gsonSerializer = new Gson();
public final CustomWrappedStack outputWrappedStack;
public final List<CustomWrappedStack> inputWrappedStacks;
public RecipeMapping(CustomWrappedStack outputWrappedStack, List<CustomWrappedStack> inputWrappedStacks) {
this.outputWrappedStack = outputWrappedStack;
this.inputWrappedStacks = inputWrappedStacks;
}
public static RecipeMapping createFromJson(String jsonRecipeMapping) {
try {
return (RecipeMapping) gsonSerializer.fromJson(jsonRecipeMapping, RecipeMapping.class);
}
catch (JsonSyntaxException exception) {
exception.printStackTrace();
// TODO Log something regarding the failed parse
}
return null;
}
public String toJson() {
return gsonSerializer.toJson(this);
}
}

View file

@ -1,16 +1,19 @@
package com.pahimar.ee3.imc;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.item.ItemStack;
import com.google.common.collect.ImmutableList;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.api.RecipeMapping;
import com.pahimar.ee3.api.StackValueMapping;
import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.emc.EmcValue;
import com.pahimar.ee3.emc.EmcValuesIMC;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.crafting.RecipesIMC;
import com.pahimar.ee3.lib.Reference;
import cpw.mods.fml.common.IScheduledTickHandler;
@ -60,7 +63,24 @@ public class InterModCommsHandler implements ITickHandler, IScheduledTickHandler
private static void processAddRecipeMessage(IMCMessage imcMessage) {
// TODO
if (imcMessage.getMessageType() == String.class) {
RecipeMapping recipeMapping = RecipeMapping.createFromJson(imcMessage.getStringValue());
if (recipeMapping != null) {
CustomWrappedStack outputWrappedStack = recipeMapping.outputWrappedStack;
List<CustomWrappedStack> inputWrappedStacks = recipeMapping.inputWrappedStacks;
RecipesIMC.addRecipe(outputWrappedStack, inputWrappedStacks);
}
else {
// TODO Log that the message payloads json was invalid
}
}
else {
// TODO Log that the message payload is of an invalid type
}
}
private static void processAddBlackListMessage(IMCMessage imcMessage) {