Adds config for every single IC2 uum recipe. (EU amount, UUM amount, -1 to disable).
Simple as that.
Tested on IC2_experimental build 116.
Should work on any version, if it doesn't, yell at me.
Java
package makmods.customuumvalues;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.RecipeInputItemStack;
import ic2.api.recipe.RecipeOutput;
import ic2.api.recipe.Recipes;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.Configuration;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = CustomUUMValuesReference.MOD_ID, name = CustomUUMValuesReference.MOD_NAME, version = CustomUUMValuesReference.VERSION, dependencies = "required-after:IC2@[2.0,)")
public class CustomUUMValues {
@Instance(CustomUUMValuesReference.MOD_ID)
public static CustomUUMValues instance;
public static Configuration config;
public static Logger logger;
public static String CONFIG_CATEGORY = "uumvalues";
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
config = new Configuration(event.getSuggestedConfigurationFile());
logger = event.getModLog();
logger.log(Level.INFO, "Pre-Initialization...");
config.load();
}
@EventHandler
public void init(FMLInitializationEvent event) {
logger.log(Level.INFO, "Initialization...");
}
public void clearScannerRecipes() {
Recipes.Scanner.getRecipes().clear();
}
public static final String AMOUNT_EU = "recordedAmountEU";
public static final String AMOUNT_UU = "recordedAmountUU";
public static void addScannerRecipe(ItemStack output, int recordedAmountUU,
int recordedAmountEU) {
if (output == null)
return;
NBTTagCompound metadata = new NBTTagCompound();
metadata.setInteger(AMOUNT_UU, recordedAmountUU);
metadata.setInteger(AMOUNT_EU, recordedAmountEU);
Recipes.Scanner.addRecipe(new RecipeInputItemStack(output), metadata,
new ItemStack[0]);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
logger.log(Level.INFO, "Post-Initialization...");
if (!Loader.isModLoaded("IC2"))
throw new RuntimeException("IC2 isn't installed.");
Map<IRecipeInput, RecipeOutput> immutableScannerCopy = Maps
.newHashMap();
immutableScannerCopy.putAll(Recipes.Scanner.getRecipes());
logger.info("Clearing old scanner recipes...");
clearScannerRecipes();
for (Entry<IRecipeInput, RecipeOutput> r : immutableScannerCopy
.entrySet()) {
try {
if (r.getKey().getInputs().size() != 1) {
logger.log(Level.SEVERE, "Recipe is invalid, continuing...");
continue;
}
ItemStack output = r.getKey().getInputs().get(0);
if (output == null) {
logger.log(Level.SEVERE, "Recipe is invalid, continuing...");
continue;
}
NBTTagCompound alreadyExisted = r.getValue().metadata;
int alreadyExistedEU = alreadyExisted.getInteger(AMOUNT_EU);
int alreadyExistedUU = alreadyExisted.getInteger(AMOUNT_UU);
String name = output.getUnlocalizedName().replace("item.", "")
.replace("tile.", "").replace(".name", "");
int eu = config.get(CONFIG_CATEGORY, name + "Eu",
alreadyExistedEU).getInt();
int uu = config.get(CONFIG_CATEGORY, name + "Uu",
alreadyExistedUU).getInt();
if (eu > 0 && uu > 0) {
logger.info(String.format(
"Re-adding scanner recipe for %s, EU: %d, UU: %d",
name, eu, uu));
addScannerRecipe(output.copy(), uu, eu);
}
} catch (Throwable t) {
logger.severe("Exception occured! Whoops!");
t.printStackTrace();
}
}
config.save();
}
}
Display More
package makmods.customuumvalues;
public class CustomUUMValuesReference {
public static final String MOD_NAME = "Custom UUM Values";
public static final String MOD_ID = "CustomUUMValues";
public static final String VERSION = "v1.2";
}