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.util.Arrays;
018    import java.util.Map;
019    import java.util.Set;
020    
021    import net.minecraft.nbt.NBTBase;
022    import net.minecraft.nbt.NBTTagCompound;
023    import net.minecraft.nbt.NBTTagList;
024    import net.minecraft.world.storage.SaveHandler;
025    import net.minecraft.world.storage.WorldInfo;
026    
027    import com.google.common.eventbus.EventBus;
028    
029    import cpw.mods.fml.common.registry.GameData;
030    import cpw.mods.fml.common.registry.GameRegistry;
031    import cpw.mods.fml.common.registry.ItemData;
032    
033    /**
034     * @author cpw
035     *
036     */
037    public 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/cpw/FML/wiki";
054            meta.updateUrl="https://github.com/cpw/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.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.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    }