Search in sources :

Example 1 with INBTData

use of arekkuusu.solar.api.entanglement.quantum.data.INBTData 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)

Aggregations

INBTData (arekkuusu.solar.api.entanglement.quantum.data.INBTData)1 NBTHolder (arekkuusu.solar.api.entanglement.quantum.data.INBTData.NBTHolder)1 Stopwatch (com.google.common.base.Stopwatch)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)1