Skip to content

Commit

Permalink
feat: extend tooltip handler to allow additional namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Mar 3, 2024
1 parent 7c88b5e commit d3ed5ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {

@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event) {
TooltipHandler.registerNamespaceToListenTo(Occultism.MODID);

//Register client side event handlers
NeoForge.EVENT_BUS.register(Occultism.SELECTED_BLOCK_RENDERER);
NeoForge.EVENT_BUS.register(Occultism.THIRD_EYE_EFFECT_RENDERER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,22 @@
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent;

import java.util.ArrayList;
import java.util.List;

@Mod.EventBusSubscriber(modid = Occultism.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class TooltipHandler {

private static final List<String> namespacesToListenFor = new ArrayList<>();

/**
* Register a namespace (= mod id) of items to listen for during tooltip handling.
* Should be called in @{@link net.neoforged.fml.event.lifecycle.FMLClientSetupEvent}
*/
public static void registerNamespaceToListenTo(String namespace) {
namespacesToListenFor.add(namespace);
}

@SubscribeEvent
public static void onAddInformation(ItemTooltipEvent event) {
ItemStack stack = event.getItemStack();
Expand All @@ -61,7 +74,7 @@ public static void onAddInformation(ItemTooltipEvent event) {

var namespace = BuiltInRegistries.ITEM.getKey(stack.getItem()).getNamespace();

if(namespace.equals(Occultism.MODID)){
if (namespacesToListenFor.contains(namespace)) {
String tooltipKey = stack.getDescriptionId() + ".auto_tooltip";
boolean tooltipExists = I18n.exists(tooltipKey);
if (tooltipExists) {
Expand Down

0 comments on commit d3ed5ac

Please sign in to comment.