Jump to content

[1.15.2] Tooltip Troubles!


-TheLittleGuy

Recommended Posts

A server I play on has this annoying "feature" where it changes how enchants are displayed on an item to look like the following:

uvA4udq.png

However I don't want that so i used some code to "reveal" the vanilla enchants (which are hidden with HideFlags nbt tag) and then removing the yellow text

Problem is, not all of the yellow lines are getting removed - Ideally there should be no yellow lines on the item.

9nnZ6QY.png

Here is the following code that results in the image above:

@SubscribeEvent
    public void onToolTip(final ItemTooltipEvent event) {
        List<ITextComponent> tooltip = event.getToolTip();
        ArrayList<String> list = new ArrayList<>();

        for(int i = 0; i < tooltip.size(); i++) {

            String line = tooltip.get(i).getFormattedText();

            if (line.matches(TextFormatting.YELLOW + "(Efficiency \\d+|Fortune \\d+|Unbreaking \\d+).*")) {  //other enchants will be added here

            //if(line.startsWith(TextFormatting.YELLOW + )) {
                list.add(line);
               tooltip.remove(i);
            }
            index = tooltip.size(); //used for testing
            s = list.toString(); //used for testing
        }

        CompoundNBT nbt = event.getItemStack().getOrCreateTag();
        nbt.remove("HideFlags");

    }

So what exactly is failing? Any help would be appreciated!

Link to comment
Share on other sites

So I came up with this code but I am unsure how to "tie" it to the tooltips. No crashes occur but it does not work

List<ITextComponent> tooltip = event.getToolTip();
        ArrayList<String> list = new ArrayList<>();
        String regex = TextFormatting.YELLOW + "(Efficiency \\d+|Fortune \\d+|Unbreaking \\d+).*";
        //add all lines of the tooltip
        for(int i = 0; i < tooltip.size(); i++) {
            String line = tooltip.get(i).getFormattedText();
            list.add(line);
        }

        Iterator itr = list.iterator();
        while (itr.hasNext()) {
            String next = (String) itr.next();

            if(regex.equals(next)) {
                tooltip.remove(next); //unsure if this is correct
                test = true; //test boolean
            }
        }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.