Fixed inventory sorting mods generating unnecessary threads
This commit is contained in:
parent
63074715d3
commit
e093970992
2 changed files with 38 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import java.text.DecimalFormatSymbols;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -641,6 +642,33 @@ public class Util extends Queue {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static ItemStack[] sortContainerState(ItemStack[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack[] sorted = new ItemStack[array.length];
|
||||
Map<String, ItemStack> map = new HashMap<>();
|
||||
for (ItemStack itemStack : array) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
map.put(itemStack.toString(), itemStack);
|
||||
}
|
||||
|
||||
ArrayList<String> sortedKeys = new ArrayList<>(map.keySet());
|
||||
Collections.sort(sortedKeys);
|
||||
|
||||
int i = 0;
|
||||
for (String key : sortedKeys) {
|
||||
sorted[i] = map.get(key);
|
||||
i++;
|
||||
}
|
||||
|
||||
return sorted;
|
||||
}
|
||||
|
||||
/* return true if ItemStack[] contents are identical */
|
||||
public static boolean compareContainers(ItemStack[] oldContainer, ItemStack[] newContainer) {
|
||||
if (oldContainer.length != newContainer.length) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue