diff --git a/src/main/java/techreborn/compat/ee3/CommandRegen.java b/src/main/java/techreborn/compat/ee3/CommandRegen.java index 01877ca17..0762f0897 100644 --- a/src/main/java/techreborn/compat/ee3/CommandRegen.java +++ b/src/main/java/techreborn/compat/ee3/CommandRegen.java @@ -58,6 +58,7 @@ public class CommandRegen extends CommandBase { commandSender.addChatMessage(new ChatComponentText("Regening EMC Values")); DynamicEnergyValueInitThread.initEnergyValueRegistry(); EnergyValueRegistry.getInstance().setShouldRegenNextRestart(false); + EnergyValueRegistry.getInstance().save(); commandSender.addChatMessage(new ChatComponentText("Syncing all EMC Values")); new CommandSyncEnergyValues().processCommand(commandSender, args); } diff --git a/src/main/java/techreborn/compat/ee3/EmcValues.java b/src/main/java/techreborn/compat/ee3/EmcValues.java index 65fc30746..0459296ac 100644 --- a/src/main/java/techreborn/compat/ee3/EmcValues.java +++ b/src/main/java/techreborn/compat/ee3/EmcValues.java @@ -1,21 +1,130 @@ package techreborn.compat.ee3; +import com.pahimar.ee3.api.exchange.EnergyValue; +import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy; import com.pahimar.ee3.api.exchange.RecipeRegistryProxy; import com.pahimar.ee3.exchange.EnergyValueRegistry; +import com.pahimar.ee3.exchange.OreStack; +import com.pahimar.ee3.exchange.WrappedStack; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; +import ic2.api.recipe.IRecipeInput; +import ic2.api.recipe.RecipeInputFluidContainer; +import ic2.api.recipe.RecipeInputItemStack; +import ic2.api.recipe.RecipeInputOreDict; +import ic2.api.recipe.RecipeOutput; +import ic2.api.recipe.Recipes; +import ic2.core.AdvRecipe; +import ic2.core.AdvShapelessRecipe; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fluids.FluidStack; import techreborn.api.recipe.IBaseRecipeType; import techreborn.api.recipe.RecipeHandler; -import techreborn.command.TechRebornDevCommand; import techreborn.compat.ICompatModule; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + public class EmcValues implements ICompatModule { + public static void addIC2Handlers() { + for (Map.Entry entry : Recipes.macerator.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.compressor.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.extractor.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.metalformerCutting.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.metalformerExtruding.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.metalformerRolling.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.oreWashing.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.centrifuge.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.blockcutter.getRecipes().entrySet()) + sendRecipeEntry(entry); + for (Map.Entry entry : Recipes.blastfurance.getRecipes().entrySet()) + sendRecipeEntry(entry); + + + for (Object recipeObject : CraftingManager.getInstance().getRecipeList()) { + if (recipeObject instanceof AdvRecipe || recipeObject instanceof AdvShapelessRecipe) { + IRecipe recipe = (IRecipe) recipeObject; + if (recipe.getRecipeOutput() != null) { + List recipeInputs = getRecipeInputs(recipe); + if (recipeInputs != null && !recipeInputs.isEmpty()) { + RecipeRegistryProxy.addRecipe(recipe.getRecipeOutput(), recipeInputs); + } + } + } + } + } + + private static void sendRecipeEntry(Map.Entry entry) { + List recipeStackOutputs = entry.getValue().items; + if (recipeStackOutputs.size() == 1) { + ItemStack recipeOutput = recipeStackOutputs.get(0); + if (recipeOutput != null) { + recipeOutput = recipeOutput.copy(); + recipeOutput.setTagCompound(entry.getValue().metadata); + + for (ItemStack recipeInput : entry.getKey().getInputs()) { + if (recipeInput != null) { + recipeInput = recipeInput.copy(); + recipeInput.stackSize = entry.getKey().getAmount(); + + RecipeRegistryProxy.addRecipe(recipeOutput, Arrays.asList(recipeInput)); + } + } + } + } + } + + private static List getRecipeInputs(IRecipe recipe) { + List recipeInputs = new ArrayList(); + + if (recipe instanceof AdvRecipe) { + for (Object object : ((AdvRecipe) recipe).input) { + addInputToList(recipeInputs, object); + } + } else if (recipe instanceof AdvShapelessRecipe) { + for (Object object : ((AdvShapelessRecipe) recipe).input) { + addInputToList(recipeInputs, object); + } + } + + return recipeInputs; + } + + public static void addInputToList(List recipeInputs, Object object) { + if (object instanceof ItemStack) { + ItemStack itemStack = ((ItemStack) object).copy(); + recipeInputs.add(itemStack); + } else if (object instanceof String) { + OreStack stack = new OreStack((String) object); + recipeInputs.add(stack); + } else if (object instanceof IRecipeInput) { + if (object instanceof RecipeInputItemStack) + recipeInputs.add(((RecipeInputItemStack) object).input); + else if (object instanceof RecipeInputOreDict) + recipeInputs.add(new OreStack(((RecipeInputOreDict) object).input)); + else if (object instanceof RecipeInputFluidContainer) + recipeInputs.add(new FluidStack(((RecipeInputFluidContainer) object).fluid, ((RecipeInputFluidContainer) object).amount)); + } + } + @Override public void preInit(FMLPreInitializationEvent event) { @@ -33,6 +142,11 @@ public class EmcValues implements ICompatModule { @Override public void postInit(FMLPostInitializationEvent event) { MinecraftForge.EVENT_BUS.register(this); + addOre("ingotCopper", 128); + addOre("ingotSilver", 1024); + addOre("ingotTin", 256); + addOre("ingotLead", 256); + addIC2Handlers(); } @Override @@ -41,10 +155,17 @@ public class EmcValues implements ICompatModule { event.registerServerCommand(new CommandReload()); } - @SubscribeEvent - public void serverTick(TickEvent.ServerTickEvent event){ + public void serverTick(TickEvent.ServerTickEvent event) { //This should be a fix for the things not saving EnergyValueRegistry.getInstance().setShouldRegenNextRestart(false); } + + private void addOre(String name, float value) { + WrappedStack stack = WrappedStack.wrap(new OreStack(name)); + EnergyValue energyValue = new EnergyValue(value); + + EnergyValueRegistryProxy.addPreAssignedEnergyValue(stack, energyValue); + } + }