2012-07-22 11:56:38 -02:30
/*
2013-03-07 19:25:48 -05:00
* Forge Mod Loader
* Copyright (c) 2012-2013 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v2.1
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2013-07-10 15:47:13 -04:00
*
2013-03-07 19:25:48 -05:00
* Contributors:
* cpw - implementation
2012-07-22 11:56:38 -02:30
*/
package cpw.mods.fml.common ;
2013-08-27 12:31:37 -04:00
import java.io.File ;
2012-12-23 22:27:02 -05:00
import java.security.cert.Certificate ;
2012-07-22 11:56:38 -02:30
import java.util.Arrays ;
2012-10-02 21:54:47 -04:00
import java.util.Map ;
2013-12-09 01:22:24 -05:00
import java.util.Map.Entry ;
2013-01-30 18:57:21 -05:00
import java.util.logging.Level ;
2012-07-22 11:56:38 -02:30
2012-12-09 22:00:51 -05:00
import net.minecraft.nbt.NBTBase ;
import net.minecraft.nbt.NBTTagCompound ;
import net.minecraft.nbt.NBTTagList ;
2012-12-08 20:21:03 -08:00
import net.minecraft.world.storage.SaveHandler ;
import net.minecraft.world.storage.WorldInfo ;
2012-10-02 21:54:47 -04:00
2013-12-09 21:36:49 -05:00
import com.google.common.collect.Maps ;
2012-08-04 11:26:51 -04:00
import com.google.common.eventbus.EventBus ;
2013-12-09 01:22:24 -05:00
import com.google.common.eventbus.Subscribe ;
2012-08-04 11:26:51 -04:00
2013-08-27 12:31:37 -04:00
import cpw.mods.fml.client.FMLFileResourcePack ;
import cpw.mods.fml.client.FMLFolderResourcePack ;
import cpw.mods.fml.common.asm.FMLSanityChecker ;
2013-12-09 01:22:24 -05:00
import cpw.mods.fml.common.event.FMLConstructionEvent ;
import cpw.mods.fml.common.network.NetworkCheckHandler ;
2013-12-06 03:11:03 -05:00
import cpw.mods.fml.common.network.NetworkRegistry ;
2013-12-11 19:07:59 -05:00
import cpw.mods.fml.common.network.internal.FMLNetworkHandler ;
2012-12-09 22:00:51 -05:00
import cpw.mods.fml.common.registry.GameData ;
2013-12-06 03:11:03 -05:00
import cpw.mods.fml.relauncher.Side ;
2012-12-07 01:52:16 -05:00
2012-07-22 11:56:38 -02:30
/**
* @author cpw
*
*/
2013-12-06 03:11:03 -05:00
public class FMLContainer extends DummyModContainer implements WorldAccessContainer
2012-07-22 11:56:38 -02:30
{
2013-12-06 03:11:03 -05:00
public FMLContainer ()
2012-07-22 11:56:38 -02:30
{
super ( new ModMetadata ());
ModMetadata meta = getMetadata ();
meta . modId = "FML" ;
meta . name = "Forge Mod Loader" ;
meta . version = Loader . instance (). getFMLVersionString ();
meta . credits = "Made possible with help from many people" ;
meta . authorList = Arrays . asList ( "cpw, LexManos" );
meta . description = "The Forge Mod Loader provides the ability for systems to load mods " +
"from the file system. It also provides key capabilities for mods to be able " +
2013-11-10 13:15:26 -05:00
"to cooperate and provide a good modding environment. " ;
2013-01-18 21:26:43 -05:00
meta . url = "https://github.com/MinecraftForge/FML/wiki" ;
meta . updateUrl = "https://github.com/MinecraftForge/FML/wiki" ;
2012-07-22 11:56:38 -02:30
meta . screenshots = new String [ 0 ] ;
meta . logoFile = "" ;
}
2012-08-04 11:26:51 -04:00
@Override
public boolean registerBus ( EventBus bus , LoadController controller )
{
2013-12-09 01:22:24 -05:00
bus . register ( this );
2012-08-04 11:26:51 -04:00
return true ;
}
2012-10-02 21:54:47 -04:00
2013-12-09 01:22:24 -05:00
@Subscribe
public void modConstruction ( FMLConstructionEvent evt )
{
NetworkRegistry . INSTANCE . register ( this , this . getClass (), null , evt . getASMHarvestedData ());
2013-12-11 18:46:25 -05:00
FMLNetworkHandler . registerChannel ( this , evt . getSide ());
2013-12-09 01:22:24 -05:00
}
@NetworkCheckHandler
public boolean checkModLists ( Map < String , String > modList , Side side )
{
return Loader . instance (). checkRemoteModList ( modList , side );
}
2012-10-02 21:54:47 -04:00
@Override
public NBTTagCompound getDataForWriting ( SaveHandler handler , WorldInfo info )
{
NBTTagCompound fmlData = new NBTTagCompound ();
NBTTagList list = new NBTTagList ();
for ( ModContainer mc : Loader . instance (). getActiveModList ())
{
NBTTagCompound mod = new NBTTagCompound ();
mod . func_74778_a ( "ModId" , mc . getModId ());
mod . func_74778_a ( "ModVersion" , mc . getVersion ());
list . func_74742_a ( mod );
}
fmlData . func_74782_a ( "ModList" , list );
2013-12-09 21:36:49 -05:00
NBTTagList dataList = new NBTTagList ();
Map < String , Integer > itemList = GameData . buildItemDataList ();
for ( Entry < String , Integer > item : itemList . entrySet ())
{
NBTTagCompound tag = new NBTTagCompound ();
tag . func_74778_a ( "K" , item . getKey ());
tag . func_74768_a ( "V" , item . getValue ());
dataList . func_74742_a ( tag );
}
fmlData . func_74782_a ( "ItemData" , dataList );
2012-10-02 21:54:47 -04:00
return fmlData ;
}
@Override
public void readData ( SaveHandler handler , WorldInfo info , Map < String , NBTBase > propertyMap , NBTTagCompound tag )
{
if ( tag . func_74764_b ( "ModList" ))
{
2013-12-02 23:46:42 -05:00
NBTTagList modList = tag . func_150295_c ( "ModList" , ( byte ) 10 );
2012-10-02 21:54:47 -04:00
for ( int i = 0 ; i < modList . func_74745_c (); i ++ )
{
2013-12-02 23:46:42 -05:00
NBTTagCompound mod = modList . func_150305_b ( i );
2012-10-02 21:54:47 -04:00
String modId = mod . func_74779_i ( "ModId" );
String modVersion = mod . func_74779_i ( "ModVersion" );
ModContainer container = Loader . instance (). getIndexedModList (). get ( modId );
if ( container == null )
{
2013-01-30 18:57:21 -05:00
FMLLog . log ( "fml.ModTracker" , Level . SEVERE , "This world was saved with mod %s which appears to be missing, things may not work well" , modId );
2012-10-02 21:54:47 -04:00
continue ;
}
if ( ! modVersion . equals ( container . getVersion ()))
{
2013-01-30 18:57:21 -05:00
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 ());
2012-10-02 21:54:47 -04:00
}
}
}
2012-12-07 01:52:16 -05:00
if ( tag . func_74764_b ( "ModItemData" ))
{
2013-12-02 23:46:42 -05:00
NBTTagList modList = tag . func_150295_c ( "ModItemData" , ( byte ) 10 );
// Set<ItemData> worldSaveItems = GameData.buildWorldItemData(modList);
// GameData.validateWorldSave(worldSaveItems);
2012-12-07 01:52:16 -05:00
}
2013-12-09 21:36:49 -05:00
else if ( tag . func_74764_b ( "ItemData" ))
2012-12-07 01:52:16 -05:00
{
2013-12-09 21:36:49 -05:00
NBTTagList list = tag . func_150295_c ( "ItemData" , ( byte ) 10 );
Map < String , Integer > dataList = Maps . newLinkedHashMap ();
for ( int i = 0 ; i < list . func_74745_c (); i ++ )
{
NBTTagCompound dataTag = list . func_150305_b ( i );
dataList . put ( dataTag . func_74779_i ( "K" ), dataTag . func_74762_e ( "V" ));
}
GameData . injectWorldIDMap ( dataList );
2012-12-07 01:52:16 -05:00
}
2012-10-02 21:54:47 -04:00
}
2012-12-07 01:52:16 -05:00
2012-12-23 22:27:02 -05:00
@Override
public Certificate getSigningCertificate ()
{
Certificate [] certificates = getClass (). getProtectionDomain (). getCodeSource (). getCertificates ();
return certificates != null ? certificates [ 0 ] : null ;
}
2013-07-10 15:47:13 -04:00
2013-08-27 12:31:37 -04:00
@Override
public File getSource ()
{
return FMLSanityChecker . fmlLocation ;
}
2013-12-06 03:11:03 -05:00
2013-07-10 15:47:13 -04:00
@Override
public Class <?> getCustomResourcePackClass ()
{
2013-08-27 12:31:37 -04:00
return getSource (). isDirectory () ? FMLFolderResourcePack . class : FMLFileResourcePack . class ;
2013-07-10 15:47:13 -04:00
}
2012-07-22 11:56:38 -02:30
}