Search in sources :

Example 1 with IResearchEffectManager

use of com.minecolonies.api.research.effects.IResearchEffectManager 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 2 with IResearchEffectManager

use of com.minecolonies.api.research.effects.IResearchEffectManager 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

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 ResearchState (com.minecolonies.api.research.util.ResearchState)2 com.minecolonies.api.util (com.minecolonies.api.util)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 MAX_DEPTH (com.minecolonies.api.research.util.ResearchConstants.MAX_DEPTH)1