Java Code Examples for cn.nukkit.item.Item#getEnchantments()
The following examples show how to use
cn.nukkit.item.Item#getEnchantments() .
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: EntityHumanType.java From Jupiter with GNU General Public License v3.0 | 5 votes |
protected double calculateEnchantmentReduction(Item item, EntityDamageEvent source) { if (!item.hasEnchantments()) { return 0; } double reduction = 0; for (Enchantment ench : item.getEnchantments()) { reduction += ench.getDamageProtection(source); } return reduction; }
Example 2
Source File: EntityHumanType.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected double calculateEnchantmentProtectionFactor(Item item, EntityDamageEvent source) { if (!item.hasEnchantments()) { return 0; } double epf = 0; for (Enchantment ench : item.getEnchantments()) { epf += ench.getProtectionFactor(source); } return epf; }
Example 3
Source File: EntityHumanType.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected double calculateEnchantmentReduction(Item item, EntityDamageEvent source) { if (!item.hasEnchantments()) { return 0; } double reduction = 0; for (Enchantment ench : item.getEnchantments()) { reduction += ench.getDamageProtection(source); } return reduction; }
Example 4
Source File: AnvilInventory.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean onRename(Player player, Item resultItem) { Item local = getItem(TARGET); Item second = getItem(SACRIFICE); if (!resultItem.equals(local, true, false) || resultItem.getCount() != local.getCount()) { //Item does not match target item. Everything must match except the tags. return false; } if (local.equals(resultItem)) { //just item transaction return true; } if (local.getId() != 0 && second.getId() == 0) { //only rename local.setCustomName(resultItem.getCustomName()); setItem(RESULT, local); player.getInventory().addItem(local); clearAll(); player.getInventory().sendContents(player); sendContents(player); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_RANDOM_ANVIL_USE); return true; } else if (local.getId() != 0 && second.getId() != 0) { //enchants combining if (!local.equals(second, true, false)) { return false; } if (local.getId() != 0 && second.getId() != 0) { Item result = local.clone(); int enchants = 0; ArrayList<Enchantment> enchantments = new ArrayList<>(Arrays.asList(second.getEnchantments())); ArrayList<Enchantment> baseEnchants = new ArrayList<>(); for (Enchantment ench : local.getEnchantments()) { if (ench.isMajor()) { baseEnchants.add(ench); } } for (Enchantment enchantment : enchantments) { if (enchantment.getLevel() < 0 || enchantment.getId() < 0) { continue; } if (enchantment.isMajor()) { boolean same = false; boolean another = false; for (Enchantment baseEnchant : baseEnchants) { if (baseEnchant.getId() == enchantment.getId()) same = true; else { another = true; } } if (!same && another) { continue; } } Enchantment localEnchantment = local.getEnchantment(enchantment.getId()); if (localEnchantment != null) { int level = Math.max(localEnchantment.getLevel(), enchantment.getLevel()); if (localEnchantment.getLevel() == enchantment.getLevel()) level++; enchantment.setLevel(level); result.addEnchantment(enchantment); continue; } result.addEnchantment(enchantment); enchants++; } result.setCustomName(resultItem.getCustomName()); player.getInventory().addItem(result); player.getInventory().sendContents(player); clearAll(); sendContents(player); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_RANDOM_ANVIL_USE); return true; } } return false; }
Example 5
Source File: AnvilInventory.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean onRename(Player player, Item resultItem) { Item local = getItem(TARGET); Item second = getItem(SACRIFICE); if (!resultItem.equals(local, true, false) || resultItem.getCount() != local.getCount()) { //Item does not match target item. Everything must match except the tags. return false; } if (local.equals(resultItem)) { //just item transaction return true; } if (local.getId() != 0 && second.getId() == 0) { //only rename local.setCustomName(resultItem.getCustomName()); setItem(RESULT, local); player.getInventory().addItem(local); clearAll(); player.getInventory().sendContents(player); sendContents(player); player.getLevel().addSound(player, Sound.RANDOM_ANVIL_USE); return true; } else if (local.getId() != 0 && second.getId() != 0) { //enchants combining if (!local.equals(second, true, false)) { return false; } if (local.getId() != 0 && second.getId() != 0) { Item result = local.clone(); int enchants = 0; ArrayList<Enchantment> enchantments = new ArrayList<>(Arrays.asList(second.getEnchantments())); ArrayList<Enchantment> baseEnchants = new ArrayList<>(); for (Enchantment ench : local.getEnchantments()) { if (ench.isMajor()) { baseEnchants.add(ench); } } for (Enchantment enchantment : enchantments) { if (enchantment.getLevel() < 0 || enchantment.getId() < 0) { continue; } if (enchantment.isMajor()) { boolean same = false; boolean another = false; for (Enchantment baseEnchant : baseEnchants) { if (baseEnchant.getId() == enchantment.getId()) same = true; else { another = true; } } if (!same && another) { continue; } } Enchantment localEnchantment = local.getEnchantment(enchantment.getId()); if (localEnchantment != null) { int level = Math.max(localEnchantment.getLevel(), enchantment.getLevel()); if (localEnchantment.getLevel() == enchantment.getLevel()) level++; enchantment.setLevel(level); result.addEnchantment(enchantment); continue; } result.addEnchantment(enchantment); enchants++; } result.setCustomName(resultItem.getCustomName()); player.getInventory().addItem(result); player.getInventory().sendContents(player); clearAll(); sendContents(player); player.getLevel().addSound(player, Sound.RANDOM_ANVIL_USE); return true; } } return false; }