use of org.cubeengine.module.itemrepair.material.RepairItem 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;
}
Aggregations