mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-23 21:50:02 +00:00
Merge remote-tracking branch 'origin/master' into mu
This commit is contained in:
129 files changed
+3542
-1651
No files matched your search
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -16,7 +17,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
import codechicken.nei.ClientHandler;
|
||||
import codechicken.nei.ItemStackMap;
|
||||
import codechicken.nei.ItemStackMap.StackMetaKey;
|
||||
import codechicken.nei.LRUCache;
|
||||
import codechicken.nei.api.IStackStringifyHandler;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
@@ -35,7 +36,7 @@ public class StackInfo {
|
||||
private static final FluidStack NULL_FLUID = new FluidStack(FluidRegistry.WATER, 0);
|
||||
public static final List<IStackStringifyHandler> stackStringifyHandlers = new ArrayList<>();
|
||||
private static final Map<String, HashMap<String, String[]>> guidfilters = new HashMap<>();
|
||||
private static final ItemStackMap<String> guidcache = new ItemStackMap<>();
|
||||
private static final Map<Item, Map<StackMetaKey, String>> guidcache = new ConcurrentHashMap<>();
|
||||
private static final LRUCache<ItemStackKey, FluidStack> fluidcache = new LRUCache<>(200);
|
||||
private static boolean isPausedItemDamageSound = false;
|
||||
|
||||
@@ -186,7 +187,9 @@ public class StackInfo {
|
||||
}
|
||||
|
||||
public static String getItemStackGUID(ItemStack stack) {
|
||||
String guid = guidcache.get(stack);
|
||||
final Item stackItem = stack.getItem();
|
||||
final Map<StackMetaKey, String> itemGuids = stackItem != null ? guidcache.get(stackItem) : null;
|
||||
String guid = itemGuids != null ? itemGuids.get(new StackMetaKey(stack)) : null;
|
||||
|
||||
if (guid != null) {
|
||||
return guid;
|
||||
@@ -194,7 +197,7 @@ public class StackInfo {
|
||||
|
||||
final NBTTagCompound nbTag = itemStackToNBT(stack, false);
|
||||
|
||||
if (nbTag == null) {
|
||||
if (nbTag == null || stack.getItem() == null) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
@@ -243,16 +246,15 @@ public class StackInfo {
|
||||
}
|
||||
});
|
||||
|
||||
synchronized (guidcache) {
|
||||
guidcache.put(stack, keys.toString());
|
||||
}
|
||||
guid = keys.toString();
|
||||
} else {
|
||||
synchronized (guidcache) {
|
||||
guidcache.put(stack, NBTHelper.toString(nbTag));
|
||||
}
|
||||
guid = NBTHelper.toString(nbTag);
|
||||
}
|
||||
|
||||
return guidcache.get(stack);
|
||||
guidcache.computeIfAbsent(stack.getItem(), item -> new ConcurrentHashMap<>())
|
||||
.put(new StackMetaKey(stack.copy()), guid);
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
public static void loadGuidFilters() {
|
||||
@@ -273,20 +275,30 @@ public class StackInfo {
|
||||
public static ItemStack getItemStackWithMinimumDamage(ItemStack[] stacks) {
|
||||
ItemStack result = stacks[0];
|
||||
|
||||
if (stacks.length > 1) {
|
||||
for (ItemStack stack : stacks) {
|
||||
// to optimize compare recipes from permutation, an item with a minimum strId and damage is taken so as
|
||||
// not to check everything permutation items
|
||||
if (stack.getItem() != null && !ItemInfo.isHidden(stack)
|
||||
&& (stack.getItemDamage() < result.getItemDamage()
|
||||
|| stack.getItemDamage() == result.getItemDamage()
|
||||
&& Item.itemRegistry.getNameForObject(stack.getItem())
|
||||
.compareTo(Item.itemRegistry.getNameForObject(result.getItem())) < 0)) {
|
||||
result = stack;
|
||||
}
|
||||
for (int i = 1; i < stacks.length; i++) {
|
||||
final ItemStack stack = stacks[i];
|
||||
if (stack.getItem() != null && isLess(stack, result) && !ItemInfo.isHidden(stack)) {
|
||||
result = stack;
|
||||
}
|
||||
}
|
||||
|
||||
return result.copy();
|
||||
}
|
||||
|
||||
private static boolean isLess(ItemStack stack, ItemStack other) {
|
||||
if (stack.getItemDamage() != other.getItemDamage()) {
|
||||
return stack.getItemDamage() < other.getItemDamage();
|
||||
}
|
||||
|
||||
final String name = getItemName(stack);
|
||||
if (name == null) return false;
|
||||
|
||||
final String otherName = getItemName(other);
|
||||
return otherName == null || name.compareTo(otherName) < 0;
|
||||
}
|
||||
|
||||
private static String getItemName(ItemStack stack) {
|
||||
final Item item = stack.getItem();
|
||||
return item == null ? null : Item.itemRegistry.getNameForObject(item);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user