use of com.minecolonies.api.research.util.ResearchConstants.TAG_RESEARCH_TREE in project minecolonies by Minecolonies.
the class LocalResearchTree method readFromNBT.
@Override
public void readFromNBT(final CompoundNBT compound, final IResearchEffectManager effects) {
researchTree.clear();
inProgress.clear();
isComplete.clear();
maxLevelResearchCompleted.clear();
NBTUtils.streamCompound(compound.getList(TAG_RESEARCH_TREE, Constants.NBT.TAG_COMPOUND)).map(researchCompound -> (ILocalResearch) StandardFactoryController.getInstance().deserialize(researchCompound)).forEach(research -> {
// / region Updated ID helper.
if (!MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearch(research.getBranch(), research.getId())) {
if (ResearchCompatMap.updateMap.containsKey(research.getId().getPath())) {
final ResearchState currentState = research.getState();
final int progress = research.getProgress();
research = new LocalResearch(ResearchCompatMap.updateMap.get(research.getId().getPath()), new ResourceLocation(com.minecolonies.api.util.constant.Constants.MOD_ID, research.getBranch().getPath()), research.getDepth());
research.setState(currentState);
research.setProgress(progress);
Log.getLogger().warn("Research " + research.getId().getPath() + " was in colony save file, and was updated to " + research.getId());
} else if (research.getBranch().getNamespace().contains("minecraft")) {
final ResearchState currentState = research.getState();
final int progress = research.getProgress();
research = new LocalResearch(new ResourceLocation(com.minecolonies.api.util.constant.Constants.MOD_ID, research.getId().getPath()), new ResourceLocation(com.minecolonies.api.util.constant.Constants.MOD_ID, research.getBranch().getPath()), research.getDepth());
research.setState(currentState);
research.setProgress(progress);
} else {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().warn("Research " + research.getId() + " was in colony save file, but was not in CompatMap.");
}
}
}
if (research.getState() == ResearchState.FINISHED) {
// or to have a different research that was in a now-removed data pack. But those will get just thrown away.
if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearch(research.getBranch(), research.getId())) {
for (final IResearchEffect<?> effect : MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().getResearch(research.getBranch(), research.getId()).getEffects()) {
effects.applyEffect(effect);
}
} else {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().warn("Research " + research.getId() + " was in colony save file, but not found as valid current research. Progress on this research may be reset.");
}
}
}
addResearch(research.getBranch(), research);
});
}
use of com.minecolonies.api.research.util.ResearchConstants.TAG_RESEARCH_TREE in project minecolonies by Minecolonies.
the class LocalResearchTree method writeToNBT.
@Override
public void writeToNBT(final CompoundNBT compound) {
@NotNull final ListNBT researchList = researchTree.values().stream().flatMap(map -> map.values().stream()).map(research -> StandardFactoryController.getInstance().serialize(research)).collect(NBTUtils.toListNBT());
compound.put(TAG_RESEARCH_TREE, researchList);
}
Aggregations