use of net.minecraftforge.fml.common.discovery.ASMDataTable in project Solar by ArekkuusuJerii.
the class WorldQuantumData method init.
public static void init(ASMDataTable table) {
Stopwatch stopwatch = Stopwatch.createStarted();
List<ASMDataTable.ASMData> loaders = Lists.newArrayList(table.getAll(NBTHolder.class.getName()));
loaders.sort((l, r) -> l.getObjectName().compareToIgnoreCase(r.getClassName()));
for (ASMDataTable.ASMData loader : loaders) {
try {
Class<?> data = Class.forName(loader.getClassName());
if (INBTData.class.isAssignableFrom(data)) {
if (Stream.of(data.getConstructors()).anyMatch(c -> c.getParameterCount() == 0)) {
NBTHolder nbtData = data.getAnnotation(NBTHolder.class);
String modId = nbtData.modId();
String name = nbtData.name();
ResourceLocation location = new ResourceLocation(modId, name);
// noinspection unchecked
DATA_MAP.put(location, (Class<INBTData<?>>) data);
} else {
Solar.LOG.error("[WorldQuantumData] - Class {} has no empty constructor", data.getName());
}
} else {
Solar.LOG.error("[WorldQuantumData] - Class {} is annotated with @NBTHolder but is not an INBTData", data.getName());
}
} catch (ClassNotFoundException e) {
Solar.LOG.error("[WorldQuantumData] - Failed to find class {}", loader.getClassName());
e.printStackTrace();
}
}
Solar.LOG.info("[Discovered {} NBT data holder(s) in {}]", loaders.size(), stopwatch.stop());
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project ForestryMC by ForestryMC.
the class ModuleManager method runSetup.
public static void runSetup(FMLPreInitializationEvent event) {
ASMDataTable asmDataTable = event.getAsmData();
Map<String, List<IForestryModule>> forestryModules = ForestryPluginUtil.getForestryModules(asmDataTable);
internalHandler = new InternalModuleHandler(getInstance());
configureModules(forestryModules);
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project BloodMagic by WayofTime.
the class PluginUtil method gatherInjections.
@Nonnull
public static List<Field> gatherInjections(ASMDataTable dataTable) {
Stopwatch stopwatch = Stopwatch.createStarted();
List<Field> injectees = Lists.newArrayList();
Set<ASMDataTable.ASMData> discoveredInjectees = dataTable.getAll(BloodMagicPlugin.Inject.class.getName());
for (ASMDataTable.ASMData data : discoveredInjectees) {
try {
Class<?> asmClass = Class.forName(data.getClassName());
Field toInject = asmClass.getDeclaredField(data.getObjectName());
if (toInject.getType() != IBloodMagicAPI.class) {
BMLog.API.error("Mod requested API injection on field {}.{} which is an invalid type.", data.getClassName(), data.getObjectName());
continue;
}
BMLog.API.info("Discovered injection request at {}.{}", data.getClassName(), data.getObjectName());
injectees.add(toInject);
} catch (Exception e) {
e.printStackTrace();
}
}
BMLog.API.info("Discovered {} potential API injection(s) in {}", injectees.size(), stopwatch.stop());
return injectees;
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project Random-Things by lumien231.
the class RTEventHandler method textureStitch.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void textureStitch(TextureStitchEvent.Pre event) {
try {
ASMDataTable asmData = RandomThings.instance.getASMData();
Set<ASMData> atlasSet = asmData.getAll(AtlasSprite.class.getName());
for (ASMData data : atlasSet) {
Class clazz = Class.forName(data.getClassName());
Field f = clazz.getDeclaredField(data.getObjectName());
f.setAccessible(true);
ResourceLocation rl = new ResourceLocation((String) data.getAnnotationInfo().get("resource"));
f.set(null, event.getMap().registerSprite(rl));
}
} catch (Exception e) {
RandomThings.instance.logger.log(Level.ERROR, "Error stitching extra textures");
e.printStackTrace();
}
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project Random-Things by lumien231.
the class ModConfiguration method doAnnoations.
private void doAnnoations(Configuration configuration) {
ASMDataTable asmData = RandomThings.instance.getASMData();
Set<ASMData> atlasSet = asmData.getAll(ConfigOption.class.getName());
for (ASMData data : atlasSet) {
try {
Class clazz = Class.forName(data.getClassName());
Field f = clazz.getDeclaredField(data.getObjectName());
f.setAccessible(true);
String name = (String) data.getAnnotationInfo().get("name");
String category = (String) data.getAnnotationInfo().get("category");
String comment = (String) data.getAnnotationInfo().get("comment");
Object result = null;
if (f.getType() == boolean.class) {
result = configuration.get(category, name, f.getBoolean(null), comment).getBoolean();
} else if (f.getType() == double.class) {
result = configuration.get(category, name, f.getDouble(null), comment).getDouble();
} else if (f.getType() == int.class) {
result = configuration.get(category, name, f.getInt(null), comment).getInt();
}
if (result != null) {
f.set(null, result);
} else {
throw new RuntimeException("Invalid Data Type for Config annotation: " + f.getType());
}
} catch (Exception e) {
RandomThings.instance.logger.log(Level.ERROR, "Error stitching extra textures");
e.printStackTrace();
}
}
}
Aggregations