package com.hea3ven.buildingbricks.core.load;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.eventbus.EventBus;

import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.VersionParser;

import com.hea3ven.buildingbricks.core.ModBuildingBricks;

public class ModContainerBuildingBricks extends DummyModContainer {
	private final ModBuildingBricks instance;
	private final File source;

	public ModContainerBuildingBricks() {
		super(new ModMetadata());

		getMetadata().modId = ModBuildingBricks.MODID;
		getMetadata().name = "Building Bricks";
		getMetadata().description = "A mod about building blocks and building tools.";
		getMetadata().version = ModBuildingBricks.VERSION;
		getMetadata().url = "https://github.com/hea3ven/BuildingBricks";
		getMetadata().authorList = Lists.newArrayList("Hea3veN");
		getMetadata().updateJSON =
				"https://raw.githubusercontent.com/hea3ven/BuildingBricks/master/media/update.json";

		instance = new ModBuildingBricks();

		URL sourceUrl = ModContainerBuildingBricks.class.getProtectionDomain().getCodeSource().getLocation();
		if ("file".equals(sourceUrl.getProtocol()))
			source = new File(sourceUrl.getFile()
					.replace("com/hea3ven/buildingbricks/core/load/ModContainerBuildingBricks.class", ""));
		else if ("jar".equals(sourceUrl.getProtocol()))
			source = new File(sourceUrl.getFile().replace("file:", "").replaceFirst("!.*$", ""));
		else
			source = null;
	}

	@Override
	public Set<ArtifactVersion> getRequirements() {
		return Sets.newHashSet(
				VersionParser.parseVersionReference(ModBuildingBricks.FORGE_DEPENDENCY));
	}

	@Override
	public List<ArtifactVersion> getDependencies() {
		return Lists.newArrayList(
				VersionParser.parseVersionReference(ModBuildingBricks.FORGE_DEPENDENCY));
	}

	@Override
	public File getSource() {
		return source;
	}

	@Override
	public String getGuiClassName() {
		return "com.hea3ven.buildingbricks.core.config.BuildingBricksConfigGuiFactory";
	}

	@Override
	public Class<?> getCustomResourcePackClass() {
		try {
			return Class.forName("net.minecraftforge.fml.client.FMLFileResourcePack", true,
					getClass().getClassLoader());
		} catch (ClassNotFoundException e) {
			return null;
		}
	}

	@Override
	public URL getUpdateUrl() {
		try {
			return new URL(getMetadata().updateJSON);
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public boolean registerBus(EventBus bus, LoadController controller) {
		bus.register(instance);
		return true;
	}
}

@@ -61,16 +61,61 @@
 o.File;%0A
+import java.io.UnsupportedEncodingException;%0A
 import j
@@ -166,16 +166,44 @@
 et.URL;%0A
+import java.net.URLDecoder;%0A
 import j
@@ -1762,38 +1762,49 @@
 ocol()))
+ %7B
 %0A%09%09%09
-source = new File(
+try %7B%0A%09%09%09%09String fileUrl = 
 sourceUr
@@ -1856,29 +1856,176 @@
 (%22!.*$%22, %22%22)
-)
 ;%0A%09%09
+%09%09source = new File(URLDecoder.decode(fileUrl, %22UTF-8%22));%0A%09%09%09%7D catch (UnsupportedEncodingException e) %7B%0A%09%09%09%09throw new RuntimeException(e);%0A%09%09%09%7D%0A%09%09%7D 
 else%0A%09%09%09sour

Fix resources not loading when the game directory has spaces