Search in sources :

Example 11 with Enchantment

use of org.spongepowered.api.item.enchantment.Enchantment in project modules-extra by CubeEngine.

the class RepairBlock method getEnchantmentMultiplier.

/*
     * Utilities
     */
public static double getEnchantmentMultiplier(ItemStack item, double factor, double base) {
    double enchantmentLevel = 0;
    Optional<List<Enchantment>> enchs = item.get(Keys.ITEM_ENCHANTMENTS);
    if (enchs.isPresent() && !enchs.get().isEmpty()) {
        for (Enchantment enchantment : enchs.get()) {
            enchantmentLevel += enchantment.getLevel();
        }
    }
    if (enchantmentLevel > 0) {
        double enchantmentMultiplier = factor * Math.pow(base, enchantmentLevel);
        enchantmentMultiplier = enchantmentMultiplier / 100.0 + 1.0;
        return enchantmentMultiplier;
    } else {
        return 1.0;
    }
}
Also used : List(java.util.List) Enchantment(org.spongepowered.api.item.enchantment.Enchantment)

Aggregations

Enchantment (org.spongepowered.api.item.enchantment.Enchantment)11 EnchantmentType (org.spongepowered.api.item.enchantment.EnchantmentType)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 SpongeEnchantment (org.spongepowered.common.item.enchantment.SpongeEnchantment)4 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 List (java.util.List)2 Map (java.util.Map)2 EnchantmentData (org.spongepowered.api.data.manipulator.mutable.item.EnchantmentData)2 Player (org.spongepowered.api.entity.living.player.Player)2 Maps (com.google.common.collect.Maps)1 Util (io.github.nucleuspowered.nucleus.Util)1 BoundedIntegerArgument (io.github.nucleuspowered.nucleus.argumentparsers.BoundedIntegerArgument)1 ImprovedCatalogTypeArgument (io.github.nucleuspowered.nucleus.argumentparsers.ImprovedCatalogTypeArgument)1 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)1 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 EssentialsEquivalent (io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent)1 PermissionInformation (io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation)1 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)1