Advertisement
spacechase0

@SideOnly @Mod's

Aug 27th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 KB | None | 0 0
  1. /*
  2.  * Forge Mod Loader
  3.  * Copyright (c) 2012-2013 cpw.
  4.  * All rights reserved. This program and the accompanying materials
  5.  * are made available under the terms of the GNU Lesser Public License v2.1
  6.  * which accompanies this distribution, and is available at
  7.  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  8.  *
  9.  * Contributors:
  10.  *     cpw - implementation
  11.  */
  12.  
  13. package cpw.mods.fml.common;
  14.  
  15. import java.io.File;
  16. import java.util.regex.Pattern;
  17.  
  18. import org.objectweb.asm.Type;
  19.  
  20. import cpw.mods.fml.common.discovery.ModCandidate;
  21. import cpw.mods.fml.common.discovery.asm.ASMModParser;
  22. import cpw.mods.fml.common.discovery.asm.ModAnnotation;
  23. import cpw.mods.fml.common.discovery.asm.ModAnnotation.EnumHolder;
  24. import cpw.mods.fml.common.modloader.ModLoaderModContainer;
  25. import cpw.mods.fml.relauncher.SideOnly;
  26.  
  27. public class ModContainerFactory
  28. {
  29.     private static Pattern modClass = Pattern.compile(".*(\\.|)(mod\\_[^\\s$]+)$");
  30.     private static ModContainerFactory INSTANCE = new ModContainerFactory();
  31.     public static ModContainerFactory instance() {
  32.         return INSTANCE;
  33.     }
  34.     public ModContainer build(ASMModParser modParser, File modSource, ModCandidate container)
  35.     {
  36.         String className = modParser.getASMType().getClassName();
  37.         if (modParser.isBaseMod(container.getRememberedBaseMods()) && modClass.matcher(className).find())
  38.         {
  39.             FMLLog.fine("Identified a BaseMod type mod %s", className);
  40.             return new ModLoaderModContainer(className, modSource, modParser.getBaseModProperties());
  41.         }
  42.         else if (modClass.matcher(className).find())
  43.         {
  44.             FMLLog.fine("Identified a class %s following modloader naming convention but not directly a BaseMod or currently seen subclass", className);
  45.             container.rememberModCandidateType(modParser);
  46.         }
  47.         else if (modParser.isBaseMod(container.getRememberedBaseMods()))
  48.         {
  49.             FMLLog.fine("Found a basemod %s of non-standard naming format", className);
  50.             container.rememberBaseModType(className);
  51.         }
  52.  
  53.         // We warn if it's not a basemod instance -- compatibility requires it to be in net.minecraft.src *sigh*
  54.         if (className.startsWith("net.minecraft.src.") && container.isClasspath() && !container.isMinecraftJar())
  55.         {
  56.             FMLLog.severe("FML has detected a mod that is using a package name based on 'net.minecraft.src' : %s. This is generally a severe programming error. "
  57.                     + " There should be no mod code in the minecraft namespace. MOVE YOUR MOD! If you're in eclipse, select your source code and 'refactor' it into "
  58.                     + "a new package. Go on. DO IT NOW!",className);
  59.         }
  60.  
  61.         ModAnnotation modAnn = null;
  62.         boolean badSide = false;
  63.         for (ModAnnotation ann : modParser.getAnnotations())
  64.         {
  65.             if (ann.getASMType().equals(Type.getType(Mod.class)))
  66.             {
  67.                 modAnn = ann;
  68.             }
  69.             else if ( ann.getASMType().equals( Type.getType( SideOnly.class ) ) )
  70.             {
  71.                 EnumHolder side = ( EnumHolder ) ann.getValues().get( "value" );
  72.                 if ( !side.value.equals( FMLCommonHandler.instance().getSide().name() ) )
  73.                 {
  74.                     badSide = true;
  75.                 }
  76.             }
  77.         }
  78.        
  79.         if ( modAnn != null && !badSide )
  80.         {
  81.             FMLLog.fine("Identified an FMLMod type mod %s", className);
  82.             return new FMLModContainer(className, modSource, modAnn.getValues());
  83.         }
  84.  
  85.         return null;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement