use of arekkuusu.solar.api.entanglement.quantum.data.INBTData.NBTHolder 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 arekkuusu.solar.api.entanglement.quantum.data.INBTData.NBTHolder in project Solar by ArekkuusuJerii.
the class WorldQuantumData method writeToNBT.
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
NBTTagList list = new NBTTagList();
saved.forEach((k, v) -> {
// noinspection SuspiciousMethodCalls
if (v.save() && DATA_MAP.containsValue(v.getClass())) {
NBTHolder nbtData = v.getClass().getAnnotation(NBTHolder.class);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("modId", nbtData.modId());
tag.setString("name", nbtData.name());
tag.setUniqueId("key", k);
tag.setTag("data", v.write());
list.appendTag(tag);
}
});
compound.setTag(EntangledIItemHandler.NBT_TAG, list);
return compound;
}
Aggregations