Search in sources :

Example 1 with BaseMaterial

use of org.cubeengine.module.itemrepair.material.BaseMaterial in project modules-extra by CubeEngine.

the class RepairBlock method calculatePrice.

private double calculatePrice(Iterable<ItemStack> items, double enchantmentFactor, double enchantmentBase, float percentage) {
    double price = 0.0;
    ItemType type;
    RepairItem item;
    double currentPrice;
    for (ItemStack itemStack : items) {
        type = itemStack.getType();
        item = itemProvider.of(type);
        currentPrice = 0;
        for (Entry<BaseMaterial, Integer> entry : item.getBaseMaterials().entrySet()) {
            currentPrice += entry.getKey().getPrice() * entry.getValue();
        }
        Integer dura = itemStack.getValue(Keys.ITEM_DURABILITY).get().get();
        Integer maxDura = itemStack.getProperty(UseLimitProperty.class).get().getValue();
        currentPrice *= (double) (maxDura - Math.min(dura, maxDura)) / maxDura;
        currentPrice *= getEnchantmentMultiplier(itemStack, enchantmentFactor, enchantmentBase);
        price += currentPrice;
    }
    price *= percentage / 100;
    return price;
}
Also used : ItemType(org.spongepowered.api.item.ItemType) BaseMaterial(org.cubeengine.module.itemrepair.material.BaseMaterial) RepairItem(org.cubeengine.module.itemrepair.material.RepairItem) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

BaseMaterial (org.cubeengine.module.itemrepair.material.BaseMaterial)1 RepairItem (org.cubeengine.module.itemrepair.material.RepairItem)1 ItemType (org.spongepowered.api.item.ItemType)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1