Search in sources :

Example 6 with ILocalResearch

use of com.minecolonies.api.research.ILocalResearch in project minecolonies by ldtteam.

the class BuildingUniversity method onColonyTick.

@Override
public void onColonyTick(@NotNull final IColony colony) {
    super.onColonyTick(colony);
    final List<ILocalResearch> inProgress = colony.getResearchManager().getResearchTree().getResearchInProgress();
    final WorkerBuildingModule module = getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == ModJobs.researcher);
    int i = 1;
    for (final ILocalResearch research : inProgress) {
        if (i > module.getAssignedCitizen().size()) {
            return;
        }
        for (final ICitizenData data : getAllAssignedCitizen()) {
            data.getCitizenSkillHandler().addXpToSkill(module.getSecondarySkill(), 25.0, data);
        }
        if (colony.getResearchManager().getResearchTree().getResearch(research.getBranch(), research.getId()).research(colony.getResearchManager().getResearchEffects(), colony.getResearchManager().getResearchTree())) {
            onSuccess(research);
        }
        i++;
    }
}
Also used : ILocalResearch(com.minecolonies.api.research.ILocalResearch) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 7 with ILocalResearch

use of com.minecolonies.api.research.ILocalResearch in project minecolonies by ldtteam.

the class LocalResearchFactory method deserialize.

@NotNull
@Override
public ILocalResearch deserialize(@NotNull final IFactoryController controller, @NotNull final CompoundNBT nbt) {
    final int state = nbt.getInt(TAG_STATE);
    final ResourceLocation id = new ResourceLocation(nbt.getString(TAG_ID));
    final ResourceLocation branch = new ResourceLocation(nbt.getString(TAG_BRANCH));
    final int depth = nbt.getInt(TAG_RESEARCH_LVL);
    final int progress = nbt.getInt(TAG_PROGRESS);
    final ILocalResearch research = getNewInstance(id, branch, depth);
    research.setState(ResearchState.values()[state]);
    research.setProgress(progress);
    return research;
}
Also used : ILocalResearch(com.minecolonies.api.research.ILocalResearch) ResourceLocation(net.minecraft.util.ResourceLocation) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ILocalResearch

use of com.minecolonies.api.research.ILocalResearch in project minecolonies by ldtteam.

the class LocalResearchFactory method deserialize.

@Override
public ILocalResearch deserialize(IFactoryController controller, PacketBuffer buffer) throws Throwable {
    final int state = buffer.readInt();
    final ResourceLocation id = buffer.readResourceLocation();
    final ResourceLocation branch = buffer.readResourceLocation();
    final int progress = buffer.readInt();
    final int depth = buffer.readInt();
    final ILocalResearch research = getNewInstance(id, branch, depth);
    research.setState(ResearchState.values()[state]);
    research.setProgress(progress);
    return research;
}
Also used : ILocalResearch(com.minecolonies.api.research.ILocalResearch) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 9 with ILocalResearch

use of com.minecolonies.api.research.ILocalResearch 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;
}
Also used : ILocalResearchTree(com.minecolonies.api.research.ILocalResearchTree) ILocalResearch(com.minecolonies.api.research.ILocalResearch) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IGlobalResearchTree(com.minecolonies.api.research.IGlobalResearchTree) ResourceLocation(net.minecraft.util.ResourceLocation) IGlobalResearch(com.minecolonies.api.research.IGlobalResearch)

Aggregations

ILocalResearch (com.minecolonies.api.research.ILocalResearch)9 ResourceLocation (net.minecraft.util.ResourceLocation)5 IColony (com.minecolonies.api.colony.IColony)2 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)2 NotNull (org.jetbrains.annotations.NotNull)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)1 IGlobalResearch (com.minecolonies.api.research.IGlobalResearch)1 IGlobalResearchTree (com.minecolonies.api.research.IGlobalResearchTree)1 ILocalResearchTree (com.minecolonies.api.research.ILocalResearchTree)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1