Advertisement
Guest User

Untitled

a guest
May 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. package crystek.modules;
  2.  
  3. import crystek.Crystek;
  4. import crystek.modules.materials.MaterialsModule;
  5. import net.minecraftforge.fml.common.Loader;
  6. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  7. import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
  8. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
  9.  
  10. import java.util.ArrayList;
  11. import java.util.List;
  12.  
  13. /**
  14. * @author Prospector on 28/05/16
  15. */
  16. public class ModuleRegistry
  17. {
  18. public static MaterialsModule materialsModule = new MaterialsModule();
  19.  
  20. public static List<Module> modules = new ArrayList<Module>();
  21. public static List<String> moduleIds = new ArrayList<String>();
  22.  
  23. public static void addModules()
  24. {
  25. modules.add(materialsModule);
  26.  
  27. for(Module i : modules)
  28. moduleIds.add(i.getModuleID());
  29. }
  30.  
  31. public static void preInit(FMLPreInitializationEvent event)
  32. {
  33. addModules();
  34. for (Module i : modules)
  35. {
  36. if (hasRequirements(i))
  37. {
  38. Crystek.logHelper.info("Module " + i.getModuleID() + " is being PreInitialized");
  39. i.preInit(event);
  40. }
  41. }
  42. }
  43.  
  44. public static void init(FMLInitializationEvent event)
  45. {
  46. for (Module i : modules)
  47. {
  48. if (hasRequirements(i))
  49. {
  50. Crystek.logHelper.info("Module " + i.getModuleID() + " is being Initialized");
  51. i.init(event);
  52. }
  53. }
  54. }
  55.  
  56. public static void postInit(FMLPostInitializationEvent event)
  57. {
  58. for (Module i : modules)
  59. {
  60. if (hasRequirements(i))
  61. {
  62. Crystek.logHelper.info("Module " + i.getModuleID() + " is being PostInitialized");
  63. i.postInit(event);
  64. }
  65. }
  66. }
  67.  
  68. public static boolean hasRequirements(Module module)
  69. {
  70. String[] reqMods = module.getModsRequired();
  71. String[] reqModules = module.getModsRequired();
  72.  
  73. if (reqMods != null)
  74. for (String i : reqMods)
  75. {
  76. if (!Loader.isModLoaded(i))
  77. {
  78. return false;
  79. }
  80. }
  81.  
  82. if (reqModules != null)
  83. for (String i : reqModules)
  84. {
  85. if (!moduleIds.contains(i))
  86. {
  87. return false;
  88. }
  89. }
  90.  
  91. return true;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement