    001/*
    002 * Forge Mod Loader
    003 * Copyright (c) 2012-2013 cpw.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the GNU Lesser Public License v2.1
    006 * which accompanies this distribution, and is available at
    007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    008 *
    009 * Contributors:
    010 *     cpw - implementation
    011 */
    012
    013package cpw.mods.fml.common;
    014
    015import java.security.cert.Certificate;
    016import java.util.Arrays;
    017import java.util.Map;
    018import java.util.Set;
    019import java.util.logging.Level;
    020
    021import net.minecraft.nbt.NBTBase;
    022import net.minecraft.nbt.NBTTagCompound;
    023import net.minecraft.nbt.NBTTagList;
    024import net.minecraft.world.storage.SaveHandler;
    025import net.minecraft.world.storage.WorldInfo;
    026
    027import com.google.common.eventbus.EventBus;
    028
    029import cpw.mods.fml.common.registry.GameData;
    030import cpw.mods.fml.common.registry.GameRegistry;
    031import cpw.mods.fml.common.registry.ItemData;
    032
    033/**
    034 * @author cpw
    035 *
    036 */
    037public class FMLDummyContainer extends DummyModContainer implements WorldAccessContainer
    038{
    039    public FMLDummyContainer()
    040    {
    041        super(new ModMetadata());
    042        ModMetadata meta = getMetadata();
    043        meta.modId="FML";
    044        meta.name="Forge Mod Loader";
    045        meta.version=Loader.instance().getFMLVersionString();
    046        meta.credits="Made possible with help from many people";
    047        meta.authorList=Arrays.asList("cpw, LexManos");
    048        meta.description="The Forge Mod Loader provides the ability for systems to load mods " +
    049                    "from the file system. It also provides key capabilities for mods to be able " +
    050                    "to cooperate and provide a good modding environment. " +
    051                    "The mod loading system is compatible with ModLoader, all your ModLoader " +
    052                    "mods should work.";
    053        meta.url="https://github.com/MinecraftForge/FML/wiki";
    054        meta.updateUrl="https://github.com/MinecraftForge/FML/wiki";
    055        meta.screenshots=new String[0];
    056        meta.logoFile="";
    057    }
    058
    059    @Override
    060    public boolean registerBus(EventBus bus, LoadController controller)
    061    {
    062        return true;
    063    }
    064
    065    @Override
    066    public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info)
    067    {
    068        NBTTagCompound fmlData = new NBTTagCompound();
    069        NBTTagList list = new NBTTagList();
    070        for (ModContainer mc : Loader.instance().getActiveModList())
    071        {
    072            NBTTagCompound mod = new NBTTagCompound();
    073            mod.setString("ModId", mc.getModId());
    074            mod.setString("ModVersion", mc.getVersion());
    075            list.appendTag(mod);
    076        }
    077        fmlData.setTag("ModList", list);
    078        NBTTagList itemList = new NBTTagList();
    079        GameData.writeItemData(itemList);
    080        fmlData.setTag("ModItemData", itemList);
    081        return fmlData;
    082    }
    083
    084    @Override
    085    public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag)
    086    {
    087        if (tag.hasKey("ModList"))
    088        {
    089            NBTTagList modList = tag.getTagList("ModList");
    090            for (int i = 0; i < modList.tagCount(); i++)
    091            {
    092                NBTTagCompound mod = (NBTTagCompound) modList.tagAt(i);
    093                String modId = mod.getString("ModId");
    094                String modVersion = mod.getString("ModVersion");
    095                ModContainer container = Loader.instance().getIndexedModList().get(modId);
    096                if (container == null)
    097                {
    098                    FMLLog.log("fml.ModTracker", Level.SEVERE, "This world was saved with mod %s which appears to be missing, things may not work well", modId);
    099                    continue;
    100                }
    101                if (!modVersion.equals(container.getVersion()))
    102                {
    103                    FMLLog.log("fml.ModTracker", Level.INFO, "This world was saved with mod %s version %s and it is now at version %s, things may not work well", modId, modVersion, container.getVersion());
    104                }
    105            }
    106        }
    107        if (tag.hasKey("ModItemData"))
    108        {
    109            NBTTagList modList = tag.getTagList("ModItemData");
    110            Set<ItemData> worldSaveItems = GameData.buildWorldItemData(modList);
    111            GameData.validateWorldSave(worldSaveItems);
    112        }
    113        else
    114        {
    115            GameData.validateWorldSave(null);
    116        }
    117    }
    118
    119
    120    @Override
    121    public Certificate getSigningCertificate()
    122    {
    123        Certificate[] certificates = getClass().getProtectionDomain().getCodeSource().getCertificates();
    124        return certificates != null ? certificates[0] : null;
    125    }
    126}