    001package net.minecraftforge.common;
    002
    003import java.io.File;
    004import java.util.Arrays;
    005import java.util.Map;
    006
    007import net.minecraft.nbt.NBTBase;
    008import net.minecraft.nbt.NBTTagCompound;
    009import net.minecraft.server.management.PlayerInstance;
    010import net.minecraft.world.storage.SaveHandler;
    011import net.minecraft.world.storage.WorldInfo;
    012
    013import com.google.common.eventbus.EventBus;
    014import com.google.common.eventbus.Subscribe;
    015
    016import cpw.mods.fml.common.DummyModContainer;
    017import cpw.mods.fml.common.LoadController;
    018import cpw.mods.fml.common.Loader;
    019import cpw.mods.fml.common.ModMetadata;
    020import cpw.mods.fml.common.WorldAccessContainer;
    021import cpw.mods.fml.common.event.FMLPostInitializationEvent;
    022import cpw.mods.fml.common.event.FMLPreInitializationEvent;
    023
    024import static net.minecraftforge.common.ForgeVersion.*;
    025
    026public class ForgeDummyContainer extends DummyModContainer implements WorldAccessContainer
    027{
    028    public static int clumpingThreshold = 64;
    029
    030    public ForgeDummyContainer()
    031    {
    032        super(new ModMetadata());
    033        ModMetadata meta = getMetadata();
    034        meta.modId       = "Forge";
    035        meta.name        = "Minecraft Forge";
    036        meta.version     = String.format("%d.%d.%d.%d", majorVersion, minorVersion, revisionVersion, buildVersion);
    037        meta.credits     = "Made possible with help from many people";
    038        meta.authorList  = Arrays.asList("LexManos", "Eloraam", "Spacetoad");
    039        meta.description = "Minecraft Forge is a common open source API allowing a broad range of mods " +
    040                           "to work cooperatively together. It allows many mods to be created without " +
    041                           "them editing the main Minecraft code.";
    042        meta.url         = "http://MinecraftForge.net";
    043        meta.updateUrl   = "http://MinecraftForge.net/forum/index.php/topic,5.0.html";
    044        meta.screenshots = new String[0];
    045        meta.logoFile    = "/forge_logo.png";
    046
    047        Configuration config = new Configuration(new File(Loader.instance().getConfigDir(), "forge.cfg"));
    048        if (!config.isChild)
    049        {
    050            config.load();
    051            Property enableGlobalCfg = config.get(Configuration.CATEGORY_GENERAL, "enableGlobalConfig", false);
    052            if (enableGlobalCfg.getBoolean(false))
    053            {
    054                Configuration.enableGlobalConfig();
    055            }
    056        }
    057        Property clumpingThresholdProperty = config.get(Configuration.CATEGORY_GENERAL, "clumpingThreshold", 64);
    058        clumpingThresholdProperty.comment = "Controls the number threshold at which Packet51 is preferred over Packet52, default and minimum 64, maximum 1024";
    059        clumpingThreshold = clumpingThresholdProperty.getInt(64);
    060        if (clumpingThreshold > 1024 || clumpingThreshold < 64)
    061        {
    062            clumpingThreshold = 64;
    063            clumpingThresholdProperty.value = "64";
    064        }
    065        config.save();
    066    }
    067
    068    @Override
    069    public boolean registerBus(EventBus bus, LoadController controller)
    070    {
    071        bus.register(this);
    072        return true;
    073    }
    074
    075    @Subscribe
    076    public void preInit(FMLPreInitializationEvent evt)
    077    {
    078        ForgeChunkManager.captureConfig(evt.getModConfigurationDirectory());
    079    }
    080
    081    @Subscribe
    082    public void postInit(FMLPostInitializationEvent evt)
    083    {
    084        ForgeChunkManager.loadConfiguration();
    085    }
    086
    087    @Override
    088    public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info)
    089    {
    090        NBTTagCompound forgeData = new NBTTagCompound();
    091        NBTTagCompound dimData = DimensionManager.saveDimensionDataMap();
    092        forgeData.setCompoundTag("DimensionData", dimData);
    093        return forgeData;
    094    }
    095
    096    @Override
    097    public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag)
    098    {
    099        if (tag.hasKey("DimensionData"))
    100        {
    101            DimensionManager.loadDimensionDataMap(tag.hasKey("DimensionData") ? tag.getCompoundTag("DimensionData") : null);
    102        }
    103    }
    104}