From 181f92104cc5085b36585fba577dfdd311a2edd6 Mon Sep 17 00:00:00 2001 From: Modbder Date: Mon, 14 Sep 2015 14:27:37 +0300 Subject: [PATCH] DummyCore 2.0 ALPHA build! --- DummyCore/Core/Core.java | 227 ++++++++++++++-------------- DummyCore/Core/CoreInitialiser.java | 149 +++++++----------- 2 files changed, 174 insertions(+), 202 deletions(-) diff --git a/DummyCore/Core/Core.java b/DummyCore/Core/Core.java index ba904d9..91dfbe1 100755 --- a/DummyCore/Core/Core.java +++ b/DummyCore/Core/Core.java @@ -3,130 +3,134 @@ package DummyCore.Core; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import DummyCore.CreativeTabs.CreativePageBlocks; -import DummyCore.CreativeTabs.CreativePageItems; -import DummyCore.Utils.EnumLightColor; -import DummyCore.Utils.IDummyConfig; -import DummyCore.Utils.Notifier; -import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraftforge.common.config.Configuration; +import DummyCore.CreativeTabs.CreativePageBlocks; +import DummyCore.CreativeTabs.CreativePageItems; +import DummyCore.Utils.IDummyConfig; +import DummyCore.Utils.LoadingUtils; +import DummyCore.Utils.Notifier; public class Core { - public static List lightBlocks = new ArrayList(); - public static List lightColors = new ArrayList(); - private static HashMap, Integer> modList = new HashMap,Integer>(); - private static HashMap configurationList = new HashMap(); - private static List modNameList = new ArrayList(); - private static CreativeTabs[] blocksTabs = new CreativeTabs[512]; - private static CreativeTabs[] itemsTabs = new CreativeTabs[512]; - private static Configuration[] config = new Configuration[512]; - private static IDummyConfig[] configurationHandlers = new IDummyConfig[512]; - private static boolean[] isConfigLoaded = new boolean[512]; - private static void registerMod(Class c, String name) throws RuntimeException + public static final ArrayList registeredMods = new ArrayList(); + public static File mcDir; + + public static boolean isModRegistered(Class mod) { - if(!modList.containsKey(c)) + for(DCMod dcm : registeredMods) + if(dcm.modClass.equals(mod)) + return true; + + return false; + } + + public static DCMod getModFromClass(Class c) + { + for(DCMod dcm : registeredMods) + if(dcm.modClass.equals(c)) + return dcm; + + return null; + } + + private static void registerMod(Class c, String name, boolean addCreativeTabs) + { + if(!isModRegistered(c)) { - int modId = getNextModId(); - if(modId < 0 || modId >= 512) + DCMod mod = new DCMod(c,name); + if(addCreativeTabs) { - throw new RuntimeException("Mod "+name+" is trying to be registered with wrong id "+modId); + mod.blocks = new CreativePageBlocks(name); + mod.items = new CreativePageItems(name); } - modList.put(c, modId); - modNameList.add(modId, name); - blocksTabs[modId] = new CreativePageBlocks(name); - itemsTabs[modId] = new CreativePageItems(name); - Notifier.notifySimple("Mod with name "+name+" and classpath "+c.getName()+".class using ID "+modId+" has been succesfully registered!"); + registeredMods.add(mod); }else { - throw new RuntimeException("Mod "+name+" is already registered!"); + Notifier.notifyError(name+"[classPath:"+c+"]Already has a DummyCore mod associated with it(is already registered), ignoring"); } } - private static void registerConfigurationFileForMod(Class c, String path) throws IOException + private static void registerConfigurationFileForMod(Class c, String path) { - File file = new File(path,getModName(getIdForMod(c))+".cfg"); - if(!file.exists()) - file.createNewFile(); - config[getIdForMod(c)] = new Configuration(file); - config[getIdForMod(c)].save(); - configurationList.put(getIdForMod(c), config[getIdForMod(c)]); - Notifier.notifySimple("Configuration File for mod "+getModName(getIdForMod(c))+" was successfully created with path "+path+getModName(getIdForMod(c))+".cfg"); + try + { + if(!isModRegistered(c)) + { + LoadingUtils.makeACrash("[DummyCore]Catched an attempt to register configuration file for not registered mod, this should not be possible and many things will go wrong as a result!", new IllegalStateException(c+" Is not a valid DCMod!"), false); + }else + { + DCMod mod = getModFromClass(c); + File file = new File(path,mod.ufName+".cfg"); + if(file.isDirectory()) + file.delete(); + + if(!file.exists()) + file.createNewFile(); + + Configuration cfg = new Configuration(file); + cfg.save(); + mod.injectFMLConfig(cfg); + Notifier.notifySimple("Configuration File for mod "+mod+" was successfully created with path "+path+mod.ufName+".cfg"); + } + } + catch(IOException e) + { + DCMod mod = getModFromClass(c); + LoadingUtils.makeACrash("[DummyCore]Could not create a config file for mod "+mod+" - check your file system!", e, true); + } } /** - * Use this in you Pre-Initiasisation functions. This will register your mod in the DummyCore system and automatically create all config and .lang files. + * Use this in you Pre-Initialization functions. This will register your mod in the DummyCore system and automatically create all config and .lang files. * From DummyCore v1.1 you no longer need to use IMCEvent to register all blocks and items. * @param c - class file of your mod. MUST be registered from the mod itself. Use getClass(). * @param modname - this name will be used to name CreativeTabs, config and .lang files. * @param configPath - the path to your configuration file. You can use FMLPreInitialisationEvent.getModConfigurationDirectory().getAbsolutePath() to get your path. - * @param config - the initialised! object, that implements IDummyConfig. - * @throws IOException - If something has gone wrong the game will give the corresponding error report. + * @param config - the initialized! object, that implements IDummyConfig. * @version From DummyCore 1.0. * @Warning From DummyCore 1.1 no longer the function registerConfigurationHandler must be called. * */ - public static void registerModAbsolute(Class c, String modname, String configPath, IDummyConfig config) throws IOException + public static void registerModAbsolute(Class c, String modname, String configPath, IDummyConfig config) { - registerMod(c,modname); + registerModAbsolute(c,modname,configPath,config,true); + } + + /** + * Use this in you Pre-Initialization functions. This will register your mod in the DummyCore system and automatically create all config and .lang files. + * From DummyCore v1.1 you no longer need to use IMCEvent to register all blocks and items. + * @param c - class file of your mod. MUST be registered from the mod itself. Use getClass(). + * @param modname - this name will be used to name CreativeTabs, config and .lang files. + * @param configPath - the path to your configuration file. You can use FMLPreInitialisationEvent.getModConfigurationDirectory().getAbsolutePath() to get your path. + * @param config - the initialized! object, that implements IDummyConfig. + * @param addCreativeTabs if the custom creative tabs for your mod should be created. + * @version From DummyCore 2.0. + * + */ + public static void registerModAbsolute(Class c, String modname, String configPath, IDummyConfig config, boolean addCreativeTabs) + { + registerMod(c,modname,addCreativeTabs); registerConfigurationFileForMod(c,configPath); registerConfigurationHandler(config,c); - loadConfigForMod(getIdForMod(c)); - } - - private static int getNextModId() - { - int i = 0; - while(i < 512) - { - if(!modList.containsValue(i)) - { - break; - } - ++i; - } - return i; - } - - /** - * Used to get the ID of the mod using .class file. - * @param m - the class file of the mod. - * @return The corresponding ID of the mod. - * @version From DummyCore 1.0 - */ - public static int getIdForMod(Class m) - { - if(modList.containsKey(m)) - { - return (Integer)modList.get(m); - } - return 0; - } - - /** - * Used to get the name of the mod using .class file. - * @param i - the id of the mod. - * @return The corresponding name of the mod. - * @version From DummyCore 1.0 - */ - public static String getModName(int i) - { - return (String)modNameList.get(i); + loadConfigForMod(c); } /** * Used to get the config file of the mod using .class file. * @param c - the class file of the mod. * @return The corresponding config file of the mod. - * @version From DummyCore 1.0 + * @version From DummyCore 2.0 */ public static Configuration getConfigFileForMod(Class c) { - return config[getIdForMod(c)]; + if(!isModRegistered(c)) + { + Notifier.notifyError("Catched an attempt to get configuration for a not registered mod, things are about go wery wrong! Offendor: "+c); + return null; + } + return getModFromClass(c).fmlCfg; } /** @@ -134,39 +138,32 @@ public class Core { * @param config - the initialised! object, that implements IDummyConfig. * @param c - the class file of the mod. Use getClass(). Should only be called in the mod itself. * @throws RuntimeException - * @version From DummyCore 1.0 + * @version From DummyCore 2.0 */ - private static void registerConfigurationHandler(IDummyConfig config, Class c) throws RuntimeException + private static void registerConfigurationHandler(IDummyConfig config, Class c) { - int modId = getIdForMod(c); - if(configurationHandlers[modId] == null) + if(!isModRegistered(c)) { - configurationHandlers[modId] = config; + LoadingUtils.makeACrash("[DummyCore]Catched an attempt to register IDummyConfig for not registered mod, this should not be possible and many things will go wrong as a result!", new IllegalStateException(c+" Is not a valid DCMod!"), false); }else { - throw new RuntimeException("Configuration handler for mod "+getModName(modId)+" is already registered!"); + DCMod mod = getModFromClass(c); + mod.injectConfig(config); + Notifier.notifySimple("IDummyConfing for mod "+mod+" was successfully created"); } } - private static void loadConfigForMod(int t) throws RuntimeException + public static void loadConfigForMod(Class c) { - if(!isConfigLoaded[t]) + if(!isModRegistered(c)) { - if(configurationHandlers[t] != null && config[t] != null) - { - config[t].load(); - configurationHandlers[t].load(config[t]); - config[t].save(); - } - else - if((configurationHandlers[t] == null && config[t] != null) || (configurationHandlers[t] != null && config[t] == null)) - { - //throw new RuntimeException("Either the configuration handler for config was not registered, or the IConfig was not registered. The ID for both elements is "+t); - } - isConfigLoaded[t] = true; + LoadingUtils.makeACrash("[DummyCore]Catched an attempt to load IDummyConfig for not registered mod, this should not be possible and many things will go wrong as a result!", new IllegalStateException(c+" Is not a valid DCMod!"), false); }else { - throw new RuntimeException("Configuration handler was already initialised!"); + DCMod mod = getModFromClass(c); + mod.fmlCfg.load(); + mod.cfg.load(mod.fmlCfg); + mod.fmlCfg.save(); } } @@ -174,22 +171,32 @@ public class Core { * Use this to get the creativetab of all mod items. * @param c - the .class file of the mod. * @return The corresponding Creative Tab - * @version From DummyCore 1.0 + * @version From DummyCore 2.0 */ public static CreativeTabs getItemTabForMod(Class c) { - return itemsTabs[getIdForMod(c)]; + if(!isModRegistered(c)) + { + Notifier.notifyError("Catched an attempt to get CreativeTabs for a not registered mod, things are about go wery wrong! Offendor: "+c); + return null; + } + return getModFromClass(c).items; } /** * Use this to get the creativetab of all mod blocks. * @param c - the .class file of the mod. * @return The corresponding Creative Tab - * @version From DummyCore 1.0 + * @version From DummyCore 2.0 */ public static CreativeTabs getBlockTabForMod(Class c) { - return blocksTabs[getIdForMod(c)]; + if(!isModRegistered(c)) + { + Notifier.notifyError("Catched an attempt to get CreativeTabs for a not registered mod, things are about go wery wrong! Offendor: "+c); + return null; + } + return getModFromClass(c).blocks; } } diff --git a/DummyCore/Core/CoreInitialiser.java b/DummyCore/Core/CoreInitialiser.java index 5c4aa65..eb1517c 100755 --- a/DummyCore/Core/CoreInitialiser.java +++ b/DummyCore/Core/CoreInitialiser.java @@ -1,7 +1,12 @@ package DummyCore.Core; -import java.lang.reflect.Method; +import static DummyCore.Core.CoreInitialiser.mcVersion; +import static DummyCore.Core.CoreInitialiser.modid; +import static DummyCore.Core.CoreInitialiser.modname; +import static DummyCore.Core.CoreInitialiser.version; + import java.util.Arrays; + import net.minecraft.command.CommandHandler; import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.MinecraftForge; @@ -13,15 +18,18 @@ import DummyCore.Utils.DummyPacketHandler; import DummyCore.Utils.DummyPacketIMSG; import DummyCore.Utils.DummyPacketIMSG_Tile; import DummyCore.Utils.DummyTilePacketHandler; +import DummyCore.Utils.LoadingUtils; +import DummyCore.Utils.MiscUtils; +import DummyCore.Utils.ModVersionChecker; import DummyCore.Utils.NetProxy_Server; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStoppedEvent; import cpw.mods.fml.common.network.NetworkRegistry; @@ -32,12 +40,18 @@ import cpw.mods.fml.relauncher.Side; * @author Modbder * @version From DummyCore 1.0 */ -@Mod(modid = "DummyCore", name = "DummyCore", version = "1.13", useMetadata = false) +@Mod(modid = modid, name = modname, version = version, useMetadata = false,acceptedMinecraftVersions=mcVersion) public class CoreInitialiser{ public static final String modid = "DummyCore"; public static final String modname = "DummyCore"; - public static final String version = "1.13"; + public static final String globalVersion = "2"; + public static final String modVersion = "0"; + public static final String mcVersion = "1.7.10"; + public static final String modmcVersion = "1710"; + public static final String buildVersion = "0"; + public static final String buildPostfix = "A"; + public static final String version = globalVersion+'.'+modVersion+'.'+modmcVersion+'.'+buildVersion+'.'+buildPostfix; public static CoreInitialiser instance; public static DummyConfig cfg = new DummyConfig(); @@ -46,79 +60,29 @@ public class CoreInitialiser{ public static NetProxy_Server proxy; public static final DummyPacketHandler packetHandler = new DummyPacketHandler(); - - /* - @Subscribe - public void constructMod(FMLConstructionEvent event) - { - System.out.println(event); - System.out.println(this); - System.out.println(languageAdapter); - System.out.println(event.getASMHarvestedData().getAnnotationsFor(this)); - Set targets = event.getASMHarvestedData().getAnnotationsFor(this).get(SidedProxy.class.getName()); - System.out.println(targets.size()); - System.out.println(targets); - System.out.println(targets.isEmpty()); - NetworkRegistry.INSTANCE.register(this, this.getClass(), null, event.getASMHarvestedData()); - ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), languageAdapter); - } - */ - - - public CoreInitialiser() + public static void initMetadata(ModMetadata meta) { - /* - super(initMetadata()); - instance = this; - languageAdapter = new ILanguageAdapter.JavaAdapter(); - */ - } - - /* - @Override - public boolean registerBus(EventBus bus, LoadController controller) - { - bus.register(instance); - return true; - } - - - @Override - public Object getMod() - { - return instance; - } - */ - - public static ModMetadata initMetadata() - { - ModMetadata meta = new ModMetadata(); meta.autogenerated = false; meta.modId = modid; meta.name = modname; meta.version = version; meta.credits = "Modbder"; meta.authorList= Arrays.asList(new String[] { - "Dummy Thinking Team; Modbder; TheDen2099" + "Dummy Thinking Team", + "Modbder", + "TheDen2099", + "MrDangerDen", + "TheMysticDark" }); meta.description="Dummy Core is a required package to launch mods made by Dummy Thinking team."; - return meta; } @EventHandler public void preInit(FMLPreInitializationEvent e) { - - ModMetadata meta = e.getModMetadata(); - meta.autogenerated = false; - meta.modId = modid; - meta.name = modname; - meta.version = version; - meta.credits = "Modbder"; - meta.authorList= Arrays.asList(new String[] { - "Dummy Thinking Team; Modbder; TheDen2099" - }); - meta.description="Dummy Core is a required package to launch mods made by Dummy Thinking team."; + + initMetadata(e.getModMetadata()); + Core.registerModAbsolute(getClass(), "DummyCore", e.getModConfigurationDirectory().getAbsolutePath(),cfg,false); if(instance == null) instance = this; network = NetworkRegistry.INSTANCE.newSimpleChannel("DummyCore"); @@ -126,33 +90,36 @@ public class CoreInitialiser{ network.registerMessage(DummyPacketHandler.class, DummyPacketIMSG.class, 0, Side.CLIENT); network.registerMessage(DummyTilePacketHandler.class, DummyPacketIMSG_Tile.class, 1, Side.SERVER); network.registerMessage(DummyTilePacketHandler.class, DummyPacketIMSG_Tile.class, 1, Side.CLIENT); - try - { - Core.registerModAbsolute(getClass(), "DummyCore", e.getModConfigurationDirectory().getAbsolutePath(),cfg); - }catch(Exception ex) - { - System.out.println("Oh, come on Forge. If something has got wrong here - this is it."); - System.out.println("No, reriously, if an exception is bbeing thrown here - nothing is going to load"); - System.out.println("Like, even the gam itself, since an exception here means File System error."); - System.out.println("And a file system error here -> impossible to create literally any file in directory!"); - System.out.println("But when I'm trying to set a System.exit(-1) here - oww, not allowed?"); - System.out.println("Fine, I can work without it... Reflection time!"); - try - { - Class system = System.class; - Method exit = system.getMethod("exit", int.class); - exit.invoke(null, -1); - }catch(Exception exc) - { - exc.printStackTrace(); - return; - } - } + MinecraftForge.EVENT_BUS.register(new DummyEventHandler()); MinecraftForge.EVENT_BUS.register(new DummyDataUtils()); FMLCommonHandler.instance().bus().register(new DummyEventHandler()); proxy.registerInfo(); + + if(Loader.isModLoaded(modid)) + LoadingUtils.knownBigASMModifiers.add("DummyCore"); + if(Loader.isModLoaded("DragonAPI")) + LoadingUtils.knownBigASMModifiers.add("DragonAPI"); //<- I have nothing against Reika, I like his mods, I just like to point out that DragonAPI adds quite a lot of ASM hooks + if(Loader.isModLoaded("Optifine") || Loader.isModLoaded("optifine")) + LoadingUtils.knownBigASMModifiers.add("Optifine"); + if(Loader.isModLoaded("CoFHCore")) + LoadingUtils.knownBigASMModifiers.add("CoFHCore"); + if(Loader.isModLoaded("easycoloredlights")) + LoadingUtils.knownBigASMModifiers.add("Easy Colored Lights"); + if(Loader.isModLoaded("thaumicinfusion")) + LoadingUtils.knownBigASMModifiers.add("Thaumic Infusion"); + if(MiscUtils.classExists("api.player.forge.PlayerAPIPlugin")) + LoadingUtils.knownBigASMModifiers.add("Player API"); + if(MiscUtils.classExists("cofh.tweak.CoFHTweaks")) + LoadingUtils.knownBigASMModifiers.add("CoFH Tweaks"); + if(Loader.isModLoaded("CoFHCore")) + LoadingUtils.knownBigASMModifiers.add("CoFHCore"); + if(MiscUtils.classExists("codechicken.core.asm.CodeChickenCoreModContainer")) + LoadingUtils.knownBigASMModifiers.add("CodeChickenCore"); + + FMLCommonHandler.instance().registerCrashCallable(new DCCrashCallable()); + ModVersionChecker.addRequest(getClass(), "https://www.dropbox.com/s/iwdfv0mc4qns00f/DummyCoreVersion.txt?dl=1"); } @EventHandler @@ -162,13 +129,6 @@ public class CoreInitialiser{ proxy.registerInit(); } - @Deprecated - @EventHandler - public void onServerStart(FMLServerAboutToStartEvent e) - { - //DummyDataUtils.load(e); - } - @EventHandler public void onServerStop(FMLServerStoppedEvent e) { @@ -181,4 +141,9 @@ public class CoreInitialiser{ MinecraftServer mcserver = event.getServer(); ((CommandHandler)mcserver.getCommandManager()).registerCommand(new CommandTransfer()); } + + public static void fmlLogMissingTextures() + { + proxy.removeMissingTextureErrors(); + } }