Posted April 11, 20205 yr A server I play on has this annoying "feature" where it changes how enchants are displayed on an item to look like the following: 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. 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!
April 11, 20205 yr Author 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 } }
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.