From 85813941bb535a1996c40f74068e80a587c6340d Mon Sep 17 00:00:00 2001 From: slprime Date: Tue, 31 Dec 2024 11:05:53 +0200 Subject: [PATCH] add synchronized --- src/main/java/codechicken/nei/recipe/StackInfo.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/StackInfo.java b/src/main/java/codechicken/nei/recipe/StackInfo.java index 26587ab8a..9856010e7 100644 --- a/src/main/java/codechicken/nei/recipe/StackInfo.java +++ b/src/main/java/codechicken/nei/recipe/StackInfo.java @@ -10,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; @@ -21,6 +22,7 @@ public class StackInfo { + private static final FluidStack NULL_FLUID = new FluidStack(FluidRegistry.WATER, 0); public static final ArrayList stackStringifyHandlers = new ArrayList<>(); private static final HashMap> guidfilters = new HashMap<>(); private static final ItemStackMap guidcache = new ItemStackMap<>(); @@ -30,7 +32,7 @@ public class StackInfo { @Override protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > 20; + return size() > 200; } }; @@ -92,7 +94,7 @@ public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolea return true; } - public static FluidStack getFluid(ItemStack stack) { + public static synchronized FluidStack getFluid(ItemStack stack) { FluidStack fluid = fluidcache.get(stack); if (fluid == null && !fluidcache.containsKey(stack)) { @@ -101,10 +103,10 @@ public static FluidStack getFluid(ItemStack stack) { fluid = stackStringifyHandlers.get(i).getFluid(stack); } - fluidcache.put(stack, fluid); + fluidcache.put(stack, fluid == null ? NULL_FLUID : fluid); } - return fluid; + return fluid == NULL_FLUID ? null : fluid; } public static boolean isFluidContainer(ItemStack stack) {