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