From 26ce6c3452bf71822e960366e2c827b2874fcf08 Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Fri, 19 Sep 2014 13:29:53 +0800 Subject: [PATCH] Added ability to add EIO recipes via Forge IMC. --- .../config/AlloySmelterRecipes_Core.xml | 16 +++++++++++++ .../enderio/config/SAGMillRecipes_Core.xml | 15 ++++++++++++ .../assets/enderio/config/VatRecipes_Core.xml | 16 +++++++++++++ src/main/java/crazypants/enderio/EnderIO.java | 24 +++++++++++++++++++ .../machine/alloy/AlloyRecipeManager.java | 2 ++ .../machine/crusher/CrusherRecipeManager.java | 2 ++ .../machine/still/VatMachineRecipe.java | 2 +- .../enderio/machine/still/VatRecipe.java | 11 +++++++-- .../machine/still/VatRecipeManager.java | 2 ++ 9 files changed, 87 insertions(+), 3 deletions(-) diff --git a/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml b/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml index bd97b552..dcda6c71 100644 --- a/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml +++ b/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml @@ -25,6 +25,22 @@ iron=0.7 food=0.35 sand/cobble/wood=0.1 + +Recipes can also be added using forge IMC messages. For example, in the init method of a mod: + +String recipe = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; +FMLInterModComms.sendMessage("EnderIO", "recipe:alloysmelter", recipe); + --> diff --git a/resources/assets/enderio/config/SAGMillRecipes_Core.xml b/resources/assets/enderio/config/SAGMillRecipes_Core.xml index b3d82cc5..dd7616e0 100644 --- a/resources/assets/enderio/config/SAGMillRecipes_Core.xml +++ b/resources/assets/enderio/config/SAGMillRecipes_Core.xml @@ -69,6 +69,21 @@ +Recipes can also be added using forge IMC messages. For example, in the init method of a mod: + +String recipe = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; +FMLInterModComms.sendMessage("EnderIO", "recipe:sagmill", recipe); + --> diff --git a/resources/assets/enderio/config/VatRecipes_Core.xml b/resources/assets/enderio/config/VatRecipes_Core.xml index 7e0c5992..bfcfcd2d 100644 --- a/resources/assets/enderio/config/VatRecipes_Core.xml +++ b/resources/assets/enderio/config/VatRecipes_Core.xml @@ -11,6 +11,22 @@ Produce: output fluid volume (mb) = IM * inputFluid.multiplier * 1000. The vat always uses 1 MJ per tick, so energy cost also equates to duration. + +Recipes can also be added using forge IMC messages. For example, in the init method of a mod: +String recipe = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; +FMLInterModComms.sendMessage("EnderIO", "recipe:vat", recipe); + --> diff --git a/src/main/java/crazypants/enderio/EnderIO.java b/src/main/java/crazypants/enderio/EnderIO.java index 7e4e3ba1..f7ea5990 100644 --- a/src/main/java/crazypants/enderio/EnderIO.java +++ b/src/main/java/crazypants/enderio/EnderIO.java @@ -3,6 +3,9 @@ package crazypants.enderio; import static crazypants.enderio.EnderIO.MODID; import static crazypants.enderio.EnderIO.MOD_NAME; import static crazypants.enderio.EnderIO.VERSION; + +import com.google.common.collect.ImmutableList; + import net.minecraft.block.material.Material; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -20,10 +23,12 @@ import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInterModComms; +import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartedEvent; import cpw.mods.fml.common.event.FMLServerStoppedEvent; +import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.relauncher.Side; @@ -120,6 +125,7 @@ import crazypants.enderio.material.ItemMachinePart; import crazypants.enderio.material.ItemMaterial; import crazypants.enderio.material.ItemPowderIngot; import crazypants.enderio.material.MaterialRecipes; +import crazypants.enderio.nei.SagMillRecipeHandler; import crazypants.enderio.network.MessageTileNBT; import crazypants.enderio.network.PacketHandler; import crazypants.enderio.teleport.BlockTravelAnchor; @@ -518,6 +524,24 @@ public class EnderIO { } } } + + @EventHandler + public void onImc(IMCEvent evt) { + ImmutableList messages = evt.getMessages(); + for(IMCMessage msg : messages) { + if(msg.isStringMessage()) { + String key = msg.key; + String value = msg.getStringValue(); + if(VatRecipeManager.IMC_KEY.equals(key)) { + VatRecipeManager.getInstance().addCustumRecipes(value); + } else if(CrusherRecipeManager.IMC_KEY.equals(key)) { + CrusherRecipeManager.getInstance().addCustomRecipes(value); + } else if(AlloyRecipeManager.IMC_KEY.equals(key)) { + AlloyRecipeManager.getInstance().addCustumRecipes(value); + } + } + } + } @EventHandler public void serverStarted(FMLServerStartedEvent event) { diff --git a/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java b/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java index 90eea154..99abfe72 100644 --- a/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java +++ b/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java @@ -28,6 +28,8 @@ import crazypants.util.Util; public class AlloyRecipeManager extends ManyToOneRecipeManager { + public static final String IMC_KEY = "recipe:alloysmelter"; + private static final String CORE_FILE_NAME = "AlloySmelterRecipes_Core.xml"; private static final String CUSTOM_FILE_NAME = "AlloySmelterRecipes_User.xml"; diff --git a/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java b/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java index f1291528..8258a9b4 100644 --- a/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java +++ b/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java @@ -24,6 +24,8 @@ import crazypants.util.Util; public class CrusherRecipeManager { + public static final String IMC_KEY = "recipe:sagmill"; + public static final int ORE_ENERGY_COST = 400; public static final int INGOT_ENERGY_COST = 240; diff --git a/src/main/java/crazypants/enderio/machine/still/VatMachineRecipe.java b/src/main/java/crazypants/enderio/machine/still/VatMachineRecipe.java index d67b3a5b..7373cc2a 100644 --- a/src/main/java/crazypants/enderio/machine/still/VatMachineRecipe.java +++ b/src/main/java/crazypants/enderio/machine/still/VatMachineRecipe.java @@ -45,7 +45,7 @@ public class VatMachineRecipe extends AbstractMachineRecipe { result.add(new MachineRecipeInput(0, inputFluidStack)); for (MachineRecipeInput ri : inputs) { - if(!ri.isFluid()) { + if(!ri.isFluid() && ri.item != null) { ItemStack st = ri.item.copy(); st.stackSize = rec.getNumConsumed(ri.item); result.add(new MachineRecipeInput(ri.slotNumber, st)); diff --git a/src/main/java/crazypants/enderio/machine/still/VatRecipe.java b/src/main/java/crazypants/enderio/machine/still/VatRecipe.java index 3cbabdc5..20701ffe 100644 --- a/src/main/java/crazypants/enderio/machine/still/VatRecipe.java +++ b/src/main/java/crazypants/enderio/machine/still/VatRecipe.java @@ -20,6 +20,7 @@ public class VatRecipe implements IRecipe { protected final RecipeInput[] inputs; protected final RecipeOutput[] output; protected final int energyRequired; + private int requiredItems; public VatRecipe(IRecipe recipe) { List fluids = recipe.getInputFluidStacks(); @@ -43,6 +44,13 @@ public class VatRecipe implements IRecipe { output = new RecipeOutput[] { new RecipeOutput(outputFluidStack) }; energyRequired = recipe.getEnergyRequired(); + + requiredItems = 1; + for (RecipeInput ri : inputs) { + if(!ri.isFluid() && ri.getSlotNumber() == 1) { + requiredItems = 2; + } + } } @@ -118,8 +126,7 @@ public class VatRecipe implements IRecipe { } } } - - return found == 3; + return found == requiredItems + 1; } diff --git a/src/main/java/crazypants/enderio/machine/still/VatRecipeManager.java b/src/main/java/crazypants/enderio/machine/still/VatRecipeManager.java index 559183b7..08e8a10b 100644 --- a/src/main/java/crazypants/enderio/machine/still/VatRecipeManager.java +++ b/src/main/java/crazypants/enderio/machine/still/VatRecipeManager.java @@ -19,6 +19,8 @@ import crazypants.enderio.machine.recipe.RecipeOutput; public class VatRecipeManager { + public static final String IMC_KEY = "recipe:vat"; + private static final String CORE_FILE_NAME = "VatRecipes_Core.xml"; private static final String CUSTOM_FILE_NAME = "VatRecipes_User.xml";