use of com.minecolonies.api.research.IGlobalResearchTree in project minecolonies by Minecolonies.
the class GenericRecipeUtils method getResearchDisplayName.
@NotNull
private static ITextComponent getResearchDisplayName(@NotNull final ResourceLocation researchId) {
final IGlobalResearchTree researchTree = IGlobalResearchTree.getInstance();
// first, try to see if this is a research id
final IGlobalResearch research = researchTree.getResearch(researchId);
if (research != null) {
return research.getName();
}
// next, see if it's an effect id
final Set<IGlobalResearch> researches = researchTree.getResearchForEffect(researchId);
if (researches != null && !researches.isEmpty()) {
// there might be more than one, but this should be sufficient for now
return researches.iterator().next().getName();
}
// otherwise it may be an effect with no research (perhaps disabled via datapack)
return new StringTextComponent("???");
}
use of com.minecolonies.api.research.IGlobalResearchTree 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;
}
use of com.minecolonies.api.research.IGlobalResearchTree 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;
}
use of com.minecolonies.api.research.IGlobalResearchTree in project AdvancedPeripherals by Seniorendi.
the class ColonyPeripheral method getResearch.
@LuaFunction(mainThread = true)
public final Object getResearch() throws LuaException {
IColony colony = getColony();
IGlobalResearchTree globalTree = IGlobalResearchTree.getInstance();
Map<String, Object> result = new HashMap<>();
for (ResourceLocation branch : globalTree.getBranches()) result.put(branch.toString(), MineColonies.getResearch(branch, globalTree.getPrimaryResearch(branch), colony));
return result;
}
Aggregations