Search in sources :

Example 1 with ResearchState

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;
}
Also used : TryResearchMessage(com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage) ResearchState(com.minecolonies.api.research.util.ResearchState)

Example 2 with ResearchState

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;
}
Also used : TryResearchMessage(com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage) ResearchState(com.minecolonies.api.research.util.ResearchState)

Example 3 with ResearchState

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);
    });
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) ResearchState(com.minecolonies.api.research.util.ResearchState) java.util(java.util) MESSAGE_RESEARCH_STARTED(com.minecolonies.api.util.constant.TranslationConstants.MESSAGE_RESEARCH_STARTED) PlayerEntity(net.minecraft.entity.player.PlayerEntity) com.minecolonies.api.research(com.minecolonies.api.research) Constants(net.minecraftforge.common.util.Constants) IResearchEffect(com.minecolonies.api.research.effects.IResearchEffect) CompoundNBT(net.minecraft.nbt.CompoundNBT) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ImmutableList(com.google.common.collect.ImmutableList) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) MAX_DEPTH(com.minecolonies.api.research.util.ResearchConstants.MAX_DEPTH) com.minecolonies.api.util(com.minecolonies.api.util) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) IResearchEffectManager(com.minecolonies.api.research.effects.IResearchEffectManager) TAG_RESEARCH_TREE(com.minecolonies.api.research.util.ResearchConstants.TAG_RESEARCH_TREE) ResearchState(com.minecolonies.api.research.util.ResearchState) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 4 with ResearchState

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);
    });
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) ResearchState(com.minecolonies.api.research.util.ResearchState) java.util(java.util) PlayerEntity(net.minecraft.entity.player.PlayerEntity) com.minecolonies.api.research(com.minecolonies.api.research) Constants(net.minecraftforge.common.util.Constants) IResearchEffect(com.minecolonies.api.research.effects.IResearchEffect) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ImmutableList(com.google.common.collect.ImmutableList) ResourceLocation(net.minecraft.util.ResourceLocation) ResearchConstants(com.minecolonies.api.research.util.ResearchConstants) IColony(com.minecolonies.api.colony.IColony) com.minecolonies.api.util(com.minecolonies.api.util) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) IResearchEffectManager(com.minecolonies.api.research.effects.IResearchEffectManager) ResearchState(com.minecolonies.api.research.util.ResearchState) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

ResearchState (com.minecolonies.api.research.util.ResearchState)4 ImmutableList (com.google.common.collect.ImmutableList)2 MinecoloniesAPIProxy (com.minecolonies.api.MinecoloniesAPIProxy)2 IColony (com.minecolonies.api.colony.IColony)2 StandardFactoryController (com.minecolonies.api.colony.requestsystem.StandardFactoryController)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 com.minecolonies.api.research (com.minecolonies.api.research)2 IResearchEffect (com.minecolonies.api.research.effects.IResearchEffect)2 IResearchEffectManager (com.minecolonies.api.research.effects.IResearchEffectManager)2 com.minecolonies.api.util (com.minecolonies.api.util)2 TryResearchMessage (com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage)2 java.util (java.util)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 ListNBT (net.minecraft.nbt.ListNBT)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Constants (net.minecraftforge.common.util.Constants)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 NotNull (org.jetbrains.annotations.NotNull)2 ResearchConstants (com.minecolonies.api.research.util.ResearchConstants)1