@@ -1,33 +1,47 @@
|
||||
package org.bukkit.inventory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
/**
|
||||
* Represents a shaped (ie normal) crafting recipe.
|
||||
*/
|
||||
public class ShapedRecipe implements Recipe {
|
||||
private ItemStack output;
|
||||
public class ShapedRecipe implements Recipe, Keyed {
|
||||
private final NamespacedKey key;
|
||||
private final ItemStack output;
|
||||
private String[] rows;
|
||||
private Map<Character, ItemStack> ingredients = new HashMap<Character, ItemStack>();
|
||||
|
||||
@Deprecated
|
||||
public ShapedRecipe(ItemStack result) {
|
||||
this.key = NamespacedKey.randomKey();
|
||||
this.output = new 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.
|
||||
*
|
||||
* @param key the unique recipe key
|
||||
* @param result The item you want the recipe to create.
|
||||
* @see ShapedRecipe#shape(String...)
|
||||
* @see ShapedRecipe#setIngredient(char, Material)
|
||||
* @see ShapedRecipe#setIngredient(char, Material, int)
|
||||
* @see ShapedRecipe#setIngredient(char, MaterialData)
|
||||
*/
|
||||
public ShapedRecipe(ItemStack result) {
|
||||
public ShapedRecipe(NamespacedKey key, ItemStack result) {
|
||||
Preconditions.checkArgument(key != null, "key");
|
||||
|
||||
this.key = key;
|
||||
this.output = new ItemStack(result);
|
||||
}
|
||||
|
||||
@@ -149,4 +163,9 @@ public class ShapedRecipe implements Recipe {
|
||||
public ItemStack getResult() {
|
||||
return output.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,23 +5,33 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Keyed;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
/**
|
||||
* Represents a shapeless recipe, where the arrangement of the ingredients on
|
||||
* the crafting grid does not matter.
|
||||
*/
|
||||
public class ShapelessRecipe implements Recipe {
|
||||
private ItemStack output;
|
||||
private List<ItemStack> ingredients = new ArrayList<ItemStack>();
|
||||
public class ShapelessRecipe implements Recipe, Keyed {
|
||||
private final NamespacedKey key;
|
||||
private final ItemStack output;
|
||||
private final List<ItemStack> ingredients = new ArrayList<ItemStack>();
|
||||
|
||||
@Deprecated
|
||||
public ShapelessRecipe(ItemStack result) {
|
||||
this.key = NamespacedKey.randomKey();
|
||||
this.output = new ItemStack(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shapeless 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.
|
||||
*
|
||||
* @param key the unique recipe key
|
||||
* @param result The item you want the recipe to create.
|
||||
* @see ShapelessRecipe#addIngredient(Material)
|
||||
* @see ShapelessRecipe#addIngredient(MaterialData)
|
||||
@@ -30,7 +40,8 @@ public class ShapelessRecipe implements Recipe {
|
||||
* @see ShapelessRecipe#addIngredient(int,MaterialData)
|
||||
* @see ShapelessRecipe#addIngredient(int,Material,int)
|
||||
*/
|
||||
public ShapelessRecipe(ItemStack result) {
|
||||
public ShapelessRecipe(NamespacedKey key, ItemStack result) {
|
||||
this.key = key;
|
||||
this.output = new ItemStack(result);
|
||||
}
|
||||
|
||||
@@ -223,4 +234,9 @@ public class ShapelessRecipe implements Recipe {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.bukkit.inventory.meta;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
public interface KnowledgeBookMeta extends ItemMeta {
|
||||
|
||||
/**
|
||||
* Checks for the existence of recipes in the book.
|
||||
*
|
||||
* @return true if the book has recipes
|
||||
*/
|
||||
boolean hasRecipes();
|
||||
|
||||
/**
|
||||
* Gets all the recipes in the book.
|
||||
*
|
||||
* @return list of all the recipes in the book
|
||||
*/
|
||||
List<NamespacedKey> getRecipes();
|
||||
|
||||
/**
|
||||
* Clears the existing book recipes, and sets the book to use the provided
|
||||
* recipes.
|
||||
*
|
||||
* @param recipes A list of recipes to set the book to use
|
||||
*/
|
||||
void setRecipes(List<NamespacedKey> recipes);
|
||||
|
||||
/**
|
||||
* Adds new recipe to the end of the book.
|
||||
*
|
||||
* @param recipes A list of recipe keys
|
||||
*/
|
||||
void addRecipe(NamespacedKey... recipes);
|
||||
|
||||
@Override
|
||||
KnowledgeBookMeta clone();
|
||||
}
|
||||
Reference in New Issue
Block a user