From 88b1b0077d01f66722c225155fedad24904e6540 Mon Sep 17 00:00:00 2001 From: slprime Date: Tue, 31 Dec 2024 09:47:07 +0200 Subject: [PATCH 1/2] Fixed NEI reload when changing dimension --- .../java/codechicken/nei/NEIClientConfig.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 22868f2e5..6b9dd5c25 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -703,23 +703,25 @@ public static OptionList getOptionList() { public static void loadWorld(String worldPath) { unloadWorld(); - NEIClientConfig.worldPath = worldPath; - setInternalEnabled(true); - logger.debug("Loading " + (Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote") + " World"); - final File specificDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath); - final boolean newWorld = !specificDir.exists(); + if (!worldPath.equals(NEIClientConfig.worldPath)) { + NEIClientConfig.worldPath = worldPath; - if (newWorld) { - specificDir.mkdirs(); - } + logger.debug("Loading " + (Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote") + " World"); + + final File specificDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath); + final boolean newWorld = !specificDir.exists(); - world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg"))); - bootNEI(ClientUtils.getWorld()); - CollapsibleItems.load(); - ItemPanels.bookmarkPanel.load(); - onWorldLoad(newWorld); + if (newWorld) { + specificDir.mkdirs(); + } + + world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg"))); + bootNEI(ClientUtils.getWorld()); + onWorldLoad(newWorld); + ItemPanels.bookmarkPanel.load(); + } } public static String getWorldPath() { @@ -734,7 +736,6 @@ private static void onWorldLoad(boolean newWorld) { creativeInv = new ItemStack[54]; LayoutManager.searchField.setText(getSearchExpression()); ItemPanels.itemPanel.quantity.setText(Integer.toString(getItemQuantity())); - SubsetWidget.loadHidden(); if (newWorld && Minecraft.getMinecraft().isSingleplayer()) world.config.getTag("inventory.cheatmode") .setIntValue(NEIClientUtils.mc().playerController.isInCreativeMode() ? 2 : 0); @@ -818,6 +819,8 @@ public void run() { }); RecipeCatalysts.loadCatalystInfo(); + CollapsibleItems.load(); + SubsetWidget.loadHidden(); ItemSorter.loadConfig(); // Set pluginNEIConfigLoaded here before posting the NEIConfigsLoadedEvent. This used to be the @@ -831,8 +834,6 @@ public void run() { ItemList.loadItems.restart(); } }.start(); - } else { - ItemList.loadItems.restart(); } } From 85813941bb535a1996c40f74068e80a587c6340d Mon Sep 17 00:00:00 2001 From: slprime Date: Tue, 31 Dec 2024 11:05:53 +0200 Subject: [PATCH 2/2] 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) {