我正在为服务器编写CraftBukkit插件。但是我找不到如何检查配料项目是否有知识
ShapedRecipe packedice = new ShapedRecipe(new ItemStack(Material.PACKED_ICE));
packedice.shape(new String[]{"aba","bcb","aba"}).setIngredient('a', Material.PRISMARINE_SHARD).setIngredient('b', Material.GOLD_BLOCK).setIngredient('c', Material.SNOW_BALL);
Bukkit.getServer().addRecipe(packedice);
最佳答案
代替ShapedRecipe packedice = new ShapedRecipe(new ItemStack(Material.PACKED_ICE));
您需要更多代码:
ItemStack i = new ItemStack(Material.PACKED_ICE);
ItemMeta m = i.getItemMeta();
m.setDisplayName("CustomDisplayName")
List<String> l = new ArrayList<String>();
l.add("Line 1");
l.add("Line 2");
m.setLore(l);
i.setItemMeta(m);
ShapedRecipe packedice = new ShapedRecipe(i);
希望能帮助到你
//编辑:
抱歉,我首先误会了您,这将检查右上角的项目是否具有Lore
"Line1"
:@EventHandler
public void onCraft(CraftItemEvent e) {
ShapedRecipe packedice = YOURRECIPE;
if(e.getInventory().getSize() == 10 && e.getInventory().getResult().equals(packedice.getResult())) {
if(e.getRawSlot() == 0) {
ItemStack upleft = e.getInventory().getItem(1);
if(upleft != null && upleft.hasItemMeta() && upleft.getItemMeta().hasLore()) {
List<String> l = upleft.getItemMeta().getLore();
if(!l.get(0).equals("Line 1")) {
e.setCancelled(true);
}
}
}
}
}