Помогите Как делать крафт с кастомками айтемами?

  • Автор темы Автор темы Zarak
  • Дата начала Дата начала

Zarak

Новичок
Пользователь
Баллы
6
Т.е. мне нужно в ингредиент добавить итемстак, Lore у которого отличается от дефолта, и что бы крафтился мой рецепт только с этим кастомным итемстаком.
Пример:
Рецепт состоит из (результат не важен):
------
Железный слиток с дисплайнеймом "Особое железо"
Ножницы
------

И что бы так:
------
Простой железный слиток
Ножницы
------
нельзя было скрафтить.
 
Java:
public void onPrepareItemCraft(PrepareItemCraftEvent event) {
CraftingInventory craftInv = event.getInventory();ItemStack result = craftInv.getResult();CmItem cmitem = CustomItem.getItemByItemstack(result); if (cmitem != null) {
for (ItemStack ingredient : craftInv.getMatrix()) {
if (ingredient != null && !cmitem.isIngredient(ingredient)) {
craftInv.setResult(null); break;}
}
if (cmitem.category == CmCategories.vanilla) {
craftInv.setResult(new ItemStack(result.getType(), result.getAmount(), result.getDurability()));}
} else {
for (ItemStack ingredient : craftInv.getMatrix()) {
if (ingredient != null) {
CmItem cmItem = CustomItem.getItemByItemstack(ingredient); if (cmItem != null && !cmItem.vanillaCraft) {
craftInv.setResult(null); break;}
}
}
}
}

Сам CmItem:
Java:
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;}
Если ты шаришь в Java хоть чучуть то наверно поймёшь что за что отвечает
 
Назад
Верх