use of net.minecraft.inventory.EquipmentSlotType in project Bookshelf by Darkhax-Minecraft.
the class EnchantmentTicking method handleTickingEnchantments.
/**
* Calculates the total enchantment level and handles ticking the ticking enchantments.
*
* @param event LivingUpdateEvent passed in by Forge.
*/
private static void handleTickingEnchantments(LivingUpdateEvent event) {
// Iterate all the constructed ticking enchantments
for (final EnchantmentTicking tickingEnch : tickingEnchantments) {
// Add up the level of all items with this effect.
int totalLevel = 0;
// Check all equipment to count up their levels.
for (final EquipmentSlotType validSlot : tickingEnch.validSlots) {
// Get the item and add to the total level
final ItemStack stack = event.getEntityLiving().getItemBySlot(validSlot);
final int level = EnchantmentHelper.getItemEnchantmentLevel(tickingEnch, stack);
if (level > 0) {
totalLevel += level;
tickingEnch.onItemTick(event.getEntityLiving(), level, stack, validSlot);
}
}
// Tick the enchantment with the user and their total level.
tickingEnch.onUserTick(event.getEntityLiving(), totalLevel);
}
}
Aggregations