codechicken.nei.guihook.IContainerTooltipHandler Java Examples

The following examples show how to use codechicken.nei.guihook.IContainerTooltipHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NEIClientEventHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SubscribeEvent
public void guiOpenEvent(GuiOpenEvent event) {
    if (event.getGui() instanceof GuiContainer) {
        if (lastGui != event.getGui()) {
            if (event.getGui() == null) {
                instanceTooltipHandlers = null;
            } else {
                instanceTooltipHandlers = new LinkedList<>();
                if (event.getGui() instanceof IContainerTooltipHandler) {
                    instanceTooltipHandlers.add((IContainerTooltipHandler) event.getGui());
                }
                instanceTooltipHandlers.addAll(tooltipHandlers);
            }
            lastGui = event.getGui();
        }
    }
}
 
Example #2
Source File: GuiHelper.java    From NotEnoughItems with MIT License 5 votes vote down vote up
/**
 * Extra lines are often used for more information. For example enchantments, potion effects and mob spawner contents.
 *
 * @param itemstack       The item to get the name for.
 * @param gui             An instance of the currentscreen passed to tooltip handlers. If null, only gui inspecific handlers should respond
 * @param includeHandlers If true tooltip handlers will add to the item tip
 * @return A list of Strings representing the text to be displayed on each line of the tool tip.
 */
public static List<String> itemDisplayNameMultiline(ItemStack itemstack, GuiContainer gui, boolean includeHandlers) {
    List<String> namelist = null;
    try {
        namelist = itemstack.getTooltip(Minecraft.getMinecraft().player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? TooltipFlags.ADVANCED : TooltipFlags.NORMAL);
    } catch (Throwable ignored) {
    }

    if (namelist == null) {
        namelist = new ArrayList<>();
    }

    if (namelist.size() == 0) {
        namelist.add("Unnamed");
    }

    if (namelist.get(0) == null || namelist.get(0).equals("")) {
        namelist.set(0, "Unnamed");
    }

    if (includeHandlers) {
        for (IContainerTooltipHandler handler : NEIClientEventHandler.tooltipHandlers) {
            handler.handleItemDisplayName(gui, itemstack, namelist);
        }
    }

    namelist.set(0, itemstack.getRarity().rarityColor.toString() + namelist.get(0));
    for (int i = 1; i < namelist.size(); i++) {
        namelist.set(i, "\u00a77" + namelist.get(i));
    }

    return namelist;
}
 
Example #3
Source File: NEIClientEventHandler.java    From NotEnoughItems with MIT License 2 votes vote down vote up
/**
 * Register a new Tooltip render handler;
 *
 * @param handler The handler to register
 */
public static void addTooltipHandler(IContainerTooltipHandler handler) {
    tooltipHandlers.add(handler);
}