[1.12.2] How to specify item data for ShapedRecipe ingredient.

Discussion in 'Spigot Plugin Development' started by Blastoise, Aug 9, 2018.

  1. I want to add a ShapedRecipe using a zombie head as one of the ingredients. Whereas the code below does what I want as far as ingredients are concerned, the given method
    Code (Java):
    ShapedRecipe#setIngredient(char key, Material ingredient, int raw)
    is marked as deprecated on the Bukkit API JavaDoc, and I can not seem to find a replacement for it which does the trick. My question is, therefore, what is the proper way to accomplish this, i.e., to add item data to recipe ingredients in a ShapedRecipe?

    Here is my code:
    Code (Java):
    private void addZombieSpawnerRecipe() {
        // Todo: create a zombie spawner ItemStack.
        // Bonus question: how do I do this?
        ShapedRecipe recipe = new ShapedRecipe(
            new NamespacedKey(this, "zombie_spawner"),
            new ItemStack(Material.MOB_SPAWNER)

        recipe.shape("III", "ISI", "III");
        recipe.setIngredient('I', Material.IRON_FENCE);

        // Here I am using a deprecated method.
        recipe.setIngredient('S', Material.SKULL_ITEM, SkullType.ZOMBIE.ordinal());

  2. Hello ! There is a function : "recette.setIngredient(char key, MaterialData ingredient)"

    Example in your case :
    Code (Java):
    recipe.setIngredient('S', new ItemStack(Material.SKULL_ITEM, 1, (short) 1).getData());
  3. data values are deprecated in 1.12 but AFAIK they are still the only way to handle things like this and so as no alternative is provided you'll have to use them. I was going to suggest using MaterialData as that looked like a nice abstraction but it seems that whole class is being obsoleted :/.