Change the plugin system to a module system and slit up modules

-Moved the woodpile from the arboriculture module to the charcoal module
-Moved the backpacks from the storage module to the backpacks module
-Moved the crates from the storage module to the creates module
-Added the database module with a new storage for individuals
-Added a gui element system to improve the alyzer api
-Added a species plugin interface to handle the database gui
-Added some alyzer methods to the species plugin to move the alyzer
integration later to it
This commit is contained in:
Nedelosk committed 2017-11-02 16:03:33 +01:00
1 parent ee272de168
commit 88fd031fb4
277 files changed
+7361 -1930

No files matched your search

@@ -0,0 +1,71 @@
package forestry.modules;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import forestry.core.utils.Log;
public class ForestryPluginUtil {
private ForestryPluginUtil() {
}
public static Map<String, List<IForestryModule>> getForestryModules(ASMDataTable asmDataTable) {
List<IForestryModule> instances = getInstances(asmDataTable, ForestryModule.class, IForestryModule.class);
Map<String, List<IForestryModule>> modules = new LinkedHashMap<>();
for(IForestryModule module : instances){
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
modules.computeIfAbsent(info.containerID(), k-> new ArrayList<>()).add(module);
}
return modules;
}
public static String getComment(IForestryModule module) {
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
String comment = I18n.translateToLocal(info.unlocalizedDescription());
Set<ResourceLocation> dependencies = module.getDependencyUids();
if(!dependencies.isEmpty()){
Iterator<ResourceLocation> iDependencies = dependencies.iterator();
StringBuilder builder = new StringBuilder(comment);
builder.append("\n");
builder.append("Dependencies: [ ");
builder.append(iDependencies.next());
while(iDependencies.hasNext()){
ResourceLocation uid = iDependencies.next();
builder.append(", ").append(uid.toString());
}
builder.append(" ]");
comment = builder.toString();
}
return comment;
}
private static <T> List<T> getInstances(ASMDataTable asmDataTable, Class annotationClass, Class<T> instanceClass) {
String annotationClassName = annotationClass.getCanonicalName();
Set<ASMDataTable.ASMData> asmDatas = asmDataTable.getAll(annotationClassName);
List<T> instances = new ArrayList<>();
for (ASMDataTable.ASMData asmData : asmDatas) {
try {
Class<?> asmClass = Class.forName(asmData.getClassName());
Class<? extends T> asmInstanceClass = asmClass.asSubclass(instanceClass);
T instance = asmInstanceClass.newInstance();
instances.add(instance);
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
Log.error("Failed to load: {}", asmData.getClassName(), e);
}
}
return instances;
}
}