Java Code Examples for org.bukkit.Bukkit#recipeIterator()

The following examples show how to use org.bukkit.Bukkit#recipeIterator() . 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: NMSUtils.java    From Transport-Pipes with MIT License 5 votes vote down vote up
public static boolean isFurnaceBurnableItem(ItemStack item) {

        Iterator<Recipe> recipeIt = Bukkit.recipeIterator();
        while (recipeIt.hasNext()) {
            Recipe recipe = recipeIt.next();
            if (!(recipe instanceof FurnaceRecipe))
                continue;
            if(!((FurnaceRecipe) recipe).getInputChoice().test(item))
                continue;
            return true;
        }

        return false;
    }
 
Example 2
Source File: RandomizedCraftsListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable(){
    Iterator<Recipe> iterator = Bukkit.recipeIterator();
    List<ItemStack> results = new ArrayList<>();
    Set<ShapedRecipe> removeRecipes = new HashSet<>();

    Recipe recipe;
    while (iterator.hasNext()){
        recipe = iterator.next();
        if (!(recipe instanceof ShapedRecipe)){
            continue;
        }

        results.add(recipe.getResult());
        removeRecipes.add((ShapedRecipe) recipe);
    }

    Collections.shuffle(results);
    Iterator<ItemStack> resultIterator = results.iterator();
    Set<ShapedRecipe> randomizedRecipes = new HashSet<>();

    for (ShapedRecipe oldRecipe : removeRecipes){
        ShapedRecipe newRecipe = cloneRecipeWithResult(oldRecipe, resultIterator.next());
        randomizedRecipes.add(newRecipe);

        VersionUtils.getVersionUtils().removeRecipeFor(newRecipe.getResult());
    }

    randomizedRecipes.forEach(r -> Bukkit.getServer().addRecipe(r));
}
 
Example 3
Source File: RecipeManager.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static void removeRecipe(Material type) {
	Iterator<Recipe> recipes = Bukkit.recipeIterator();
	Recipe recipe;
	while (recipes.hasNext()) {
		recipe = recipes.next();
		if (recipe != null && recipe.getResult().getType() == type) {
			recipes.remove();
		}
	}
}
 
Example 4
Source File: RecipeManager.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static void removeVanillaRecipe(Material type) {
	Iterator<Recipe> recipes = Bukkit.recipeIterator();
	Recipe recipe;
	while (recipes.hasNext()) {
		recipe = recipes.next();
		if (recipe != null && recipe.getResult().isSimilar(new ItemStack(type))) {
			recipes.remove();
		}
	}
}
 
Example 5
Source File: RecipeManager.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static void removeRecipe(Material type, short durability) {
	Iterator<Recipe> recipes = Bukkit.recipeIterator();
	Recipe recipe;
	while (recipes.hasNext()) {
		recipe = recipes.next();
		if (recipe != null && recipe.getResult().getType() == type && recipe.getResult().getDurability() == durability) {
			recipes.remove();
		}
	}
}
 
Example 6
Source File: RecipeCalculator.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static ItemStack getSmeltedOutput(Material type) {
	ItemStack result = null;
	Iterator<Recipe> iter = Bukkit.recipeIterator();
	while (iter.hasNext()) {
	   Recipe recipe = iter.next();
	   if (!(recipe instanceof FurnaceRecipe)) continue;
	   if (((FurnaceRecipe) recipe).getInput().getType() != type) continue;
	   result = recipe.getResult();
	   break;
	}
	
	return result;
}