Added handling of recipe ICM messages.
This commit is contained in:
parent
fa1d7b2839
commit
63d38ceffd
37
common/com/pahimar/ee3/api/RecipeMapping.java
Normal file
37
common/com/pahimar/ee3/api/RecipeMapping.java
Normal 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);
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue