001    /*
002     * The FML Forge Mod Loader suite.
003     * Copyright (C) 2012 cpw
004     *
005     * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or any later version.
007     *
008     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
009     * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
010     *
011     * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
012     * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
013     */
014    
015    package cpw.mods.fml.common;
016    
017    import java.security.cert.Certificate;
018    import java.util.Arrays;
019    import java.util.Map;
020    import java.util.Set;
021    
022    import net.minecraft.nbt.NBTBase;
023    import net.minecraft.nbt.NBTTagCompound;
024    import net.minecraft.nbt.NBTTagList;
025    import net.minecraft.world.storage.SaveHandler;
026    import net.minecraft.world.storage.WorldInfo;
027    
028    import com.google.common.eventbus.EventBus;
029    
030    import cpw.mods.fml.common.registry.GameData;
031    import cpw.mods.fml.common.registry.GameRegistry;
032    import cpw.mods.fml.common.registry.ItemData;
033    
034    /**
035     * @author cpw
036     *
037     */
038    public class FMLDummyContainer extends DummyModContainer implements WorldAccessContainer
039    {
040        public FMLDummyContainer()
041        {
042            super(new ModMetadata());
043            ModMetadata meta = getMetadata();
044            meta.modId="FML";
045            meta.name="Forge Mod Loader";
046            meta.version=Loader.instance().getFMLVersionString();
047            meta.credits="Made possible with help from many people";
048            meta.authorList=Arrays.asList("cpw, LexManos");
049            meta.description="The Forge Mod Loader provides the ability for systems to load mods " +
050                        "from the file system. It also provides key capabilities for mods to be able " +
051                        "to cooperate and provide a good modding environment. " +
052                        "The mod loading system is compatible with ModLoader, all your ModLoader " +
053                        "mods should work.";
054            meta.url="https://github.com/cpw/FML/wiki";
055            meta.updateUrl="https://github.com/cpw/FML/wiki";
056            meta.screenshots=new String[0];
057            meta.logoFile="";
058        }
059    
060        @Override
061        public boolean registerBus(EventBus bus, LoadController controller)
062        {
063            return true;
064        }
065    
066        @Override
067        public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info)
068        {
069            NBTTagCompound fmlData = new NBTTagCompound();
070            NBTTagList list = new NBTTagList();
071            for (ModContainer mc : Loader.instance().getActiveModList())
072            {
073                NBTTagCompound mod = new NBTTagCompound();
074                mod.setString("ModId", mc.getModId());
075                mod.setString("ModVersion", mc.getVersion());
076                list.appendTag(mod);
077            }
078            fmlData.setTag("ModList", list);
079            NBTTagList itemList = new NBTTagList();
080            GameData.writeItemData(itemList);
081            fmlData.setTag("ModItemData", itemList);
082            return fmlData;
083        }
084    
085        @Override
086        public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag)
087        {
088            if (tag.hasKey("ModList"))
089            {
090                NBTTagList modList = tag.getTagList("ModList");
091                for (int i = 0; i < modList.tagCount(); i++)
092                {
093                    NBTTagCompound mod = (NBTTagCompound) modList.tagAt(i);
094                    String modId = mod.getString("ModId");
095                    String modVersion = mod.getString("ModVersion");
096                    ModContainer container = Loader.instance().getIndexedModList().get(modId);
097                    if (container == null)
098                    {
099                        FMLLog.severe("This world was saved with mod %s which appears to be missing, things may not work well", modId);
100                        continue;
101                    }
102                    if (!modVersion.equals(container.getVersion()))
103                    {
104                        FMLLog.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());
105                    }
106                }
107            }
108            if (tag.hasKey("ModItemData"))
109            {
110                NBTTagList modList = tag.getTagList("ModItemData");
111                Set<ItemData> worldSaveItems = GameData.buildWorldItemData(modList);
112                GameData.validateWorldSave(worldSaveItems);
113            }
114            else
115            {
116                GameData.validateWorldSave(null);
117            }
118        }
119    
120    
121        @Override
122        public Certificate getSigningCertificate()
123        {
124            Certificate[] certificates = getClass().getProtectionDomain().getCodeSource().getCertificates();
125            return certificates != null ? certificates[0] : null;
126        }
127    }