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());
}
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();
}
}
}
}
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)));
}
}
}
}
}
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());
}
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)));
}
}
}
}
}
Aggregations