package ljfa.tntutils;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import ljfa.tntutils.util.LogHelper;
import net.minecraft.block.Block;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry;

public class Config {
    public static Configuration conf;

    public static final String CATEGORY_GENERAL = "general";
    
    public static boolean replaceTNT;
    public static boolean explosionCommand;
    public static boolean spareTileEntities;
    public static String[] blacklistArray;
    public static Set<Block> blacklist = null;
    public static boolean blacklistActive = false;
    public static boolean disableBlockDamage;
    
    public static void loadConfig(File file) {
        if(conf == null)
            conf = new Configuration(file);
        
        conf.load();
        loadValues();
        
        FMLCommonHandler.instance().bus().register(new ChangeHandler());
    }
    
    public static void loadValues() {
        replaceTNT = conf.get(CATEGORY_GENERAL, "preventChainExplosions", true, "Prevent explosions from triggering TNT").setRequiresMcRestart(true).getBoolean();
        explosionCommand = conf.get(CATEGORY_GENERAL, "addExplosionCommand", true, "Adds the \"/explosion\" command").setRequiresMcRestart(true).getBoolean();
        spareTileEntities = conf.get(CATEGORY_GENERAL, "spareTileEntites", false, "Makes explosions not destroy tile entities").getBoolean();
        blacklistArray = conf.get(CATEGORY_GENERAL, "destructionBlacklist", new String[0], "A list of blocks that will never be destroyed by explosions").getStringList();
        disableBlockDamage = conf.get(CATEGORY_GENERAL, "disableBlockDamage", false, "Disables all block damage from explosions").getBoolean();
        //----------------
        if(conf.hasChanged())
            conf.save();
    }
    
    public static void createBlacklistSet() {
        blacklist = new HashSet<Block>();
        for(String name: blacklistArray) {
            String[] parts = name.split(":");
            Block block;
            if(parts.length == 1) {
                block = GameRegistry.findBlock("minecraft", parts[0]);
            } else if(parts.length == 2) {
                block = GameRegistry.findBlock(parts[0], parts[1]);
            } else {
                LogHelper.error("Invalid block name: %s", name);
                continue;
            }
            if(block == null) {
                LogHelper.error("Block not found: %s", name);
            } else {
                blacklist.add(block);
                LogHelper.info("Added block to blacklist: %s", name);
            }
        }
        blacklistActive = blacklist.size() != 0;
    }
    
    /** Reloads the config values upon change */
    public static class ChangeHandler {
        @SubscribeEvent
        public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
            if(event.modID.equals(Reference.MODID)) {
                loadValues();
                createBlacklistSet();
            }
        }
    }
}

@@ -370,58 +370,8 @@
 ent;
-%0Aimport cpw.mods.fml.common.registry.GameRegistry;
 %0A%0Apu
@@ -2132,410 +2132,65 @@
     
-String%5B%5D parts = name.split(%22:%22);%0A            Block block;%0A            if(parts.length == 1) %7B%0A                block = GameRegistry.findBlock(%22minecraft%22, parts%5B0%5D);%0A            %7D else if(parts.length == 2) %7B%0A                block = GameRegistry.findBlock(parts%5B0%5D, parts%5B1%5D);%0A            %7D else %7B%0A                LogHelper.error(%22Invalid block name: %25s%22, name);%0A                continue;%0A            %7D
+Block block = (Block)Block.blockRegistry.getObject(name);
 %0A   
@@ -2369,12 +2369,13 @@
 per.
-info
+debug
 (%22Ad

Use BlockRegistry instead