本文整理了Java中org.bukkit.inventory.ItemStack.getEnchantmentLevel()
方法的一些代码示例,展示了ItemStack.getEnchantmentLevel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.getEnchantmentLevel()
方法的具体详情如下:
包路径:org.bukkit.inventory.ItemStack
类名称:ItemStack
方法名:getEnchantmentLevel
[英]Gets the level of the specified enchantment on this item stack
[中]获取此项目堆栈上指定的附魔级别
代码示例来源:origin: Bukkit/Bukkit
/**
* Removes the specified {@link Enchantment} if it exists on this
* ItemStack
*
* @param ench Enchantment to remove
* @return Previous level, or 0
*/
public int removeEnchantment(Enchantment ench) {
int level = getEnchantmentLevel(ench);
if (level == 0 || meta == null) {
return level;
}
meta.removeEnchant(ench);
return level;
}
代码示例来源:origin: GlowstoneMC/Glowstone
private int getEnchantmentLevel(Enchantment enchantment) {
return !InventoryUtil.isEmpty(itemStack) && itemStack.getType() == Material.FISHING_ROD
? itemStack.getEnchantmentLevel(enchantment)
: 0;
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
// TODO: Implement Silk Touch
ThreadLocalRandom random = ThreadLocalRandom.current();
int count = minCount;
if (maxCount > minCount) {
count += random.nextInt(maxCount - minCount);
}
ItemStack stack = new ItemStack(dropType, count, (short) data);
if (tool == null) {
return Collections.unmodifiableList(Arrays.asList(stack));
}
Collection<ItemStack> drops = super.getDrops(block, tool);
if (drops.size() == 0) {
return drops;
}
if (tool.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) {
stack.setAmount(count * getMultiplicator(random,
tool.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS)));
}
return Collections.unmodifiableList(Arrays.asList(stack));
}
代码示例来源:origin: GlowstoneMC/Glowstone
private int getProtectionFactor(Entity entity) {
if (!(entity instanceof LivingEntity)) {
return 0;
}
LivingEntity livingEntity = (LivingEntity) entity;
int level = 0;
if (livingEntity.getEquipment() != null) {
for (ItemStack stack : livingEntity.getEquipment().getArmorContents()) {
if (stack != null) {
int stackLevel = stack.getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS);
if (stackLevel > level) {
level = stackLevel;
}
}
}
}
return level << 1;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Inflicts damage to an item. Unbreaking enchantment is applied if present.
*
* @param player the player holding the item, or null if held by a dispenser
* @param holding the item
*
* @return the updated item stack
*/
public static ItemStack damageItem(GlowPlayer player, ItemStack holding) {
if (player != null && player.getGameMode() == GameMode.CREATIVE) {
return holding;
}
// Apply unbreaking enchantment.
// TODO: Armor has a different formula for chance to avoid damage
int durability = holding.getEnchantmentLevel(Enchantment.DURABILITY);
if (durability > 0 && ThreadLocalRandom.current().nextDouble() < 1 / (durability + 1)) {
return holding;
}
holding.setDurability((short) (holding.getDurability() + 1));
if (holding.getDurability() == holding.getType().getMaxDurability() + 1) {
if (player != null) {
EventFactory.getInstance()
.callEvent(new PlayerItemBreakEvent(player, holding));
}
return createEmptyStack();
}
return holding;
}
代码示例来源:origin: GlowstoneMC/Glowstone
&& ThreadLocalRandom.current().nextFloat() >= 0.8 ? 1 : 0)
* (1 + 0.25 * bow.getEnchantmentLevel(Enchantment.ARROW_DAMAGE)));
launchedProjectile.setVelocity(player.getEyeLocation().getDirection().multiply(
Math.max(5, chargeFraction * MAX_SPEED)));
launchedArrow
.setKnockbackStrength(bow
.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK));
代码示例来源:origin: GlowstoneMC/Glowstone
if (effectiveTool != null && effectiveTool.matches(toolType)) {
double miningMultiplier = ToolType.getMiningMultiplier(toolType);
int efficiencyLevel = tool.getEnchantmentLevel(Enchantment.DIG_SPEED);
if (efficiencyLevel > 0) {
miningMultiplier += efficiencyLevel * efficiencyLevel + 1;
代码示例来源:origin: GlowstoneMC/Glowstone
+ itemInHand.getEnchantmentLevel(Enchantment.FIRE_ASPECT) * 80);
int level = itemInHand.getEnchantmentLevel(Enchantment.DAMAGE_ALL);
if (level > 0) {
damage += 1.0F + 0.5F * (level - 1);
int level = itemInHand.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS);
if (level > 0) {
damage += level * 2.5F;
int level = itemInHand.getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD);
damage += level * 2.5F;
代码示例来源:origin: gvlfm78/BukkitOldCombatMechanics
public static double applyEntityBasedDamage(EntityType entity, ItemStack item, double startDamage){
Enchantment ench = enchants.get(entity);
if(ench == null){
return startDamage;
}
if(ench == Enchantment.DAMAGE_UNDEAD || ench == Enchantment.DAMAGE_ARTHROPODS){
return startDamage + 2.5 * item.getEnchantmentLevel(ench);
}
return startDamage;
}
代码示例来源:origin: SpigotMC/Spigot-API
/**
* Removes the specified {@link Enchantment} if it exists on this
* ItemStack
*
* @param ench Enchantment to remove
* @return Previous level, or 0
*/
public int removeEnchantment(Enchantment ench) {
int level = getEnchantmentLevel(ench);
if (level == 0 || meta == null) {
return level;
}
meta.removeEnchant(ench);
return level;
}
代码示例来源:origin: artex-development/Lukkit
@Override
public LuaValue call(LuaValue value) {
return CoerceJavaToLua.coerce(item.getEnchantmentLevel((Enchantment) value.checkuserdata(Enchantment.class)));
}
});
代码示例来源:origin: NoCheatPlus/NoCheatPlus
/**
* Test, if there is any armor with the given enchantment on.
*
* @param player
* @param enchantment
* If null, false will be returned.
* @return
*/
private static boolean hasArmor(final Player player, final Enchantment enchantment) {
if (enchantment == null) {
return false;
}
final PlayerInventory inv = player.getInventory();
final ItemStack[] contents = inv.getArmorContents();
for (int i = 0; i < contents.length; i++){
final ItemStack stack = contents[i];
if (stack != null && stack.getEnchantmentLevel(enchantment) > 0){
return true;
}
}
return false;
}
代码示例来源:origin: NoCheatPlus/NoCheatPlus
/**
* Get the knock-back "level", a player can deal based on sprinting +
* item(s) in hand. The minimum knock-back level is 1.0 (1 + 1 for sprinting
* + knock-back level), currently capped at 20. Since detecting relevance of
* items in main vs. off hand, we use the maximum of both, for now.
*
* @param player
* @return
*/
private double getKnockBackLevel(final Player player) {
double level = 1.0; // 1.0 is the minimum knock-back value.
// TODO: Get the RELEVANT item (...).
final ItemStack stack = Bridge1_9.getItemInMainHand(player);
if (!BlockProperties.isAir(stack)) {
level = (double) stack.getEnchantmentLevel(Enchantment.KNOCKBACK);
}
if (player.isSprinting()) {
// TODO: Lost sprint?
level += 1.0;
}
// Cap the level to something reasonable. TODO: Config / cap the velocity anyway.
return Math.min(20.0, level);
}
代码示例来源:origin: NoCheatPlus/NoCheatPlus
/**
* Checks if is valid tool.
*
* @param blockType
* the block type
* @param itemInHand
* the item in hand
* @return true, if is valid tool
*/
public static boolean isValidTool(final Material blockType, final ItemStack itemInHand) {
final BlockProps blockProps = getBlockProps(blockType);
final ToolProps toolProps = getToolProps(itemInHand);
final int efficiency = itemInHand == null ? 0 : itemInHand.getEnchantmentLevel(Enchantment.DIG_SPEED);
return isValidTool(blockType, blockProps, toolProps, efficiency);
}
代码示例来源:origin: NoCheatPlus/NoCheatPlus
/**
* Retrieve the maximum level for an enchantment, present in armor slots.
*
* @param player
* @param enchantment
* If null, 0 will be returned.
* @return 0 if none found, or the maximum found.
*/
private static int getMaxLevelArmor(final Player player, final Enchantment enchantment) {
if (enchantment == null) {
return 0;
}
int level = 0;
// Find the maximum level for the given enchantment.
final ItemStack[] armor = player.getInventory().getArmorContents();
for (int i = 0; i < armor.length; i++) {
final ItemStack item = armor[i];
if (!BlockProperties.isAir(item)) {
level = Math.max(item.getEnchantmentLevel(enchantment), level);
}
}
return level;
}
代码示例来源:origin: gvlfm78/BukkitOldCombatMechanics
private void onSwordAttack(EntityDamageByEntityEvent e, Player p, ItemStack weapon){
//Disable sword sweep
Location location = p.getLocation(); // ATTACKER
int level = 0;
try{ //In a try catch for servers that haven't updated
level = weapon.getEnchantmentLevel(Enchantment.SWEEPING_EDGE);
} catch(NoSuchFieldError ignored) { }
float damage = ToolDamage.getDamage(weapon.getType()) * level / (level + 1) + 1;
if(e.getDamage() == damage){
// Possibly a sword-sweep attack
if(sweepLocations.contains(location)){
debug("Cancelling sweep...", p);
e.setCancelled(true);
}
} else {
sweepLocations.add(location);
}
}
代码示例来源:origin: mcMMO-Dev/mcMMO
/**
* Modify the durability of an ItemStack.
*
* @param itemStack The ItemStack which durability should be modified
* @param durabilityModifier the amount to modify the durability by
* @param maxDamageModifier the amount to adjust the max damage by
*/
public static void handleDurabilityChange(ItemStack itemStack, int durabilityModifier, double maxDamageModifier) {
if (itemStack.hasItemMeta() && itemStack.getItemMeta().isUnbreakable()) {
return;
}
Material type = itemStack.getType();
short maxDurability = mcMMO.getRepairableManager().isRepairable(type) ? mcMMO.getRepairableManager().getRepairable(type).getMaximumDurability() : type.getMaxDurability();
durabilityModifier = (int) Math.min(durabilityModifier / (itemStack.getEnchantmentLevel(Enchantment.DURABILITY) + 1), maxDurability * maxDamageModifier);
itemStack.setDurability((short) Math.min(itemStack.getDurability() + durabilityModifier, maxDurability));
}
代码示例来源:origin: TheBusyBiscuit/Slimefun4
/**
*
* @param e BlockBreakEvent
* @since 4.2.0
*/
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
List<ItemStack> drops = new ArrayList<ItemStack>();
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
int fortune = 1;
if (item != null) {
if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
fortune = SlimefunStartup.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
if (fortune <= 0) fortune = 1;
fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + SlimefunStartup.randomize(5) : 1) * (fortune + 1);
}
if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && e.getBlock().getType().toString().endsWith("_ORE")) {
if (Talisman.checkFor(e, SlimefunItem.getByID("MINER_TALISMAN"))) {
if (drops.isEmpty()) drops = (List<ItemStack>) e.getBlock().getDrops();
for (ItemStack drop : new ArrayList<ItemStack>(drops)) {
if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
}
}
}
}
}
}
代码示例来源:origin: NoCheatPlus/NoCheatPlus
int efficiency = 0;
if (itemInHand.containsEnchantment(Enchantment.DIG_SPEED)) {
efficiency = itemInHand.getEnchantmentLevel(Enchantment.DIG_SPEED);
代码示例来源:origin: mcMMO-Dev/mcMMO
public static void removeAbilityBuff(ItemStack item) {
if (item == null || item.getType() == Material.AIR || (!ItemUtils.isPickaxe(item) && !ItemUtils.isShovel(item)) || !item.containsEnchantment(Enchantment.DIG_SPEED)) {
return;
}
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta.hasLore()) {
List<String> itemLore = itemMeta.getLore();
if (itemLore.remove("mcMMO Ability Tool")) {
int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED);
if (efficiencyLevel <= AdvancedConfig.getInstance().getEnchantBuff()) {
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
}
else {
itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel - AdvancedConfig.getInstance().getEnchantBuff(), true);
}
itemMeta.setLore(itemLore);
item.setItemMeta(itemMeta);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!