use of com.minecolonies.api.research.util.ResearchState in project minecolonies by ldtteam.
the class WindowResearchTree method drawResearchItem.
/**
* Draw the entirety of an individual research item on a tree, including icons and tooltips.
*
* @param view the view to append it to.
* @param offsetX the horizontal offset of the left side of the research block.
* @param offsetY the vertical offset of the top side of the research block.
* @param research the global research characteristics to draw.
* @param abandoned the abandoned status of the parent of the research, if one is present.
* @return abandoned status, true if the research is blocked in the local colony the completion of a sibling research, or an ancestor's sibling's research.
*/
private boolean drawResearchItem(final ZoomDragView view, final int offsetX, final int offsetY, final IGlobalResearch research, boolean abandoned) {
final ILocalResearchTree tree = building.getColony().getResearchManager().getResearchTree();
final boolean parentResearched = tree.hasCompletedResearch(research.getParent());
final IGlobalResearch parentResearch = IGlobalResearchTree.getInstance().getResearch(branch, research.getParent());
final ResearchState state = tree.getResearch(branch, research.getId()) == null ? ResearchState.NOT_STARTED : tree.getResearch(branch, research.getId()).getState();
final int progress = tree.getResearch(branch, research.getId()) == null ? 0 : tree.getResearch(branch, research.getId()).getProgress();
if (mc.player.isCreative() && state == ResearchState.IN_PROGRESS && MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchCreativeCompletion.get() && progress < IGlobalResearchTree.getInstance().getBranchData(branch).getBaseTime(research.getDepth())) {
Network.getNetwork().sendToServer(new TryResearchMessage(building, research.getId(), research.getBranch(), false));
}
if (research.getDepth() != 1 && (state != ResearchState.FINISHED && state != ResearchState.IN_PROGRESS) && parentResearch.hasOnlyChild() && parentResearch.hasResearchedChild(tree)) {
abandoned = true;
}
final ResearchButtonState researchState = getResearchButtonState(abandoned, parentResearched, research, state);
drawResearchBoxes(view, offsetX, offsetY, research, researchState, progress);
drawResearchReqsAndCosts(view, offsetX, offsetY, research, researchState);
drawResearchIcons(view, offsetX, offsetY, research, researchState);
drawResearchTexts(view, offsetX, offsetY, research, researchState, progress);
return abandoned;
}
use of com.minecolonies.api.research.util.ResearchState in project minecolonies by Minecolonies.
the class WindowResearchTree method drawResearchItem.
/**
* Draw the entirety of an individual research item on a tree, including icons and tooltips.
*
* @param view the view to append it to.
* @param offsetX the horizontal offset of the left side of the research block.
* @param offsetY the vertical offset of the top side of the research block.
* @param research the global research characteristics to draw.
* @param abandoned the abandoned status of the parent of the research, if one is present.
* @return abandoned status, true if the research is blocked in the local colony the completion of a sibling research, or an ancestor's sibling's research.
*/
private boolean drawResearchItem(final ZoomDragView view, final int offsetX, final int offsetY, final IGlobalResearch research, boolean abandoned) {
final ILocalResearchTree tree = building.getColony().getResearchManager().getResearchTree();
final boolean parentResearched = tree.hasCompletedResearch(research.getParent());
final IGlobalResearch parentResearch = IGlobalResearchTree.getInstance().getResearch(branch, research.getParent());
final ResearchState state = tree.getResearch(branch, research.getId()) == null ? ResearchState.NOT_STARTED : tree.getResearch(branch, research.getId()).getState();
final int progress = tree.getResearch(branch, research.getId()) == null ? 0 : tree.getResearch(branch, research.getId()).getProgress();
if (mc.player.isCreative() && state == ResearchState.IN_PROGRESS && MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchCreativeCompletion.get() && progress < IGlobalResearchTree.getInstance().getBranchData(branch).getBaseTime(research.getDepth())) {
Network.getNetwork().sendToServer(new TryResearchMessage(building, research.getId(), research.getBranch(), false));
}
if (research.getDepth() != 1 && (state != ResearchState.FINISHED && state != ResearchState.IN_PROGRESS) && parentResearch.hasOnlyChild() && parentResearch.hasResearchedChild(tree)) {
abandoned = true;
}
final ResearchButtonState researchState = getResearchButtonState(abandoned, parentResearched, research, state);
drawResearchBoxes(view, offsetX, offsetY, research, researchState, progress);
drawResearchReqsAndCosts(view, offsetX, offsetY, research, researchState);
drawResearchIcons(view, offsetX, offsetY, research, researchState);
drawResearchTexts(view, offsetX, offsetY, research, researchState, progress);
return abandoned;
}
use of com.minecolonies.api.research.util.ResearchState 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.ResearchState in project minecolonies by ldtteam.
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);
});
}
Aggregations