Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.inventory.ShapedRecipe Class Reference
Inheritance diagram for org.bukkit.inventory.ShapedRecipe:
org.bukkit.inventory.Recipe

Public Member Functions

 ShapedRecipe (ItemStack result)
 
ShapedRecipe shape (final String...shape)
 
ShapedRecipe setIngredient (char key, MaterialData ingredient)
 
ShapedRecipe setIngredient (char key, Material ingredient)
 
ShapedRecipe setIngredient (char key, Material ingredient, int raw)
 
Map< Character, ItemStackgetIngredientMap ()
 
String[] getShape ()
 
ItemStack getResult ()
 

Detailed Description

Represents a shaped (ie normal) crafting recipe.

Definition at line 14 of file ShapedRecipe.java.

Constructor & Destructor Documentation

org.bukkit.inventory.ShapedRecipe.ShapedRecipe ( ItemStack  result)

Create a shaped recipe to craft the specified ItemStack. The constructor merely determines the result and type; to set the actual recipe, you'll need to call the appropriate methods.

Parameters
resultThe item you want the recipe to create.
See also
ShapedRecipe::shape(String...)
ShapedRecipe::setIngredient(char, Material)
ShapedRecipe::setIngredient(char, Material, int)
ShapedRecipe::setIngredient(char, MaterialData)

Definition at line 30 of file ShapedRecipe.java.

30  {
31  this.output = new ItemStack(result);
32  }

Member Function Documentation

Map<Character, ItemStack> org.bukkit.inventory.ShapedRecipe.getIngredientMap ( )

Get a copy of the ingredients map.

Returns
The mapping of character to ingredients.

Definition at line 119 of file ShapedRecipe.java.

119  {
120  HashMap<Character, ItemStack> result = new HashMap<Character, ItemStack>();
121  for (Map.Entry<Character, ItemStack> ingredient : ingredients.entrySet()) {
122  if (ingredient.getValue() == null) {
123  result.put(ingredient.getKey(), null);
124  } else {
125  result.put(ingredient.getKey(), ingredient.getValue().clone());
126  }
127  }
128  return result;
129  }
ItemStack org.bukkit.inventory.ShapedRecipe.getResult ( )

Get the result.

Returns
The result stack.

Implements org.bukkit.inventory.Recipe.

Definition at line 145 of file ShapedRecipe.java.

145  {
146  return output.clone();
147  }
String [] org.bukkit.inventory.ShapedRecipe.getShape ( )

Get the shape.

Returns
The recipe's shape.

Definition at line 136 of file ShapedRecipe.java.

136  {
137  return rows.clone();
138  }
ShapedRecipe org.bukkit.inventory.ShapedRecipe.setIngredient ( char  key,
MaterialData  ingredient 
)

Sets the material that a character in the recipe shape refers to.

Parameters
keyThe character that represents the ingredient in the shape.
ingredientThe ingredient.
Returns
The changed recipe, so you can chain calls.

Definition at line 77 of file ShapedRecipe.java.

References org.bukkit.material.MaterialData.getData(), and org.bukkit.material.MaterialData.getItemType().

Referenced by org.bukkit.inventory.ShapedRecipe.setIngredient().

77  {
78  return setIngredient(key, ingredient.getItemType(), ingredient.getData());
79  }
ShapedRecipe setIngredient(char key, MaterialData ingredient)
ShapedRecipe org.bukkit.inventory.ShapedRecipe.setIngredient ( char  key,
Material  ingredient 
)

Sets the material that a character in the recipe shape refers to.

Parameters
keyThe character that represents the ingredient in the shape.
ingredientThe ingredient.
Returns
The changed recipe, so you can chain calls.

Definition at line 88 of file ShapedRecipe.java.

References org.bukkit.inventory.ShapedRecipe.setIngredient().

88  {
89  return setIngredient(key, ingredient, 0);
90  }
ShapedRecipe setIngredient(char key, MaterialData ingredient)
ShapedRecipe org.bukkit.inventory.ShapedRecipe.setIngredient ( char  key,
Material  ingredient,
int  raw 
)

Sets the material that a character in the recipe shape refers to.

Parameters
keyThe character that represents the ingredient in the shape.
ingredientThe ingredient.
rawThe raw material data as an integer.
Returns
The changed recipe, so you can chain calls.
Deprecated:
Magic value

Definition at line 102 of file ShapedRecipe.java.

102  {
103  Validate.isTrue(ingredients.containsKey(key), "Symbol does not appear in the shape:", key);
104 
105  // -1 is the old wildcard, map to Short.MAX_VALUE as the new one
106  if (raw == -1) {
107  raw = Short.MAX_VALUE;
108  }
109 
110  ingredients.put(key, new ItemStack(ingredient, 1, (short) raw));
111  return this;
112  }
ShapedRecipe org.bukkit.inventory.ShapedRecipe.shape ( final String...  shape)

Set the shape of this recipe to the specified rows. Each character represents a different ingredient; exactly what each character represents is set separately. The first row supplied corresponds with the upper most part of the recipe on the workbench e.g. if all three rows are supplies the first string represents the top row on the workbench.

Parameters
shapeThe rows of the recipe (up to 3 rows).
Returns
The changed recipe, so you can chain calls.

Definition at line 45 of file ShapedRecipe.java.

45  {
46  Validate.notNull(shape, "Must provide a shape");
47  Validate.isTrue(shape.length > 0 && shape.length < 4, "Crafting recipes should be 1, 2, 3 rows, not ", shape.length);
48 
49  for (String row : shape) {
50  Validate.notNull(row, "Shape cannot have null rows");
51  Validate.isTrue(row.length() > 0 && row.length() < 4, "Crafting rows should be 1, 2, or 3 characters, not ", row.length());
52  }
53  this.rows = new String[shape.length];
54  for (int i = 0; i < shape.length; i++) {
55  this.rows[i] = shape[i];
56  }
57 
58  // Remove character mappings for characters that no longer exist in the shape
59  HashMap<Character, ItemStack> newIngredients = new HashMap<Character, ItemStack>();
60  for (String row : shape) {
61  for (Character c : row.toCharArray()) {
62  newIngredients.put(c, ingredients.get(c));
63  }
64  }
65  this.ingredients = newIngredients;
66 
67  return this;
68  }
ShapedRecipe shape(final String...shape)

The documentation for this class was generated from the following file: