diff --git a/src/main/java/com/aetherteam/nitrogen/event/listeners/TooltipListeners.java b/src/main/java/com/aetherteam/nitrogen/event/listeners/TooltipListeners.java index 384d471..8a08004 100644 --- a/src/main/java/com/aetherteam/nitrogen/event/listeners/TooltipListeners.java +++ b/src/main/java/com/aetherteam/nitrogen/event/listeners/TooltipListeners.java @@ -3,21 +3,21 @@ import com.aetherteam.nitrogen.Nitrogen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.ForgeRegistries; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Supplier; @Mod.EventBusSubscriber(modid = Nitrogen.MODID) public class TooltipListeners { - public static Map PREDICATES = new HashMap<>(); + public static Map, TooltipPredicate> PREDICATES = new HashMap<>(); @SubscribeEvent public static void onTooltipCreationLowPriority(ItemTooltipEvent event) { @@ -28,13 +28,19 @@ public static void onTooltipCreationLowPriority(ItemTooltipEvent event) { } public static void addAbilityTooltips(Player player, ItemStack stack, List components) { + TooltipPredicate predicate = null; + for (Map.Entry, TooltipPredicate> entry : PREDICATES.entrySet()) { + if (entry.getKey().get() == stack.getItem()) { + predicate = entry.getValue(); + break; + } + } for (int i = 1; i <= 5; i++) { String string = stack.getDescriptionId() + "." + Nitrogen.MODID + ".ability.tooltip." + i; if (I18n.exists(string)) { Component component = Component.translatable(string); - ResourceLocation location = ForgeRegistries.ITEMS.getKey(stack.getItem()); - if (PREDICATES.containsKey(location)) { - component = PREDICATES.get(location).override(player, stack, components, component); + if (predicate != null) { + component = predicate.override(player, stack, components, component); } components.add(i, component); }