Skip to content

Instantly share code, notes, and snippets.

@Harleyoc1
Created March 18, 2021 21:10
Show Gist options
  • Save Harleyoc1/ef9d0b2b5ec37837d4bbbfb7bc428f26 to your computer and use it in GitHub Desktop.
Save Harleyoc1/ef9d0b2b5ec37837d4bbbfb7bc428f26 to your computer and use it in GitHub Desktop.
Simple tooltip event for displaying Forge item tags
package com.blah;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.List;
/**
* Tool tip event for viewing forge tags set to items.
*
* @author Harley O'Connor
*/
public final class TooltipEvent {
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public void onTooltip(final ItemTooltipEvent event) {
List<ITextComponent> toolTip = event.getToolTip();
for (ResourceLocation tag : event.getItemStack().getItem().getTags())
toolTip.add(new StringTextComponent("§8" + tag.toString()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment