public class CmItem {
public static final ItemStack NEXT_BUTTON = new ItemStack(Material.WOOD_BUTTON); public static final ItemStack PREV_BUTTON = new ItemStack(Material.WOOD_BUTTON); public static final ItemStack PAGE = new ItemStack(Material.PAPER); public static final ItemStack EXIT = new ItemStack(Material.IRON_DOOR); public static Map<String, CmItem> cmItemMap = Maps.newHashMap(); public static List<String> allowedSmeltIngredient = new ArrayList<>(); public ItemStack item; public CmCategory category; public List<Inventory> recipeMenu = new ArrayList<>(); public List<ItemRecipe> recipeList; public boolean vanillaCraft; private int recipesCount = 0; public CmItem(CmCategory category, ItemStack item, List<ItemRecipe> recipeList) {
this.category = category; this.item = item; this.recipeList = recipeList; this.vanillaCraft = false;}
public CmItem(CmCategory category, ItemStack item, List<ItemRecipe> recipeList, boolean vanillaCraft) {
this.category = category; this.item = item; this.recipeList = recipeList; this.vanillaCraft = vanillaCraft;}
public static void addIngredientsToFurnaceWhitelist() {
Bukkit.recipeIterator().forEachRemaining(Recipe -> {
try {
FurnaceRecipe furnaceRecipe = (FurnaceRecipe) Recipe;allowedSmeltIngredient.add(furnaceRecipe.getInput().toString());} catch (Exception ignored) {
}
});}
public void register() {
this.category.add(item);CyanMods.Items.add(this);cmItemMap.put(getId(), this);recipeRegister();}
private void recipeRegister() {
final MaterialData air = new MaterialData(Material.AIR);recipeList.forEach(ItemRecipe -> {
if (ItemRecipe.showRecipe) recipesCount++; if (ItemRecipe.recipeType == RecipeType.SHAPED_RECIPE) {
ShapedRecipe shapedRecipe = new ShapedRecipe(ItemRecipe.result);shapedRecipe.shape("ABC", "DEF", "GHI"); for (int i = 0; i < 9; i++) {
shapedRecipe.setIngredient((char) (65 + i), ItemRecipe.recipeMatrix[i] != null ? ItemRecipe.recipeMatrix[i].getData() : air);}
Bukkit.addRecipe(shapedRecipe);}
if (ItemRecipe.recipeType == RecipeType.SHAPELESS_RECIPE) {
ShapelessRecipe shapelessRecipe = new ShapelessRecipe(ItemRecipe.result); for (int i = 0; i < 9; i++) {
if (ItemRecipe.recipeMatrix[i] != null) {
shapelessRecipe.addIngredient(ItemRecipe.recipeMatrix[i].getData());}
}
Bukkit.addRecipe(shapelessRecipe);}
if (ItemRecipe.recipeType == RecipeType.FURNACE) {
FurnaceRecipe furnaceRecipe = new FurnaceRecipe(ItemRecipe.result, ItemRecipe.recipeMatrix[0].getData());Bukkit.addRecipe(furnaceRecipe);}
});}
public String getId() {
return this.item.getItemMeta().getLocalizedName();}
public String getName() {
return this.item.getItemMeta().getDisplayName();}
public boolean isIngredient(ItemStack itemStack) {
ItemStack tempitem = itemStack.clone();tempitem.setAmount(1); for (ItemRecipe itemRecipe : recipeList) {
String recipe = Arrays.toString(itemRecipe.recipeMatrix); if (recipe.contains(tempitem.toString())) return true;}
return false;}