mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-10-25 20:22:23 +00:00
ignore format codes when sorting by name (#1656)
This commit is contained in:
1 file changed
+12
-2
@@ -11,20 +11,25 @@
|
||||
package appeng.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.util.font.FontRendering;
|
||||
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public class ItemSorters {
|
||||
|
||||
private static final Pattern FORMATTING_PATTERN = Pattern.compile("(?s)" + '\u00a7' + ".");
|
||||
|
||||
private static SortDir direction = SortDir.ASCENDING;
|
||||
|
||||
public static final Comparator<IAEStack<?>> CONFIG_BASED_SORT_BY_NAME = Comparator
|
||||
.comparing(IAEStack::getDisplayName, (a, b) -> a.compareToIgnoreCase(b) * direction.sortHint);
|
||||
.comparing(ItemSorters::getSortName, (a, b) -> a.compareToIgnoreCase(b) * direction.sortHint);
|
||||
|
||||
public static final Comparator<IAEStack<?>> CONFIG_BASED_SORT_BY_MOD = Comparator
|
||||
.comparing((IAEStack<?> stack) -> stack.getModId(), (a, b) -> a.compareToIgnoreCase(b) * direction.sortHint)
|
||||
.thenComparing(IAEStack::getDisplayName);
|
||||
.thenComparing(ItemSorters::getSortName);
|
||||
|
||||
public static final Comparator<IAEStack<?>> CONFIG_BASED_SORT_BY_SIZE = Comparator
|
||||
.comparing(IAEStack::getStackSize, (a, b) -> Long.compare(b, a) * direction.sortHint);
|
||||
@@ -42,6 +47,11 @@ public class ItemSorters {
|
||||
}
|
||||
};
|
||||
|
||||
/** Display name without format codes, so &-styled or colored names sort by their visible text. */
|
||||
private static String getSortName(final IAEStack<?> stack) {
|
||||
return FORMATTING_PATTERN.matcher(FontRendering.preprocessText(stack.getDisplayName())).replaceAll("");
|
||||
}
|
||||
|
||||
public static int compareInt(final int a, final int b) {
|
||||
// for backwards compat for ext mods...
|
||||
return Integer.compare(a, b);
|
||||
|
||||
Reference in new issue
Block a user