// Path: src/main/java/xilef11/mc/runesofwizardry_classics/Refs.java
// public final class Refs {
// 	private Refs(){}
// 	public static final String MODID = "runesofwizardry_classics";
// 	public static final String VERSION = "@VERSION@";
// 	public static final String NAME="Runes of Wizardry - Classic Dusts Pack";
// 	public static final String GUI_FACTORY="xilef11.mc.runesofwizardry_classics.client.gui.GuiFactory";
// 	public static final String CLIENT_PROXY = "xilef11.mc.runesofwizardry_classics.proxy.ClientProxy",
// 							   SERVER_PROXY="xilef11.mc.runesofwizardry_classics.proxy.ServerProxy";
// 	public static final String PATTERN_PATH=MODID+":patterns/";
// 	public static final String TEXTURE_PATH=MODID+":";
// 	public static final int TICKS_PER_DAY=24000;
// 	public static final int TPS=20;
// 	public static final class Lang{
// 		private Lang(){}
// 		public static final String RUNE=MODID+".rune";
// 		public static final String CONFIG=MODID+".configuration";
// 		public static final String DEC=RUNE+".decorative";
// 		
// 		public static final class Jei{
// 			private Jei(){}
// 			public static final String JEI=MODID+".jei";
// 			public static final String SPIRIT_SWORD=JEI+".spirit_sword";
// 			public static final String SPIRIT_PICKAXE=JEI+".spirit_pickaxe";
// 		}
// 	}
// }
// 
// Path: src/main/java/xilef11/mc/runesofwizardry_classics/RunesofWizardry_Classics.java
// @Mod(modid = Refs.MODID, version = Refs.VERSION, name=Refs.NAME, guiFactory=Refs.GUI_FACTORY, dependencies = "required-after:runesofwizardry;after:guideapi")
// public class RunesofWizardry_Classics
// {
// 	@SidedProxy(clientSide=Refs.CLIENT_PROXY,serverSide=Refs.SERVER_PROXY)
// 	public static IProxy proxy;
// 	
// 	private static Logger logger;
// 	/**Returns the logger for the mod**/
// 	public static Logger log(){return logger;}
// 	
// 	@EventHandler
// 	public void preInit(FMLPreInitializationEvent event){
// 		logger = event.getModLog();
// 		RunesofWizardry_Classics.log().info("Registering Classic dusts");
// 		ClassicDusts.instance = new ClassicDusts();
// 		DustRegistry.registerDust(ClassicDusts.instance);
// 		DustVariable.instance=new DustVariable();
// 		DustRegistry.registerDust(DustVariable.instance);
// 		//init the runes
// 		ModRunes.initRunes();
// 		ModInscriptions.initInscriptions();
// 		//register the config
// 		Config.init(event.getSuggestedConfigurationFile());
// 		MinecraftForge.EVENT_BUS.register(new Config());
// 	}
//     @EventHandler
//     public void init(FMLInitializationEvent event)
//     {
//     	//register the runes
//     	ModRunes.registerRunes();
//     	ModInscriptions.registerInscriptions();
//     }
//     @EventHandler
//     public void postInit(FMLPostInitializationEvent event){
//     	if(Loader.isModLoaded("guideapi")){
//     		GuideBookAdditions.handlePost();
//     	}
//     }
// }


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.storage.MapStorage;
import net.minecraft.world.storage.WorldSavedData;
import xilef11.mc.runesofwizardry_classics.Refs;
import xilef11.mc.runesofwizardry_classics.RunesofWizardry_Classics;
package xilef11.mc.runesofwizardry_classics.managers;

/**
 * Manages and save the data for teleportation network
 * @see http://mcforge.readthedocs.org/en/latest/datastorage/worldsaveddata/
 * @author Xilef11
 *
 */
public class TeleportationData extends WorldSavedData {
	private static final String DATA_NAME = Refs.MODID + "_TeleportationData";
	public TeleportationData(){
		this(DATA_NAME);
	}
	public TeleportationData(String name) {
		super(name);
	}
	/**
	 * Get the saved teleportation data for a world (or a new instance if there is none)
	 * @param world the world for which to get the teleportation network data
	 * @return the (possibly empty) teleportation network data for a world
	 */
	public static TeleportationData get(World world) {
		MapStorage storage = world.getPerWorldStorage();
		TeleportationData instance = (TeleportationData) storage.getOrLoadData(TeleportationData.class, DATA_NAME);
		if (instance == null) {
			instance = new TeleportationData();
			storage.setData(DATA_NAME, instance);
		}
		return instance;
	}
	//the key is the "id" of a blockstate in the form blockid@meta
	private Map<String,Set<BlockPos>> networks = new HashMap<>();
	/**
	 * Adds a teleport location to a network
	 * @param state the BlockState that identifies the network
	 * @param pos the position to add to the network
	 */
	public void registerLocation(IBlockState state, BlockPos pos){
		//get the key for this blockstate
		String key = getStateID(state);
		//add the position for this state
		addLocation(key, pos);
		this.markDirty();
		/*markDirty here instead of in addLocation
		 * because addLocation is called when reading from NBT (which is not a change in the data)
		 * maybe add it to readFromNBT if saving doesn't work properly on servers
		 */
	}
	/**
	 * Removes a teleport location from a network
	 * @param state the BlockState that identifies the network
	 * @param pos the position to remove from the network
	 */
	public void removeLocation(IBlockState state, BlockPos pos){
		String key = getStateID(state);
		Set<BlockPos> locations = networks.get(key);
		if(locations!=null){
			locations.remove(pos);
		}else{
// Path: src/main/java/xilef11/mc/runesofwizardry_classics/Refs.java
// public final class Refs {
// 	private Refs(){}
// 	public static final String MODID = "runesofwizardry_classics";
// 	public static final String VERSION = "@VERSION@";
// 	public static final String NAME="Runes of Wizardry - Classic Dusts Pack";
// 	public static final String GUI_FACTORY="xilef11.mc.runesofwizardry_classics.client.gui.GuiFactory";
// 	public static final String CLIENT_PROXY = "xilef11.mc.runesofwizardry_classics.proxy.ClientProxy",
// 							   SERVER_PROXY="xilef11.mc.runesofwizardry_classics.proxy.ServerProxy";
// 	public static final String PATTERN_PATH=MODID+":patterns/";
// 	public static final String TEXTURE_PATH=MODID+":";
// 	public static final int TICKS_PER_DAY=24000;
// 	public static final int TPS=20;
// 	public static final class Lang{
// 		private Lang(){}
// 		public static final String RUNE=MODID+".rune";
// 		public static final String CONFIG=MODID+".configuration";
// 		public static final String DEC=RUNE+".decorative";
// 		
// 		public static final class Jei{
// 			private Jei(){}
// 			public static final String JEI=MODID+".jei";
// 			public static final String SPIRIT_SWORD=JEI+".spirit_sword";
// 			public static final String SPIRIT_PICKAXE=JEI+".spirit_pickaxe";
// 		}
// 	}
// }
// 
// Path: src/main/java/xilef11/mc/runesofwizardry_classics/RunesofWizardry_Classics.java
// @Mod(modid = Refs.MODID, version = Refs.VERSION, name=Refs.NAME, guiFactory=Refs.GUI_FACTORY, dependencies = "required-after:runesofwizardry;after:guideapi")
// public class RunesofWizardry_Classics
// {
// 	@SidedProxy(clientSide=Refs.CLIENT_PROXY,serverSide=Refs.SERVER_PROXY)
// 	public static IProxy proxy;
// 	
// 	private static Logger logger;
// 	/**Returns the logger for the mod**/
// 	public static Logger log(){return logger;}
// 	
// 	@EventHandler
// 	public void preInit(FMLPreInitializationEvent event){
// 		logger = event.getModLog();
// 		RunesofWizardry_Classics.log().info("Registering Classic dusts");
// 		ClassicDusts.instance = new ClassicDusts();
// 		DustRegistry.registerDust(ClassicDusts.instance);
// 		DustVariable.instance=new DustVariable();
// 		DustRegistry.registerDust(DustVariable.instance);
// 		//init the runes
// 		ModRunes.initRunes();
// 		ModInscriptions.initInscriptions();
// 		//register the config
// 		Config.init(event.getSuggestedConfigurationFile());
// 		MinecraftForge.EVENT_BUS.register(new Config());
// 	}
//     @EventHandler
//     public void init(FMLInitializationEvent event)
//     {
//     	//register the runes
//     	ModRunes.registerRunes();
//     	ModInscriptions.registerInscriptions();
//     }
//     @EventHandler
//     public void postInit(FMLPostInitializationEvent event){
//     	if(Loader.isModLoaded("guideapi")){
//     		GuideBookAdditions.handlePost();
//     	}
//     }
// }


// Path: src/main/java/xilef11/mc/runesofwizardry_classics/managers/TeleportationData.java
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.storage.MapStorage;
import net.minecraft.world.storage.WorldSavedData;
import xilef11.mc.runesofwizardry_classics.Refs;
import xilef11.mc.runesofwizardry_classics.RunesofWizardry_Classics;

package xilef11.mc.runesofwizardry_classics.managers;

/**
 * Manages and save the data for teleportation network
 * @see http://mcforge.readthedocs.org/en/latest/datastorage/worldsaveddata/
 * @author Xilef11
 *
 */
public class TeleportationData extends WorldSavedData {
	private static final String DATA_NAME = Refs.MODID + "_TeleportationData";
	public TeleportationData(){
		this(DATA_NAME);
	}
	public TeleportationData(String name) {
		super(name);
	}
	/**
	 * Get the saved teleportation data for a world (or a new instance if there is none)
	 * @param world the world for which to get the teleportation network data
	 * @return the (possibly empty) teleportation network data for a world
	 */
	public static TeleportationData get(World world) {
		MapStorage storage = world.getPerWorldStorage();
		TeleportationData instance = (TeleportationData) storage.getOrLoadData(TeleportationData.class, DATA_NAME);
		if (instance == null) {
			instance = new TeleportationData();
			storage.setData(DATA_NAME, instance);
		}
		return instance;
	}
	//the key is the "id" of a blockstate in the form blockid@meta
	private Map<String,Set<BlockPos>> networks = new HashMap<>();
	/**
	 * Adds a teleport location to a network
	 * @param state the BlockState that identifies the network
	 * @param pos the position to add to the network
	 */
	public void registerLocation(IBlockState state, BlockPos pos){
		//get the key for this blockstate
		String key = getStateID(state);
		//add the position for this state
		addLocation(key, pos);
		this.markDirty();
		/*markDirty here instead of in addLocation
		 * because addLocation is called when reading from NBT (which is not a change in the data)
		 * maybe add it to readFromNBT if saving doesn't work properly on servers
		 */
	}
	/**
	 * Removes a teleport location from a network
	 * @param state the BlockState that identifies the network
	 * @param pos the position to remove from the network
	 */
	public void removeLocation(IBlockState state, BlockPos pos){
		String key = getStateID(state);
		Set<BlockPos> locations = networks.get(key);
		if(locations!=null){
			locations.remove(pos);
		}else{
			RunesofWizardry_Classics.log().warn("Trying to remove a teleport destination with inexistant key: "+key+" for state: "+state+" at pos: ");