Java Code Examples for org.bukkit.Material#BOOK
The following examples show how to use
org.bukkit.Material#BOOK .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoDisenchanter.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private boolean isDisenchantable(ItemStack item) { SlimefunItem sfItem = null; // stops endless checks of getByItem for empty book stacks. if (item != null && item.getType() != Material.BOOK) { sfItem = SlimefunItem.getByItem(item); } return sfItem == null || sfItem.isDisenchantable(); }
Example 2
Source File: AutoEnchanter.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
private MachineRecipe findRecipe(BlockMenu menu) { for (int slot : getInputSlots()) { ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); // Check if the item is enchantable if (!isEnchantable(target)) { return null; } ItemStack item = menu.getItemInSlot(slot); // Enchant if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) { Map<Enchantment, Integer> enchantments = new HashMap<>(); Set<ItemEnchantment> emeraldEnchantments = new HashSet<>(); int amount = 0; int specialAmount = 0; EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); for (Map.Entry<Enchantment, Integer> e : meta.getStoredEnchants().entrySet()) { if (e.getKey().canEnchantItem(target)) { amount++; enchantments.put(e.getKey(), e.getValue()); } } if (SlimefunPlugin.getThirdPartySupportService().isEmeraldEnchantsInstalled()) { for (ItemEnchantment enchantment : EmeraldEnchants.getInstance().getRegistry().getEnchantments(item)) { if (EmeraldEnchants.getInstance().getRegistry().isApplicable(target, enchantment.getEnchantment()) && EmeraldEnchants.getInstance().getRegistry().getEnchantmentLevel(target, enchantment.getEnchantment().getName()) < enchantment.getLevel()) { amount++; specialAmount++; emeraldEnchantments.add(enchantment); } } specialAmount += EmeraldEnchants.getInstance().getRegistry().getEnchantments(target).size(); } if (amount > 0 && specialAmount <= emeraldEnchantsLimit) { ItemStack enchantedItem = target.clone(); enchantedItem.setAmount(1); for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) { enchantedItem.addUnsafeEnchantment(entry.getKey(), entry.getValue()); } for (ItemEnchantment ench : emeraldEnchantments) { EmeraldEnchants.getInstance().getRegistry().applyEnchantment(enchantedItem, ench.getEnchantment(), ench.getLevel()); } return new MachineRecipe(75 * amount, new ItemStack[] { target, item }, new ItemStack[] { enchantedItem, new ItemStack(Material.BOOK) }); } return null; } } return null; }
Example 3
Source File: AutoDisenchanter.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
private MachineRecipe findRecipe(BlockMenu menu) { Map<Enchantment, Integer> enchantments = new HashMap<>(); Set<ItemEnchantment> emeraldEnchantments = new HashSet<>(); for (int slot : getInputSlots()) { ItemStack item = menu.getItemInSlot(slot); if (!isDisenchantable(item)) { return null; } AutoDisenchantEvent event = new AutoDisenchantEvent(item); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return null; } ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); // Disenchanting if (item != null && target != null && target.getType() == Material.BOOK) { int amount = 0; for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) { enchantments.put(entry.getKey(), entry.getValue()); amount++; } if (SlimefunPlugin.getThirdPartySupportService().isEmeraldEnchantsInstalled()) { for (ItemEnchantment enchantment : EmeraldEnchants.getInstance().getRegistry().getEnchantments(item)) { amount++; emeraldEnchantments.add(enchantment); } } if (amount > 0) { ItemStack disenchantedItem = item.clone(); disenchantedItem.setAmount(1); ItemStack book = new ItemStack(Material.ENCHANTED_BOOK); transferEnchantments(disenchantedItem, book, enchantments); for (ItemEnchantment ench : emeraldEnchantments) { EmeraldEnchants.getInstance().getRegistry().applyEnchantment(book, ench.getEnchantment(), ench.getLevel()); EmeraldEnchants.getInstance().getRegistry().applyEnchantment(disenchantedItem, ench.getEnchantment(), 0); } return new MachineRecipe(90 * amount, new ItemStack[] { target, item }, new ItemStack[] { disenchantedItem, book }); } } } return null; }
Example 4
Source File: BookOfSoulsEmptyCI.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
public BookOfSoulsEmptyCI() { super("bos-empty", ChatColor.GREEN + "Book of Souls" + ChatColor.RESET + " - " + ChatColor.RED + "Empty", Material.BOOK); setLore("§bThis is a empty Book of Souls.", "§bRight-click an entity to capture the soul."); }