More work on IMC stuffs

This commit is contained in:
pahimar 2013-07-10 21:04:18 -04:00
parent 32ff63be6b
commit 7da16caa44
2 changed files with 39 additions and 21 deletions

View file

@ -1,7 +1,6 @@
package com.pahimar.ee3; package com.pahimar.ee3;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -31,7 +30,6 @@ import com.pahimar.ee3.core.util.LogHelper;
import com.pahimar.ee3.core.util.VersionHelper; import com.pahimar.ee3.core.util.VersionHelper;
import com.pahimar.ee3.creativetab.CreativeTabEE3; import com.pahimar.ee3.creativetab.CreativeTabEE3;
import com.pahimar.ee3.emc.DynEMC; import com.pahimar.ee3.emc.DynEMC;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.ModItems; import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes; import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
import com.pahimar.ee3.lib.Reference; import com.pahimar.ee3.lib.Reference;
@ -169,7 +167,7 @@ public class EquivalentExchange3 {
// Quick test to see that sending an encoded recipe to be added to the recipe registry works // Quick test to see that sending an encoded recipe to be added to the recipe registry works
NBTTagCompound encodedItemStack = NBTHelper.encodeRecipeAsNBT(new ItemStack(Item.bucketWater), Arrays.asList(new ItemStack(Item.bucketEmpty), new ItemStack(Block.waterStill))); NBTTagCompound encodedItemStack = NBTHelper.encodeRecipeAsNBT(new ItemStack(Item.bucketWater), Arrays.asList(new ItemStack(Item.bucketEmpty), new ItemStack(Block.waterStill)));
FMLInterModComms.sendMessage(Reference.MOD_ID, Strings.IMC_ADD_RECIPE_KEY, encodedItemStack); FMLInterModComms.sendMessage(Reference.MOD_ID, Strings.IMC_ADD_RECIPE_KEY, encodedItemStack.toString());
} }
@PostInit @PostInit

View file

@ -3,7 +3,6 @@ package com.pahimar.ee3.core.handlers;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import com.pahimar.ee3.core.util.LogHelper; import com.pahimar.ee3.core.util.LogHelper;
@ -25,7 +24,7 @@ public class InterModCommsHandler {
processAddRecipeMessage(imcMessage); processAddRecipeMessage(imcMessage);
} }
else if (imcMessage.key.equalsIgnoreCase(Strings.IMC_ADD_BLACKLIST_ENTRY)) { else if (imcMessage.key.equalsIgnoreCase(Strings.IMC_ADD_BLACKLIST_ENTRY)) {
// TODO Handle EMC blacklist IMC messages processAddEMCBlacklist(imcMessage);
} }
else if (imcMessage.key.equalsIgnoreCase(Strings.IMC_SET_EMC_VALUE)) { else if (imcMessage.key.equalsIgnoreCase(Strings.IMC_SET_EMC_VALUE)) {
processSetEMCValueMessage(imcMessage); processSetEMCValueMessage(imcMessage);
@ -35,13 +34,8 @@ public class InterModCommsHandler {
private static void processAddRecipeMessage(IMCMessage imcMessage) { private static void processAddRecipeMessage(IMCMessage imcMessage) {
if (imcMessage.getMessageType() == String.class) { if (imcMessage.getMessageType() == NBTTagCompound.class) {
// TODO Verify if the string we received is a valid encoded string
}
else if (imcMessage.getMessageType() == ItemStack.class) {
LogHelper.severe("Mod: '" + imcMessage.getSender() + "' attempting to add a recipe to the recipe registry via InterModCommunications with an invalid argument: ItemStack (expected String or NBTTagCompound)");
}
else if (imcMessage.getMessageType() == NBTTagCompound.class) {
NBTTagCompound encodedRecipe = imcMessage.getNBTValue(); NBTTagCompound encodedRecipe = imcMessage.getNBTValue();
Map<CustomWrappedStack, List<CustomWrappedStack>> decodedRecipe = NBTHelper.decodeRecipeFromNBT(encodedRecipe); Map<CustomWrappedStack, List<CustomWrappedStack>> decodedRecipe = NBTHelper.decodeRecipeFromNBT(encodedRecipe);
@ -49,25 +43,51 @@ public class InterModCommsHandler {
if (!decodedRecipe.isEmpty()) { if (!decodedRecipe.isEmpty()) {
for (CustomWrappedStack key : decodedRecipe.keySet()) { for (CustomWrappedStack key : decodedRecipe.keySet()) {
RecipeRegistry.getInstance().addRecipe(key, decodedRecipe.get(key)); RecipeRegistry.getInstance().addRecipe(key, decodedRecipe.get(key));
LogHelper.info("Mod: '" + imcMessage.getSender() + "' added recipe with output '" + key.toString() + "' and inputs '" + decodedRecipe.get(key) + "'"); LogHelper.info("Mod '" + imcMessage.getSender() + "' added recipe with output '" + key.toString() + "' and inputs '" + decodedRecipe.get(key) + "'");
} }
} }
else { else {
LogHelper.severe("Mod: '" + imcMessage.getSender() + "' attempting to add a NBT encoded recipe to the recipe registry via InterModCommunications, but the encoded recipe is invalid"); LogHelper.severe("Mod '" + imcMessage.getSender() + "' attempting to add a NBT encoded recipe to the recipe registry via InterModCommunications, but the encoded recipe is invalid");
} }
} }
else {
LogHelper.severe("Mod '" + imcMessage.getSender() + "' attempting to add a recipe to the recipe registry via InterModCommunications with an invalid argument type (received " + imcMessage.getMessageType().getSimpleName() + ", expected NBTTagCompound)");
}
}
private static void processAddEMCBlacklist(IMCMessage imcMessage) {
if (imcMessage.getMessageType() == NBTTagCompound.class) {
// NBTTagCompound encodedRecipe = imcMessage.getNBTValue();
//
// if (VALID_EMC_ASSIGNMENT) {
// LogHelper.info("Mod '" + imcMessage.getSender() + "' added '" + OBJECT + "' to the EMC blacklist'");
// }
// else {
// LogHelper.severe("Mod '" + imcMessage.getSender() + "' attempting to add to the EMC blacklist via InterModCommunications, but the encoded value assignment is invalid");
// }
}
else {
LogHelper.severe("Mod '" + imcMessage.getSender() + "' attempting to add to the EMC blacklist via InterModCommunications with an invalid argument type (received " + imcMessage.getMessageType().getSimpleName() + ", expected NBTTagCompound)");
}
} }
private static void processSetEMCValueMessage(IMCMessage imcMessage) { private static void processSetEMCValueMessage(IMCMessage imcMessage) {
if (imcMessage.getMessageType() == String.class) { if (imcMessage.getMessageType() == NBTTagCompound.class) {
// TODO Verify if the string we received is a valid encoded string
// NBTTagCompound encodedRecipe = imcMessage.getNBTValue();
//
// if (VALID_EMC_ASSIGNMENT) {
// LogHelper.info("Mod '" + imcMessage.getSender() + "' set EMC value '" + EMC_VALUE + "' to object '" + OBJECT + "'");
// }
// else {
// LogHelper.severe("Mod '" + imcMessage.getSender() + "' attempting to set an EMC value via InterModCommunications, but the encoded value assignment is invalid");
// }
} }
else if (imcMessage.getMessageType() == ItemStack.class) { else {
LogHelper.severe("Mod: '" + imcMessage.getSender() + "' attempting to set an EMC value via InterModCommunications with an invalid argument: ItemStack (expected String or NBTTagCompound)"); LogHelper.severe("Mod '" + imcMessage.getSender() + "' attempting to set an EMC value via InterModCommunications with an invalid argument type (received " + imcMessage.getMessageType().getSimpleName() + ", expected NBTTagCompound)");
}
else if (imcMessage.getMessageType() == NBTTagCompound.class) {
// TODO Handle setting an EMC value with the provided NBTTagCompound
} }
} }
} }