package quadrum;

import java.io.File;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;

import net.minecraft.client.Minecraft;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.Side;

import quadrum.client.ResourcePackQuadrum;
import quadrum.lib.data.Effect;
import quadrum.lib.data.EffectDeserializer;
import quadrum.proxy.CommonProxy;

@Mod(modid = "Quadrum", name = "Quadrum", version = "@Version@")
public class Quadrum {

	@SidedProxy(serverSide = "quadrum.proxy.CommonProxy", clientSide = "quadrum.proxy.ClientProxy")
	public static CommonProxy proxy;

	@Mod.Instance("Quadrum")
	public static Quadrum instance;

	public static Gson gson;

	static {
		GsonBuilder gsonBuilder = new GsonBuilder();
		gsonBuilder.registerTypeAdapter(Effect.class, new EffectDeserializer());
		gsonBuilder.setPrettyPrinting();
		gson = gsonBuilder.create();
	}

	public static Logger logger;

	public static File configDir;
	public static File blockDir;
	public static File itemDir;

	public static boolean textureStackTrace;
	public static boolean dumpBlockMap;
	public static boolean dumpItemMap;

	public static void log(Level level, String message, Object... args) {
		logger.log(level, String.format(message, args));
	}

	@Mod.EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		if (event.getSide() == Side.CLIENT)
			Minecraft.getMinecraft().defaultResourcePacks.add(new ResourcePackQuadrum());

		logger = event.getModLog();
		configDir = new File(event.getModConfigurationDirectory(), "Quadrum/");
		blockDir = new File(configDir, "block/");
		itemDir = new File(configDir, "item/");

		if (!blockDir.exists())
			blockDir.mkdirs();

		if (!itemDir.exists())
			itemDir.mkdirs();

		proxy.preInit(event);
	}

	@Mod.EventHandler
	public void postInit(FMLPostInitializationEvent event) {
		proxy.postInit(event);
	}
}

@@ -1959,16 +1959,478 @@
 irs();%0A%0A
+%09%09if (event.getSide() == Side.CLIENT) %7B%0A%09%09%09File textures = new File(configDir, %22textures/%22);%0A%09%09%09File blockTextures = new File(textures, %22blocks/%22);%0A%09%09%09File itemTextures = new File(textures, %22items/%22);%0A%09%09%09File lang = new File(configDir, %22lang/%22);%0A%0A%09%09%09if (!textures.exists())%0A%09%09%09%09textures.mkdirs();%0A%09%09%09if (!blockTextures.exists())%0A%09%09%09%09blockTextures.mkdirs();%0A%09%09%09if (!itemTextures.exists())%0A%09%09%09%09itemTextures.mkdirs();%0A%09%09%09if (!lang.exists())%0A%09%09%09%09lang.mkdirs();%0A%09%09%7D%0A%0A
 %09%09proxy.

create files if they do not exist yet