-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae26603
commit 5ec9db2
Showing
7 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/de/teamlapen/werewolves/util/AlphanumericComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package de.teamlapen.werewolves.util; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.Comparator; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class AlphanumericComparator implements Comparator<ResourceLocation> { | ||
|
||
private final Pattern p = Pattern.compile("(\\D*)(\\d*)"); | ||
|
||
@Override | ||
public int compare(ResourceLocation s, ResourceLocation t1) { | ||
String first = s.toString(); | ||
String second = t1.toString(); | ||
Matcher m1 = p.matcher(first); | ||
Matcher m2 = p.matcher(second); | ||
|
||
// The loop is required because the string can contain multiple numeric parts, | ||
// e.g., beast2part10 | ||
while (m1.find() && m2.find()) { | ||
// Non-numeric part (could be empty) | ||
int nonNumericCompare = m1.group(1).compareTo(m2.group(1)); | ||
if (nonNumericCompare != 0) { | ||
return nonNumericCompare; | ||
} | ||
|
||
// Numeric part (could be empty) | ||
if (!m1.group(2).isEmpty() && !m2.group(2).isEmpty()) { | ||
int numericCompare = Integer.compare(Integer.parseInt(m1.group(2)), Integer.parseInt(m2.group(2))); | ||
if (numericCompare != 0) { | ||
return numericCompare; | ||
} | ||
} | ||
} | ||
|
||
// Handle if one string is a prefix of the other. | ||
// E.g., beast2 and beast2part10 | ||
if (m1.hitEnd() && m2.hitEnd()) { | ||
return 0; | ||
} else { | ||
return m1.hitEnd() ? -1 : 1; | ||
} | ||
|
||
} | ||
} |
Binary file added
BIN
+8.74 KB
src/main/resources/assets/werewolves/textures/entity/werewolf/beast/beast_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.86 KB
src/main/resources/assets/werewolves/textures/entity/werewolf/beast/beast_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.75 KB
...urces/assets/werewolves/textures/entity/werewolf/survivalist/survivalist_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.86 KB
...ources/assets/werewolves/textures/entity/werewolf/survivalist/survivalist_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.