Search in sources :

Example 11 with ASMDataTable

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());
}
Also used : NBTHolder(arekkuusu.solar.api.entanglement.quantum.data.INBTData.NBTHolder) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ResourceLocation(net.minecraft.util.ResourceLocation) Stopwatch(com.google.common.base.Stopwatch) INBTData(arekkuusu.solar.api.entanglement.quantum.data.INBTData)

Example 12 with ASMDataTable

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);
}
Also used : ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 13 with ASMDataTable

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;
}
Also used : Field(java.lang.reflect.Field) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) Stopwatch(com.google.common.base.Stopwatch) Nonnull(javax.annotation.Nonnull)

Example 14 with ASMDataTable

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();
    }
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) Field(java.lang.reflect.Field) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) AtlasSprite(lumien.randomthings.lib.AtlasSprite) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 15 with ASMDataTable

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();
        }
    }
}
Also used : ConfigOption(lumien.randomthings.lib.ConfigOption) ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) Field(java.lang.reflect.Field) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable)

Aggregations

ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)15 Field (java.lang.reflect.Field)4 ASMData (net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData)4 Stopwatch (com.google.common.base.Stopwatch)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 Nonnull (javax.annotation.Nonnull)2 Property (net.minecraftforge.common.config.Property)2 ModAnnotation (net.minecraftforge.fml.common.discovery.asm.ModAnnotation)2 Side (net.minecraftforge.fml.relauncher.Side)2 Pair (org.apache.commons.lang3.tuple.Pair)2 BloodMagicPlugin (WayofTime.bloodmagic.api.BloodMagicPlugin)1 IBloodMagicPlugin (WayofTime.bloodmagic.api.IBloodMagicPlugin)1 GuideBook (amerifrance.guideapi.api.GuideBook)1 IGuideBook (amerifrance.guideapi.api.IGuideBook)1 Book (amerifrance.guideapi.api.impl.Book)1 INBTData (arekkuusu.solar.api.entanglement.quantum.data.INBTData)1 NBTHolder (arekkuusu.solar.api.entanglement.quantum.data.INBTData.NBTHolder)1 Joiner (com.google.common.base.Joiner)1