-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability tooltip display system
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ build | |
# other | ||
eclipse | ||
run | ||
runs | ||
__pycache__ | ||
logs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/aetherteam/nitrogen/event/listeners/TooltipListeners.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.aetherteam.nitrogen.event.listeners; | ||
|
||
import com.aetherteam.nitrogen.Nitrogen; | ||
import net.minecraft.client.resources.language.I18n; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.Mod; | ||
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Mod.EventBusSubscriber(modid = Nitrogen.MODID) | ||
public class TooltipListeners { | ||
public static Map<ResourceLocation, TooltipPredicate> PREDICATES = new HashMap<>(); | ||
|
||
@SubscribeEvent | ||
public static void onTooltipCreationLowPriority(ItemTooltipEvent event) { | ||
Player player = event.getEntity(); | ||
ItemStack itemStack = event.getItemStack(); | ||
List<Component> itemTooltips = event.getToolTip(); | ||
addAbilityTooltips(player, itemStack, itemTooltips); | ||
} | ||
|
||
public static void addAbilityTooltips(Player player, ItemStack stack, List<Component> components) { | ||
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 = BuiltInRegistries.ITEM.getKey(stack.getItem()); | ||
if (PREDICATES.containsKey(location)) { | ||
component = PREDICATES.get(location).override(player, stack, components, component); | ||
} | ||
components.add(i, component); | ||
} | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
public interface TooltipPredicate { | ||
Component override(Player player, ItemStack stack, List<Component> components, Component component); | ||
} | ||
} |