想在合成配方中检测配方物品的属性是否达到要求,如果否则不显示合成物,附代码(目前无法检测属性,能合成) private void xx() {
private void xx() {
MaterialData i1 = new MaterialData(Material.xx)
String n1 = "检测的lore";
ItemStack a = i1.toItemStack();
List<String> list = a.getItemMeta().getLore();
for (String k : list) {
if (k.equals(n1)) {
                                        
ItemStack is = new ItemStack(Material.xx);
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "xx"), is);
recipe.shape(new String[] { "111", "111", "111" });
recipe.setIngredient('1', i1);
getServer().addRecipe(recipe);
                                        
}
                                
}
}
}
 private void xx() {
private void xx() {
MaterialData i1 = new MaterialData(Material.xx)
String n1 = "检测的lore";
ItemStack a = i1.toItemStack();
List<String> list = a.getItemMeta().getLore();
for (String k : list) {
if (k.equals(n1)) {
                
ItemStack is = new ItemStack(Material.xx);
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "xx"), is);
recipe.shape(new String[] { "111", "111", "111" });
recipe.setIngredient('1', i1);
getServer().addRecipe(recipe);
                
}
           
}
}
}
MaterialData i1 = new MaterialData(Material.xx)
String n1 = "检测的lore";
ItemStack a = i1.toItemStack();
List<String> list = a.getItemMeta().getLore();
for (String k : list) {
if (k.equals(n1)) {
ItemStack is = new ItemStack(Material.xx);
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "xx"), is);
recipe.shape(new String[] { "111", "111", "111" });
recipe.setIngredient('1', i1);
getServer().addRecipe(recipe);
}
}
}
}
2021.12 数据,可能有更多内容
想在合成配方中检测配方物品的属性是否达到要求,如果否则不显示合成物,附代码(目前无法检测属性,能合成) private void xx() {
private void xx() {MaterialData i1 = new MaterialData(Material.xx)
String n1 = "检测的lore";
ItemStack a = i1.toItemStack();
List<String> list = a.getItemMeta().getLore();
for (String k : list) {
if (k.equals(n1)) {
ItemStack is = new ItemStack(Material.xx);
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "xx"), is);
recipe.shape(new String[] { "111", "111", "111" });
recipe.setIngredient('1', i1);
getServer().addRecipe(recipe);
}
}
}
}
Recipe只认Material
你需要addRecipe的同时,配合PrepareItemCraftEvent使用
PrepareItemCraftEvent e
ItemStack[] items=e.getInventory().getMatrix(); //获取9宫格内的物品
boolean hasRecipe=false;
for(ItemStack item:items)
{
if(你的判断代码,如果不成立)
hasRecipe=false;
if(!hasRecipe)
break;
}
if(!hasRecipe)
e.getInventory().setResult(null); //设置合成结果为空
你需要addRecipe的同时,配合PrepareItemCraftEvent使用
PrepareItemCraftEvent e
ItemStack[] items=e.getInventory().getMatrix(); //获取9宫格内的物品
boolean hasRecipe=false;
for(ItemStack item:items)
{
if(你的判断代码,如果不成立)
hasRecipe=false;
if(!hasRecipe)
break;
}
if(!hasRecipe)
e.getInventory().setResult(null); //设置合成结果为空
注册配方的时候时候是支持识别lore和nbt等各种自定义属性的
recipe.setIngredient(key, RecipeChoice.ExactChoice(itemStack))
recipe.setIngredient(key, RecipeChoice.ExactChoice(itemStack))