Last active
August 29, 2015 14:08
-
-
Save Unh0lyTigg/a415ef3cbcab79cbb862 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.unh0lytigg.circuitboards.base; | |
| import java.lang.annotation.Annotation; | |
| import java.util.Set; | |
| import cpw.mods.fml.common.discovery.ASMDataTable; | |
| import cpw.mods.fml.common.discovery.ASMDataTable.ASMData; | |
| public class ASMUser { | |
| private static ASMDataTable table; | |
| public static void loadTable(ASMDataTable table) { | |
| ASMUser.table = table; | |
| } | |
| public static Set<ASMData> getData(Class<? extends Annotation> target) { | |
| return table.getAll(target.getName()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Mod(modid="circuitboards-base", name="CircuitBoards", version="$version") | |
| public class BaseMod { | |
| @Instance("circuitboards-base") | |
| public static BaseMod INSTANCE; | |
| @SidedProxy(clientSide="org.unh0lytigg.circuitboards.base.proxy.ProxyClient",serverSide="org.unh0lytigg.circuitboards.base.proxy.Proxy") | |
| public static Proxy PROXY; | |
| @LoggerInstance("CircuitBoards") | |
| public static Logger LOGGER; | |
| @EventHandler | |
| public void preinit(FMLPreInitializationEvent event) { | |
| PROXY.preInit(event); | |
| } | |
| @EventHandler | |
| public void init(FMLInitializationEvent event) { | |
| PROXY.init(); | |
| } | |
| @EventHandler | |
| public void postinit(FMLPostInitializationEvent event) { | |
| PROXY.postInit(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void loadLoggers() { | |
| try { | |
| Set<ASMData> dataset = ASMUser.getData(LoggerInstance.class); | |
| System.out.println("Loggers: " + dataset.size()); | |
| for (ASMData data : dataset) { | |
| String loggername = (String)data.getAnnotationInfo().get("value"); | |
| Class<?> c = Class.forName(data.getClassName()); | |
| Field f = ReflectionHelper.findField(c, data.getObjectName()); | |
| if (!((f.getModifiers() & Modifier.STATIC) == Modifier.STATIC)) | |
| throw new IllegalStateException("Cannot set logger on non-static field"); | |
| if (loggername == null) { | |
| f.set(null, LogManager.getLogger(c.getName())); | |
| } else { | |
| f.set(null, LogManager.getLogger(loggername)); | |
| } | |
| } | |
| } catch (Exception e) { e.printStackTrace(); } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment