Class ShapedRecipe

java.lang.Object
net.minecraft.recipe.ShapedRecipe
All Implemented Interfaces:
CraftingRecipe, Recipe<CraftingInventory>
Direct Known Subclasses:
MapExtendingRecipe

public class ShapedRecipe
extends Object
implements CraftingRecipe
  • Field Details

  • Constructor Details

  • Method Details

    • getId

      public Identifier getId()
      Specified by:
      getId in interface Recipe<CraftingInventory>
    • getSerializer

      public RecipeSerializer<?> getSerializer()
      Specified by:
      getSerializer in interface Recipe<CraftingInventory>
    • getGroup

      @Environment(CLIENT) public String getGroup()
      Optional group this recipe belongs in. Used to group recipes into different categories by the recipe book.
      Specified by:
      getGroup in interface Recipe<CraftingInventory>
    • getOutput

      public ItemStack getOutput()
      Specified by:
      getOutput in interface Recipe<CraftingInventory>
    • getIngredients

      public DefaultedList<Ingredient> getIngredients()
      The ingredients accepted as inputs for this recipe. Used by the recipe book when displaying a ghost form of this recipe on the crafting grid as well as for previewing the possible inputs in the book itself.
      Specified by:
      getIngredients in interface Recipe<CraftingInventory>
    • fits

      @Environment(CLIENT) public boolean fits​(int width, int height)
      Determines whether this recipe's pattern will fit into the available crafting area.
      Specified by:
      fits in interface Recipe<CraftingInventory>
    • matches

      public boolean matches​(CraftingInventory craftingInventory, World world)
      Description copied from interface: Recipe
      Determines whether this recipe matches the contents currently placed inside the available crafting grid.
      Specified by:
      matches in interface Recipe<CraftingInventory>
    • matchesPattern

      private boolean matchesPattern​(CraftingInventory inv, int offsetX, int offsetY, boolean flipped)
    • craft

      public ItemStack craft​(CraftingInventory craftingInventory)
      Description copied from interface: Recipe
      Crafts this recipe.

      This method may perform side effects on the inventory argument.

      This method should return a new item stack on each call.

      Specified by:
      craft in interface Recipe<CraftingInventory>
      Returns:
      the resulting item stack
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • createPatternMatrix

      private static DefaultedList<Ingredient> createPatternMatrix​(String[] pattern, Map<String,​Ingredient> symbols, int width, int height)
      Compiles a pattern and series of symbols into a list of ingredients (the matrix) suitable for matching against a crafting grid.
    • removePadding

      static String[] removePadding​(String[] pattern)
      Removes empty space from around the recipe pattern.

      Turns patterns such as:

       
       "   o"
       "   a"
       "    "
       
       
      Into:
       
       "o"
       "a"
       
       
      Returns:
      a new recipe pattern with all leading and trailing empty rows/columns removed
    • findFirstSymbol

      private static int findFirstSymbol​(String line)
    • findLastSymbol

      private static int findLastSymbol​(String pattern)
    • getPattern

      private static String[] getPattern​(JsonArray json)
    • readSymbols

      private static Map<String,​Ingredient> readSymbols​(JsonObject json)
      Reads the pattern symbols.
      Returns:
      a mapping from a symbol to the ingredient it represents
    • getItemStack

      public static ItemStack getItemStack​(JsonObject json)