org.bukkit.inventory.RecipeChoice Java Examples
The following examples show how to use
org.bukkit.inventory.RecipeChoice.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MinecraftRecipeService.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
/** * This returns the shape of a given {@link Recipe}. * For any shapeless {@link Recipe} the result will be equivalent to * {@link RecipeSnapshot#getRecipeInput(Recipe)}. * For a {@link ShapedRecipe} this method will fix the order so it matches a * 3x3 crafting grid. * * @param recipe * The {@link Recipe} to get the shape from * @return An Array of {@link RecipeChoice} representing the shape of this {@link Recipe} */ public RecipeChoice[] getRecipeShape(Recipe recipe) { Validate.notNull(recipe, "Recipe must not be null!"); if (recipe instanceof ShapedRecipe) { List<RecipeChoice> choices = new LinkedList<>(); for (String row : ((ShapedRecipe) recipe).getShape()) { int columns = row.toCharArray().length; for (char key : row.toCharArray()) { choices.add(((ShapedRecipe) recipe).getChoiceMap().get(key)); } while (columns < 3) { choices.add(null); columns++; } } return choices.toArray(new RecipeChoice[0]); } else { return snapshot.getRecipeInput(recipe); } }
Example #2
Source File: TestRecipeService.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Test public void testShapelessRecipeShape() { MinecraftRecipeService service = new MinecraftRecipeService(plugin); Assertions.assertThrows(IllegalArgumentException.class, () -> service.getRecipeShape(null)); NamespacedKey key = new NamespacedKey(plugin, "shapeless_test"); ShapelessRecipe recipe = new ShapelessRecipe(key, new ItemStack(Material.TNT_MINECART)); MaterialChoice choice = new MaterialChoice(Material.TNT); recipe.addIngredient(choice); server.addRecipe(recipe); service.refresh(); Assertions.assertArrayEquals(new RecipeChoice[] { choice }, service.getRecipeShape(recipe)); }
Example #3
Source File: ItemService.java From Transport-Pipes with MIT License | 5 votes |
public ShapedRecipe createShapedRecipe(TransportPipes transportPipes, String recipeKey, ItemStack resultItem, String[] shape, Object... ingredientMap) { ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(transportPipes, recipeKey), resultItem); recipe.shape(shape); for (int i = 0; i < ingredientMap.length; i += 2) { char c = (char) ingredientMap[i]; if (ingredientMap[i + 1] instanceof Material) { recipe.setIngredient(c, (Material) ingredientMap[i + 1]); } else { recipe.setIngredient(c, new RecipeChoice.MaterialChoice(((Collection<Material>) ingredientMap[i + 1]).stream().collect(Collectors.toList()))); } } return recipe; }
Example #4
Source File: UpsideDownCraftsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private ShapedRecipe getUpsideDownRecipeFor(ShapedRecipe recipe){ ShapedRecipe upsideDown = VersionUtils.getVersionUtils().createShapedRecipe(recipe.getResult(), UUID.randomUUID().toString()); upsideDown.shape(getUpsideDownShape(recipe.getShape())); Map<Character, RecipeChoice> recipeChoiceMap = recipe.getChoiceMap(); for (char c : recipeChoiceMap.keySet()){ upsideDown.setIngredient(c, recipeChoiceMap.get(c)); } return upsideDown; }
Example #5
Source File: RandomizedCraftsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private ShapedRecipe cloneRecipeWithResult(ShapedRecipe recipe, ItemStack result){ ShapedRecipe clone = VersionUtils.getVersionUtils().createShapedRecipe(result, UUID.randomUUID().toString()); clone.shape(recipe.getShape()); Map<Character, RecipeChoice> recipeChoiceMap = recipe.getChoiceMap(); for (char c : recipeChoiceMap.keySet()){ clone.setIngredient(c, recipeChoiceMap.get(c)); } return clone; }
Example #6
Source File: ElectricFurnace.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public void registerDefaultRecipes() { SlimefunPlugin.getMinecraftRecipeService().subscribe(snapshot -> { for (FurnaceRecipe recipe : snapshot.getRecipes(FurnaceRecipe.class)) { RecipeChoice choice = recipe.getInputChoice(); if (choice instanceof MaterialChoice) { for (Material input : ((MaterialChoice) choice).getChoices()) { registerRecipe(4, new ItemStack[] { new ItemStack(input) }, new ItemStack[] { recipe.getResult() }); } } } }); }
Example #7
Source File: ChestSlimefunGuide.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
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); RecipeChoiceTask task = new RecipeChoiceTask(); if (optional.isPresent()) { MinecraftRecipe<?> mcRecipe = optional.get(); RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipeService().getRecipeShape(recipe); if (choices.length == 1 && choices[0] instanceof MaterialChoice) { recipeItems[4] = new ItemStack(((MaterialChoice) choices[0]).getChoices().get(0)); if (((MaterialChoice) choices[0]).getChoices().size() > 1) { task.add(recipeSlots[4], (MaterialChoice) choices[0]); } } else { for (int i = 0; i < choices.length; i++) { if (choices[i] instanceof MaterialChoice) { recipeItems[i] = new ItemStack(((MaterialChoice) choices[i]).getChoices().get(0)); if (((MaterialChoice) choices[i]).getChoices().size() > 1) { task.add(recipeSlots[i], (MaterialChoice) choices[i]); } } } } recipeType = new RecipeType(mcRecipe); result = recipe.getResult(); } else { recipeItems = new ItemStack[] { null, null, null, null, new CustomItem(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()); } }