Search in sources :

Example 1 with MinecraftRecipe

use of io.github.bakedlibs.dough.recipes.MinecraftRecipe in project Slimefun4 by Slimefun.

the class SurvivalSlimefunGuide method showMinecraftRecipe.

private void showMinecraftRecipe(Recipe[] recipes, int index, ItemStack item, PlayerProfile profile, Player p, boolean addToHistory) {
    Recipe recipe = recipes[index];
    ItemStack[] recipeItems = new ItemStack[9];
    RecipeType recipeType = RecipeType.NULL;
    ItemStack result = null;
    Optional<MinecraftRecipe<? super Recipe>> optional = MinecraftRecipe.of(recipe);
    AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
    if (optional.isPresent()) {
        showRecipeChoices(recipe, recipeItems, task);
        recipeType = new RecipeType(optional.get());
        result = recipe.getResult();
    } else {
        recipeItems = new ItemStack[] { null, null, null, null, new CustomItemStack(Material.BARRIER, "&4We are somehow unable to show you this Recipe :/"), null, null, null, null };
    }
    ChestMenu menu = create(p);
    if (addToHistory) {
        profile.getGuideHistory().add(item, index);
    }
    displayItem(menu, profile, p, item, result, recipeType, recipeItems, task);
    if (recipes.length > 1) {
        for (int i = 27; i < 36; i++) {
            menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
        }
        menu.addItem(28, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
            if (index > 0) {
                showMinecraftRecipe(recipes, index - 1, item, profile, p, true);
            }
            return false;
        });
        menu.addItem(34, ChestMenuUtils.getNextButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
            if (index < recipes.length - 1) {
                showMinecraftRecipe(recipes, index + 1, item, profile, p, true);
            }
            return false;
        });
    }
    menu.open(p);
    if (!task.isEmpty()) {
        task.start(menu.toInventory());
    }
}
Also used : MinecraftRecipe(io.github.bakedlibs.dough.recipes.MinecraftRecipe) Recipe(org.bukkit.inventory.Recipe) RecipeType(io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType) MinecraftRecipe(io.github.bakedlibs.dough.recipes.MinecraftRecipe) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) AsyncRecipeChoiceTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask)

Aggregations

CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)1 MinecraftRecipe (io.github.bakedlibs.dough.recipes.MinecraftRecipe)1 RecipeType (io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType)1 AsyncRecipeChoiceTask (io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask)1 ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)1 ItemStack (org.bukkit.inventory.ItemStack)1 Recipe (org.bukkit.inventory.Recipe)1