Search in sources :

Example 6 with GlobalResearch

use of com.minecolonies.coremod.research.GlobalResearch in project minecolonies by ldtteam.

the class ResearchListener method calcResearchTree.

/**
 * Parses out a GlobalResearch map to apply parent/child relationships between researches, and to graft and warn about inconsistent relationships.
 *
 * @param researchMap   A Map of ResearchIDs to GlobalResearches to turn into a GlobalResearchTree.
 * @return              An IGlobalResearchTree containing the validated researches.
 */
private IGlobalResearchTree calcResearchTree(final Map<ResourceLocation, GlobalResearch> researchMap) {
    final IGlobalResearchTree researchTree = MinecoloniesAPIProxy.getInstance().getGlobalResearchTree();
    // The research tree should be reset on world unload, but certain events and disconnects break that.  Do it here, too.
    researchTree.reset();
    // Next, set up child relationships, and handle cases where they're not logically consistent.
    for (final Map.Entry<ResourceLocation, GlobalResearch> entry : researchMap.entrySet()) {
        if (entry.getValue().getParent().getPath().isEmpty() && entry.getValue().getDepth() > 1) {
            // For now, log and re-graft entries with no parent and depth to the root of their branch.
            entry.setValue(new GlobalResearch(entry.getValue().getId(), entry.getValue().getBranch(), 1, entry.getValue().getEffects(), entry.getValue().getIconTextureResourceLocation(), entry.getValue().getIconItemStack(), entry.getValue().isImmutable()));
            Log.getLogger().error(entry.getValue().getBranch() + "/" + entry.getKey() + "could not be attached to tree: inconsistent depth for parentage.");
        } else if (!entry.getValue().getParent().getPath().isEmpty()) {
            if (researchMap.containsKey(entry.getValue().getParent())) {
                if (researchMap.get(entry.getValue().getParent()).getBranch().equals(entry.getValue().getBranch())) {
                    researchMap.get(entry.getValue().getParent()).addChild(entry.getValue());
                } else {
                    Log.getLogger().error(entry.getValue().getBranch() + "/" + entry.getKey() + "could not be attached to " + entry.getValue().getParent() + " on " + researchMap.get(entry.getValue().getParent()).getBranch());
                    // For now, log and re-graft entries with inconsistent parent-child relationships as a separate primary research.
                    entry.setValue(new GlobalResearch(entry.getValue().getId(), entry.getValue().getBranch(), 1, entry.getValue().getEffects(), entry.getValue().getIconTextureResourceLocation(), entry.getValue().getIconItemStack(), entry.getValue().isImmutable()));
                }
            } else {
                Log.getLogger().error(entry.getValue().getBranch() + "/" + entry.getKey() + " could not find parent " + entry.getValue().getParent());
                // For now, log and re-graft entries with inconsistent parent-child relationships as a separate primary research.
                entry.setValue(new GlobalResearch(entry.getValue().getId(), entry.getValue().getBranch(), 1, entry.getValue().getEffects(), entry.getValue().getIconTextureResourceLocation(), entry.getValue().getIconItemStack(), entry.getValue().isImmutable()));
            }
        }
        researchTree.addResearch(entry.getValue().getBranch(), entry.getValue(), true);
    }
    return researchTree;
}
Also used : GlobalResearch(com.minecolonies.coremod.research.GlobalResearch) ResourceLocation(net.minecraft.util.ResourceLocation) HashMap(java.util.HashMap) Map(java.util.Map) IGlobalResearchTree(com.minecolonies.api.research.IGlobalResearchTree)

Aggregations

GlobalResearch (com.minecolonies.coremod.research.GlobalResearch)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 IGlobalResearchTree (com.minecolonies.api.research.IGlobalResearchTree)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 IResearchRequirement (com.minecolonies.api.research.IResearchRequirement)2 ResearchEffectCategory (com.minecolonies.coremod.research.ResearchEffectCategory)2 Collection (java.util.Collection)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 DedicatedServer (net.minecraft.server.dedicated.DedicatedServer)2