Search in sources :

Example 1 with CustomRecipe

use of com.minecolonies.coremod.colony.crafting.CustomRecipe in project minecolonies by Minecolonies.

the class GenericRecipeCategory method findRecipes.

@NotNull
public List<IGenericRecipe> findRecipes(@NotNull final Map<IRecipeType<?>, List<IGenericRecipe>> vanilla) {
    final List<IGenericRecipe> recipes = new ArrayList<>();
    // vanilla shaped and shapeless crafting recipes
    if (this.crafting.canLearnCraftingRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.CRAFTING)) {
            if (!this.crafting.canLearnLargeRecipes() && recipe.getGridSize() > 2)
                continue;
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // vanilla furnace recipes (do we want to check smoking and blasting too?)
    if (this.crafting.canLearnFurnaceRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.SMELTING)) {
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // custom MineColonies additional recipes
    for (final CustomRecipe customRecipe : CustomRecipeManager.getInstance().getRecipes(this.crafting.getCustomRecipeKey())) {
        final IRecipeStorage recipeStorage = customRecipe.getRecipeStorage();
        if (!recipeStorage.getAlternateOutputs().isEmpty()) {
            // this is a multi-output recipe; assume it replaces a bunch of vanilla
            // recipes we already added above
            recipes.removeIf(r -> ItemStackUtils.compareItemStacksIgnoreStackSize(recipeStorage.getPrimaryOutput(), r.getPrimaryOutput()));
            recipes.removeIf(r -> recipeStorage.getAlternateOutputs().stream().anyMatch(s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, r.getPrimaryOutput())));
        }
        recipes.add(GenericRecipeUtils.create(customRecipe, recipeStorage));
    }
    // and even more recipes that can't be taught, but are just inherent in the worker AI
    recipes.addAll(this.crafting.getAdditionalRecipesForDisplayPurposesOnly());
    return recipes.stream().sorted(Comparator.comparing(IGenericRecipe::getLevelSort).thenComparing(r -> r.getPrimaryOutput().getItem().getRegistryName())).collect(Collectors.toList());
}
Also used : BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IIngredients(mezz.jei.api.ingredients.IIngredients) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) IRecipeType(net.minecraft.item.crafting.IRecipeType) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) LootTableAnalyzer(com.minecolonies.coremod.colony.crafting.LootTableAnalyzer) BlockState(net.minecraft.block.BlockState) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) IDrawableStatic(mezz.jei.api.gui.drawable.IDrawableStatic) Collectors(java.util.stream.Collectors) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) Blocks(net.minecraft.block.Blocks) ResourceLocation(net.minecraft.util.ResourceLocation) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) VanillaTypes(mezz.jei.api.constants.VanillaTypes) NotNull(org.jetbrains.annotations.NotNull) IJob(com.minecolonies.api.colony.jobs.IJob) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CustomRecipe

use of com.minecolonies.coremod.colony.crafting.CustomRecipe in project minecolonies by Minecolonies.

the class AbstractCraftingBuildingModule method checkForWorkerSpecificRecipes.

@Override
public void checkForWorkerSpecificRecipes() {
    final IRecipeManager recipeManager = IColonyManager.getInstance().getRecipeManager();
    for (final CustomRecipe newRecipe : CustomRecipeManager.getInstance().getRecipes(getCustomRecipeKey())) {
        final IRecipeStorage recipeStorage = newRecipe.getRecipeStorage();
        final IToken<?> recipeToken = recipeManager.checkOrAddRecipe(recipeStorage);
        if (newRecipe.isValidForBuilding(building)) {
            IToken<?> duplicateFound = null;
            boolean forceReplace = false;
            for (IToken<?> token : recipes) {
                if (token == recipeToken) {
                    duplicateFound = token;
                    break;
                }
                final IRecipeStorage storage = recipeManager.getRecipes().get(token);
                // Let's verify that this recipe doesn't exist in an improved form
                if (storage != null && storage.getPrimaryOutput().equals(recipeStorage.getPrimaryOutput(), true)) {
                    List<ItemStorage> recipeInput1 = storage.getCleanedInput();
                    List<ItemStorage> recipeInput2 = recipeStorage.getCleanedInput();
                    if (recipeInput1.size() != recipeInput2.size()) {
                        continue;
                    }
                    if (recipeInput1.size() > 1) {
                        recipeInput1.sort(Comparator.comparing(item -> Objects.hash(item.hashCode(), item.getAmount())));
                        recipeInput2.sort(Comparator.comparing(item -> Objects.hash(item.hashCode(), item.getAmount())));
                    }
                    boolean allMatch = true;
                    for (int i = 0; i < recipeInput1.size(); i++) {
                        if (!recipeInput1.get(i).getItem().equals(recipeInput2.get(i).getItem())) {
                            allMatch = false;
                            break;
                        }
                    }
                    if (allMatch) {
                        duplicateFound = token;
                        if (storage.getRecipeType() instanceof ClassicRecipe && recipeStorage.getRecipeType() instanceof MultiOutputRecipe) {
                            // This catches the old custom recipes without a RecipeSource
                            forceReplace = true;
                        }
                        if (storage.getRecipeSource() != null && storage.getRecipeSource().equals(recipeStorage.getRecipeSource())) {
                            // This will only happen if the tokens don't match, aka: the recipe has changed.
                            forceReplace = true;
                        }
                        break;
                    }
                }
            }
            if (duplicateFound == null) {
                addRecipeToList(recipeToken, true);
                building.getColony().getRequestManager().onColonyUpdate(request -> request.getRequest() instanceof IDeliverable && ((IDeliverable) request.getRequest()).matches(recipeStorage.getPrimaryOutput()));
                markDirty();
            } else if ((forceReplace || newRecipe.getMustExist()) && !(duplicateFound.equals(recipeToken))) {
                // We found the base recipe for a multi-recipe, replace it with the multi-recipe
                replaceRecipe(duplicateFound, recipeToken);
                building.getColony().getRequestManager().onColonyUpdate(request -> request.getRequest() instanceof IDeliverable && ((IDeliverable) request.getRequest()).matches(recipeStorage.getPrimaryOutput()));
                // Clean up old 'classic' recipes that the new multi-recipe replaces
                final List<ItemStack> alternates = recipeStorage.getAlternateOutputs();
                for (IToken<?> token : recipes) {
                    final IRecipeStorage storage = recipeManager.getRecipes().get(token);
                    if (storage.getRecipeType() instanceof ClassicRecipe && ItemStackUtils.compareItemStackListIgnoreStackSize(alternates, storage.getPrimaryOutput(), false, true)) {
                        removeRecipe(token);
                    }
                }
                building.getColony().getRequestManager().onColonyUpdate(request -> request.getRequest() instanceof IDeliverable && recipeStorage.getAlternateOutputs().stream().anyMatch(i -> ((IDeliverable) request.getRequest()).matches(i)));
                markDirty();
            }
        } else {
            if (recipes.contains(recipeToken)) {
                removeRecipe(recipeToken);
                markDirty();
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) SettingKey(com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) RECIPE_IMPROVED(com.minecolonies.api.util.constant.TranslationConstants.RECIPE_IMPROVED) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) ListNBT(net.minecraft.nbt.ListNBT) PublicWorkerCraftingProductionResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingProductionResolver) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TAG_RECIPES(com.minecolonies.api.util.constant.NbtTagConstants.TAG_RECIPES) Predicate(java.util.function.Predicate) LootParameters(net.minecraft.loot.LootParameters) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) com.minecolonies.api.crafting(com.minecolonies.api.crafting) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) com.minecolonies.api.colony.buildings.modules(com.minecolonies.api.colony.buildings.modules) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) PublicWorkerCraftingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingRequestResolver) CRAFTING_REDUCEABLE(com.minecolonies.api.util.constant.TagConstants.CRAFTING_REDUCEABLE) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) IWareHouse(com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) com.minecolonies.api.util(com.minecolonies.api.util) RECIPES(com.minecolonies.api.research.util.ResearchConstants.RECIPES) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) ModTags(com.minecolonies.api.items.ModTags) IColonyManager(com.minecolonies.api.colony.IColonyManager) Tuple(net.minecraft.util.Tuple) CrafterRecipeSetting(com.minecolonies.coremod.colony.buildings.modules.settings.CrafterRecipeSetting) Blocks(net.minecraft.block.Blocks) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) PacketBuffer(net.minecraft.network.PacketBuffer) IJob(com.minecolonies.api.colony.jobs.IJob) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)

Example 3 with CustomRecipe

use of com.minecolonies.coremod.colony.crafting.CustomRecipe in project minecolonies by Minecolonies.

the class ClientEventHandler method handleCrafterRecipeTooltips.

/**
 * Display crafter recipe-related information on the client.
 * @param colony   The colony to check against, if one is present.
 * @param toolTip  The tooltip to add the text onto.
 * @param item     The item that will have the tooltip text added.
 */
private static void handleCrafterRecipeTooltips(@Nullable final IColony colony, final List<ITextComponent> toolTip, final Item item) {
    final List<CustomRecipe> recipes = CustomRecipeManager.getInstance().getRecipeByOutput(item);
    if (recipes.isEmpty()) {
        return;
    }
    for (CustomRecipe rec : recipes) {
        if (!rec.getShowTooltip() || rec.getCrafter().length() < 2) {
            continue;
        }
        final BuildingEntry craftingBuilding = crafterToBuilding.get().get(rec.getCrafter());
        if (craftingBuilding == null)
            continue;
        final ITextComponent craftingBuildingName = getFullBuildingName(craftingBuilding);
        if (rec.getMinBuildingLevel() > 0) {
            final String schematicName = craftingBuilding.getRegistryName().getPath();
            // the above is not guaranteed to match (and indeed doesn't for a few buildings), but
            // does match for all currently interesting crafters, at least.  there doesn't otherwise
            // appear to be an easy way to get the schematic name from a BuildingEntry ... or
            // unless we can change how colony.hasBuilding uses its parameter...
            final IFormattableTextComponent reqLevelText = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_BUILDLEVEL_TOOLTIP_GUI, craftingBuildingName, rec.getMinBuildingLevel());
            if (colony != null && colony.hasBuilding(schematicName, rec.getMinBuildingLevel(), true)) {
                reqLevelText.setStyle(Style.EMPTY.withColor(TextFormatting.AQUA));
            } else {
                reqLevelText.setStyle(Style.EMPTY.withColor(TextFormatting.RED));
            }
            toolTip.add(reqLevelText);
        } else {
            final IFormattableTextComponent reqBuildingTxt = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_AVAILABLE_TOOLTIP_GUI, craftingBuildingName).setStyle(Style.EMPTY.withItalic(true).withColor(TextFormatting.GRAY));
            toolTip.add(reqBuildingTxt);
        }
        if (rec.getRequiredResearchId() != null) {
            final Set<IGlobalResearch> researches;
            if (IMinecoloniesAPI.getInstance().getGlobalResearchTree().hasResearch(rec.getRequiredResearchId())) {
                researches = new HashSet<>();
                researches.add(IMinecoloniesAPI.getInstance().getGlobalResearchTree().getResearch(rec.getRequiredResearchId()));
            } else {
                researches = IMinecoloniesAPI.getInstance().getGlobalResearchTree().getResearchForEffect(rec.getRequiredResearchId());
            }
            if (researches != null) {
                final TextFormatting researchFormat;
                if (colony != null && (colony.getResearchManager().getResearchTree().hasCompletedResearch(rec.getRequiredResearchId()) || colony.getResearchManager().getResearchEffects().getEffectStrength(rec.getRequiredResearchId()) > 0)) {
                    researchFormat = TextFormatting.AQUA;
                } else {
                    researchFormat = TextFormatting.RED;
                }
                for (IGlobalResearch research : researches) {
                    toolTip.add(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_REQUIRES_RESEARCH_TOOLTIP_GUI, research.getName()).setStyle(Style.EMPTY.withColor(researchFormat)));
                }
            }
        }
    }
}
Also used : CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) IGlobalResearch(com.minecolonies.api.research.IGlobalResearch)

Example 4 with CustomRecipe

use of com.minecolonies.coremod.colony.crafting.CustomRecipe in project minecolonies by ldtteam.

the class GenericRecipeCategory method findRecipes.

@NotNull
public List<IGenericRecipe> findRecipes(@NotNull final Map<IRecipeType<?>, List<IGenericRecipe>> vanilla) {
    final List<IGenericRecipe> recipes = new ArrayList<>();
    // vanilla shaped and shapeless crafting recipes
    if (this.crafting.canLearnCraftingRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.CRAFTING)) {
            if (!this.crafting.canLearnLargeRecipes() && recipe.getGridSize() > 2)
                continue;
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // vanilla furnace recipes (do we want to check smoking and blasting too?)
    if (this.crafting.canLearnFurnaceRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.SMELTING)) {
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // custom MineColonies additional recipes
    for (final CustomRecipe customRecipe : CustomRecipeManager.getInstance().getRecipes(this.crafting.getCustomRecipeKey())) {
        final IRecipeStorage recipeStorage = customRecipe.getRecipeStorage();
        if (!recipeStorage.getAlternateOutputs().isEmpty()) {
            // this is a multi-output recipe; assume it replaces a bunch of vanilla
            // recipes we already added above
            recipes.removeIf(r -> ItemStackUtils.compareItemStacksIgnoreStackSize(recipeStorage.getPrimaryOutput(), r.getPrimaryOutput()));
            recipes.removeIf(r -> recipeStorage.getAlternateOutputs().stream().anyMatch(s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, r.getPrimaryOutput())));
        }
        recipes.add(GenericRecipeUtils.create(customRecipe, recipeStorage));
    }
    // and even more recipes that can't be taught, but are just inherent in the worker AI
    recipes.addAll(this.crafting.getAdditionalRecipesForDisplayPurposesOnly());
    return recipes.stream().sorted(Comparator.comparing(IGenericRecipe::getLevelSort).thenComparing(r -> r.getPrimaryOutput().getItem().getRegistryName())).collect(Collectors.toList());
}
Also used : BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IIngredients(mezz.jei.api.ingredients.IIngredients) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) IRecipeType(net.minecraft.item.crafting.IRecipeType) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) LootTableAnalyzer(com.minecolonies.coremod.colony.crafting.LootTableAnalyzer) BlockState(net.minecraft.block.BlockState) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) IDrawableStatic(mezz.jei.api.gui.drawable.IDrawableStatic) Collectors(java.util.stream.Collectors) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) Blocks(net.minecraft.block.Blocks) ResourceLocation(net.minecraft.util.ResourceLocation) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) VanillaTypes(mezz.jei.api.constants.VanillaTypes) NotNull(org.jetbrains.annotations.NotNull) IJob(com.minecolonies.api.colony.jobs.IJob) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CustomRecipe

use of com.minecolonies.coremod.colony.crafting.CustomRecipe in project minecolonies by ldtteam.

the class ClientEventHandler method handleCrafterRecipeTooltips.

/**
 * Display crafter recipe-related information on the client.
 * @param colony   The colony to check against, if one is present.
 * @param toolTip  The tooltip to add the text onto.
 * @param item     The item that will have the tooltip text added.
 */
private static void handleCrafterRecipeTooltips(@Nullable final IColony colony, final List<ITextComponent> toolTip, final Item item) {
    final List<CustomRecipe> recipes = CustomRecipeManager.getInstance().getRecipeByOutput(item);
    if (recipes.isEmpty()) {
        return;
    }
    for (CustomRecipe rec : recipes) {
        if (!rec.getShowTooltip() || rec.getCrafter().length() < 2) {
            continue;
        }
        final BuildingEntry craftingBuilding = crafterToBuilding.get().get(rec.getCrafter());
        if (craftingBuilding == null)
            continue;
        final ITextComponent craftingBuildingName = getFullBuildingName(craftingBuilding);
        if (rec.getMinBuildingLevel() > 0) {
            final String schematicName = craftingBuilding.getRegistryName().getPath();
            // the above is not guaranteed to match (and indeed doesn't for a few buildings), but
            // does match for all currently interesting crafters, at least.  there doesn't otherwise
            // appear to be an easy way to get the schematic name from a BuildingEntry ... or
            // unless we can change how colony.hasBuilding uses its parameter...
            final IFormattableTextComponent reqLevelText = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_BUILDLEVEL_TOOLTIP_GUI, craftingBuildingName, rec.getMinBuildingLevel());
            if (colony != null && colony.hasBuilding(schematicName, rec.getMinBuildingLevel(), true)) {
                reqLevelText.setStyle(Style.EMPTY.withColor(TextFormatting.AQUA));
            } else {
                reqLevelText.setStyle(Style.EMPTY.withColor(TextFormatting.RED));
            }
            toolTip.add(reqLevelText);
        } else {
            final IFormattableTextComponent reqBuildingTxt = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_AVAILABLE_TOOLTIP_GUI, craftingBuildingName).setStyle(Style.EMPTY.withItalic(true).withColor(TextFormatting.GRAY));
            toolTip.add(reqBuildingTxt);
        }
        if (rec.getRequiredResearchId() != null) {
            final Set<IGlobalResearch> researches;
            if (IMinecoloniesAPI.getInstance().getGlobalResearchTree().hasResearch(rec.getRequiredResearchId())) {
                researches = new HashSet<>();
                researches.add(IMinecoloniesAPI.getInstance().getGlobalResearchTree().getResearch(rec.getRequiredResearchId()));
            } else {
                researches = IMinecoloniesAPI.getInstance().getGlobalResearchTree().getResearchForEffect(rec.getRequiredResearchId());
            }
            if (researches != null) {
                final TextFormatting researchFormat;
                if (colony != null && (colony.getResearchManager().getResearchTree().hasCompletedResearch(rec.getRequiredResearchId()) || colony.getResearchManager().getResearchEffects().getEffectStrength(rec.getRequiredResearchId()) > 0)) {
                    researchFormat = TextFormatting.AQUA;
                } else {
                    researchFormat = TextFormatting.RED;
                }
                for (IGlobalResearch research : researches) {
                    toolTip.add(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_REQUIRES_RESEARCH_TOOLTIP_GUI, research.getName()).setStyle(Style.EMPTY.withColor(researchFormat)));
                }
            }
        }
    }
}
Also used : CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) IGlobalResearch(com.minecolonies.api.research.IGlobalResearch)

Aggregations

CustomRecipe (com.minecolonies.coremod.colony.crafting.CustomRecipe)6 BuildingEntry (com.minecolonies.api.colony.buildings.registry.BuildingEntry)4 IJob (com.minecolonies.api.colony.jobs.IJob)4 CustomRecipeManager (com.minecolonies.coremod.colony.crafting.CustomRecipeManager)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Blocks (net.minecraft.block.Blocks)4 ItemStack (net.minecraft.item.ItemStack)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)3 NotNull (org.jetbrains.annotations.NotNull)3 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IColony (com.minecolonies.api.colony.IColony)2 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 com.minecolonies.api.colony.buildings.modules (com.minecolonies.api.colony.buildings.modules)2 ICraftingBuildingModule (com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule)2 ISettingKey (com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)2 IWareHouse (com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)2