Skip to content

Commit

Permalink
add synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
slprime committed Dec 31, 2024
1 parent 88b1b00 commit 8581394
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/codechicken/nei/recipe/StackInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,6 +22,7 @@

public class StackInfo {

private static final FluidStack NULL_FLUID = new FluidStack(FluidRegistry.WATER, 0);
public static final ArrayList<IStackStringifyHandler> stackStringifyHandlers = new ArrayList<>();
private static final HashMap<String, HashMap<String, String[]>> guidfilters = new HashMap<>();
private static final ItemStackMap<String> guidcache = new ItemStackMap<>();
Expand All @@ -30,7 +32,7 @@ public class StackInfo {

@Override
protected boolean removeEldestEntry(Map.Entry<ItemStack, FluidStack> eldest) {
return size() > 20;
return size() > 200;
}
};

Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down

0 comments on commit 8581394

Please sign in to comment.