Search in sources :

Example 1 with ILocalResearchTree

use of com.minecolonies.api.research.ILocalResearchTree in project AdvancedPeripherals by Seniorendi.

the class MineColonies method getResearch.

/**
 * Returns a map with all possible researches
 *
 * @param branch     The branch, there are only a few branches
 * @param researches The primary researches of the branch
 * @param colony     The colony
 * @return a map with all possible researches
 */
public static List<Object> getResearch(ResourceLocation branch, List<ResourceLocation> researches, IColony colony) {
    List<Object> result = new ArrayList<>();
    if (researches != null) {
        for (ResourceLocation researchName : researches) {
            // All global possible researches
            IGlobalResearchTree globalTree = IGlobalResearchTree.getInstance();
            // The research tree of the colony
            ILocalResearchTree colonyTree = colony.getResearchManager().getResearchTree();
            IGlobalResearch research = globalTree.getResearch(branch, researchName);
            if (research == null)
                continue;
            ILocalResearch colonyResearch = colonyTree.getResearch(branch, researchName);
            List<String> effects = new ArrayList<>();
            for (IResearchEffect<?> researchEffect : research.getEffects()) effects.add(researchEffect.getDesc().toString());
            Map<String, Object> map = new HashMap<>();
            map.put("id", researchName.toString());
            map.put("name", research.getName().getString());
            map.put("researchEffects", effects);
            map.put("status", colonyResearch == null ? ResearchState.NOT_STARTED.toString() : colonyResearch.getState());
            List<Object> childrenResearch = getResearch(branch, research.getChildren(), colony);
            if (!childrenResearch.isEmpty())
                map.put("children", childrenResearch);
            result.add(map);
        }
    }
    return result;
}
Also used : ILocalResearchTree(com.minecolonies.api.research.ILocalResearchTree) ILocalResearch(com.minecolonies.api.research.ILocalResearch) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IGlobalResearchTree(com.minecolonies.api.research.IGlobalResearchTree) ResourceLocation(net.minecraft.util.ResourceLocation) IGlobalResearch(com.minecolonies.api.research.IGlobalResearch)

Aggregations

IGlobalResearch (com.minecolonies.api.research.IGlobalResearch)1 IGlobalResearchTree (com.minecolonies.api.research.IGlobalResearchTree)1 ILocalResearch (com.minecolonies.api.research.ILocalResearch)1 ILocalResearchTree (com.minecolonies.api.research.ILocalResearchTree)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ResourceLocation (net.minecraft.util.ResourceLocation)1