Java Code Examples for net.minecraft.item.ItemStack#getTooltip()

The following examples show how to use net.minecraft.item.ItemStack#getTooltip() . 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: ShowArmor.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
private List<String> getItemToolTip(ItemStack itemStack) {
    if (itemStack == null) {
        return new ArrayList<>();
    }
    @SuppressWarnings("unchecked")
    List<String> list = itemStack.getTooltip(Wrapper.INSTANCE.player(), true);

    for (int i = 0; i < list.size(); ++i) {
        if (i == 0) {
            list.set(i, itemStack.getRarity().rarityColor + list.get(i));
        } else {
            list.set(i, "\u00a77" + list.get(i));
        }
    }

    return list;
}
 
Example 2
Source File: Utils.java    From SkyblockAddons with MIT License 5 votes vote down vote up
public boolean isMaterialForRecipe(ItemStack item) {
    final List<String> tooltip = item.getTooltip(null, false);
    for (String s : tooltip) {
        if ("§5§o§eRight-click to view recipes!".equals(s)) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: Widget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
protected static List<String> getItemToolTip(ItemStack itemStack) {
    Minecraft mc = Minecraft.getMinecraft();
    ITooltipFlag flag = mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
    List<String> tooltip = itemStack.getTooltip(mc.player, flag);
    for (int i = 0; i < tooltip.size(); ++i) {
        if (i == 0) {
            tooltip.set(i, itemStack.getItem().getForgeRarity(itemStack).getColor() + tooltip.get(i));
        } else {
            tooltip.set(i, TextFormatting.GRAY + tooltip.get(i));
        }
    }
    return tooltip;
}
 
Example 4
Source File: GuiSurgery.java    From Cyberware with MIT License 5 votes vote down vote up
protected void renderToolTip(ItemStack stack, int x, int y, int extras)
{
	List<String> list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);

	for (int i = 0; i < list.size(); ++i)
	{
		if (i == 0)
		{
			list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
		}
		else
		{
			list.set(i, TextFormatting.GRAY + (String)list.get(i));
		}
	}
	
	if (extras == 1)
	{
		list.add(1, I18n.format("cyberware.gui.remove"));
	}
	else if (extras >= 2)
	{
		list.add(1, I18n.format("cyberware.gui.click"));
		
		if (extras == 3)
		{
			list.set(0, list.get(0) + " " + I18n.format("cyberware.gui.added"));
		}
		else if (extras == 4)
		{
			list.set(0, list.get(0) + " " + I18n.format("cyberware.gui.removed"));
		}
	}

	FontRenderer font = stack.getItem().getFontRenderer(stack);
	this.drawHoveringText(list, x, y, (font == null ? fontRendererObj : font));
}
 
Example 5
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 6
Source File: GuiContainerManager.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().thePlayer, includeHandlers && Minecraft.getMinecraft().gameSettings.advancedItemTooltips);
    } catch (Throwable ignored) {}

    if (namelist == null)
        namelist = new ArrayList<String>();

    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 : tooltipHandlers) {
            namelist = 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 7
Source File: InventoryUtils.java    From SkyblockAddons with MIT License 4 votes vote down vote up
/**
 * Checks if the player is wearing any Revenant or Tarantula armor.
 * If the armor is detected, the armor's levelling progress is retrieved to be displayed on the HUD.
 *
 * @param p the player to check
 */
public void checkIfWearingSlayerArmor(EntityPlayerSP p) {
    if (main.getConfigValues().isEnabled(Feature.SLAYER_INDICATOR)) {
        for (int i = 3; i >= 0; i--) {
            ItemStack item = p.inventory.armorInventory[i];
            String itemID = item != null ? ItemUtils.getSkyBlockItemID(item) : null;

            if (itemID != null && (itemID.startsWith("REVENANT") || itemID.startsWith("TARANTULA"))) {
                String percent = null;
                String defence = null;
                List<String> tooltip = item.getTooltip(null, false);
                for (String line : tooltip) {
                    Matcher matcher = REVENANT_UPGRADE_PATTERN.matcher(line);
                    if (matcher.matches()) { // Example: line§5§o§7Next Upgrade: §a+240❈ §8(§a14,418§7/§c15,000§8)
                        try {
                            float percentage = Float.parseFloat(matcher.group(2).replace(",", "")) / Integer.parseInt(matcher.group(3).replace(",", "")) * 100;
                            BigDecimal bigDecimal = new BigDecimal(percentage).setScale(0, BigDecimal.ROUND_HALF_UP);
                            percent = bigDecimal.toString();
                            defence = ChatFormatting.GREEN + matcher.group(1);
                            break;
                        } catch (NumberFormatException ignored) {
                        }
                    }
                }
                if (percent != null && defence != null) {
                    SlayerArmorProgress currentProgress = slayerArmorProgresses[i];

                    if (currentProgress == null || item != currentProgress.getItemStack()) {
                        // The item has changed or didn't exist. Create new object.
                        slayerArmorProgresses[i] = new SlayerArmorProgress(item, percent, defence);
                    } else {
                        // The item has remained the same. Just update the stats.
                        currentProgress.setPercent(percent);
                        currentProgress.setDefence(defence);
                    }
                }
            } else {
                slayerArmorProgresses[i] = null;
            }
        }
    }
}
 
Example 8
Source File: GuiChestHook.java    From SkyblockAddons with MIT License 4 votes vote down vote up
public static void handleMouseClick(Slot slotIn, Container slots, IInventory lowerChestInventory, ReturnValue<?> returnValue) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    if (main.getUtils().getEnchantmentMatches().size() > 0) {
        if (slotIn != null && !slotIn.inventory.equals(Minecraft.getMinecraft().thePlayer.inventory) && slotIn.getHasStack()) {
            if (slotIn.getSlotIndex() == 13 && EnumUtils.InventoryType.getCurrentInventoryType() == EnumUtils.InventoryType.ENCHANTMENT_TABLE) {
                ItemStack[] enchantBottles = {slots.getSlot(29).getStack(), slots.getSlot(31).getStack(), slots.getSlot(33).getStack()};
                for (ItemStack bottle : enchantBottles) {
                    if (bottle != null && bottle.hasDisplayName()) {
                        if (bottle.getDisplayName().startsWith(ChatFormatting.GREEN + "Enchant Item")) {
                            Minecraft mc = Minecraft.getMinecraft();
                            List<String> toolip = bottle.getTooltip(mc.thePlayer, false);
                            if (toolip.size() > 2) {
                                String[] lines = toolip.get(2).split(Pattern.quote("* "));

                                if (lines.length > 1) {
                                    String enchantLine = lines[1];
                                    if (main.getUtils().enchantReforgeMatches(enchantLine)) {
                                        main.getUtils().playLoudSound("random.orb", 0.1);
                                        returnValue.cancel();
                                    }
                                }
                            }
                        } else if (bottle.getDisplayName().startsWith(ChatFormatting.RED + "Enchant Item")) {
                            // Stop player from removing item before the enchants have even loaded.
                            returnValue.cancel();
                        }
                    }
                }
            } else if (slotIn.getSlotIndex() == 22 && EnumUtils.InventoryType.getCurrentInventoryType() == EnumUtils.InventoryType.REFORGE_ANVIL) {
                Slot itemSlot = slots.getSlot(13);
                if (itemSlot != null && itemSlot.getHasStack()) {
                    ItemStack item = itemSlot.getStack();
                    if (item.hasDisplayName()) {
                        String reforge = main.getUtils().getReforgeFromItem(item);
                        if (reforge != null) {
                            if (main.getUtils().enchantReforgeMatches(reforge)) {
                                main.getUtils().playLoudSound("random.orb", 0.1);
                                returnValue.cancel();
                            }
                        }
                    }
                }
            }
        }
    }

    if (main.getConfigValues().isEnabled(Feature.STOP_DROPPING_SELLING_RARE_ITEMS) && !main.getUtils().isInDungeon() &&
            lowerChestInventory.hasCustomName() && NPCUtils.isFullMerchant(lowerChestInventory.getDisplayName().getUnformattedText())
            && slotIn != null && slotIn.inventory instanceof InventoryPlayer) {
        if (!main.getUtils().getItemDropChecker().canDropItem(slotIn)) {
            returnValue.cancel();
        }
    }
}