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 import java.util.concurrent.ConcurrentMap; 021 022 import net.minecraft.src.NBTBase; 023 import net.minecraft.src.NBTTagCompound; 024 import net.minecraft.src.NBTTagList; 025 import net.minecraft.src.NBTTagString; 026 import net.minecraft.src.SaveHandler; 027 import net.minecraft.src.WorldInfo; 028 029 import com.google.common.collect.MapMaker; 030 import com.google.common.collect.Sets; 031 import com.google.common.eventbus.EventBus; 032 033 import cpw.mods.fml.common.registry.GameData; 034 import cpw.mods.fml.common.registry.GameRegistry; 035 import cpw.mods.fml.common.registry.ItemData; 036 037 /** 038 * @author cpw 039 * 040 */ 041 public class FMLDummyContainer extends DummyModContainer implements WorldAccessContainer 042 { 043 public FMLDummyContainer() 044 { 045 super(new ModMetadata()); 046 ModMetadata meta = getMetadata(); 047 meta.modId="FML"; 048 meta.name="Forge Mod Loader"; 049 meta.version=Loader.instance().getFMLVersionString(); 050 meta.credits="Made possible with help from many people"; 051 meta.authorList=Arrays.asList("cpw, LexManos"); 052 meta.description="The Forge Mod Loader provides the ability for systems to load mods " + 053 "from the file system. It also provides key capabilities for mods to be able " + 054 "to cooperate and provide a good modding environment. " + 055 "The mod loading system is compatible with ModLoader, all your ModLoader " + 056 "mods should work."; 057 meta.url="https://github.com/cpw/FML/wiki"; 058 meta.updateUrl="https://github.com/cpw/FML/wiki"; 059 meta.screenshots=new String[0]; 060 meta.logoFile=""; 061 } 062 063 @Override 064 public boolean registerBus(EventBus bus, LoadController controller) 065 { 066 return true; 067 } 068 069 @Override 070 public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) 071 { 072 NBTTagCompound fmlData = new NBTTagCompound(); 073 NBTTagList list = new NBTTagList(); 074 for (ModContainer mc : Loader.instance().getActiveModList()) 075 { 076 NBTTagCompound mod = new NBTTagCompound(); 077 mod.setString("ModId", mc.getModId()); 078 mod.setString("ModVersion", mc.getVersion()); 079 list.appendTag(mod); 080 } 081 fmlData.setTag("ModList", list); 082 NBTTagList itemList = new NBTTagList(); 083 GameData.writeItemData(itemList); 084 fmlData.setTag("ModItemData", itemList); 085 return fmlData; 086 } 087 088 @Override 089 public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag) 090 { 091 if (tag.hasKey("ModList")) 092 { 093 NBTTagList modList = tag.getTagList("ModList"); 094 for (int i = 0; i < modList.tagCount(); i++) 095 { 096 NBTTagCompound mod = (NBTTagCompound) modList.tagAt(i); 097 String modId = mod.getString("ModId"); 098 String modVersion = mod.getString("ModVersion"); 099 ModContainer container = Loader.instance().getIndexedModList().get(modId); 100 if (container == null) 101 { 102 FMLLog.severe("This world was saved with mod %s which appears to be missing, things may not work well", modId); 103 continue; 104 } 105 if (!modVersion.equals(container.getVersion())) 106 { 107 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()); 108 } 109 } 110 } 111 if (tag.hasKey("ModItemData")) 112 { 113 NBTTagList modList = tag.getTagList("ModItemData"); 114 Set<ItemData> worldSaveItems = GameData.buildWorldItemData(modList); 115 GameData.validateWorldSave(worldSaveItems); 116 } 117 else 118 { 119 GameData.validateWorldSave(null); 120 } 121 } 122 123 }