Skip to content

Commit 6374c16

Browse files
slprimeslprime
andauthored
Fixed NEI reload when changing dimension (#583)
Co-authored-by: slprime <history-21@yandex.ru>
1 parent 8dd36f1 commit 6374c16

File tree

3 files changed

+62
-24
lines changed

3 files changed

+62
-24
lines changed

src/main/java/codechicken/nei/NEIClientConfig.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -703,23 +703,25 @@ public static OptionList getOptionList() {
703703

704704
public static void loadWorld(String worldPath) {
705705
unloadWorld();
706-
NEIClientConfig.worldPath = worldPath;
707-
708706
setInternalEnabled(true);
709-
logger.debug("Loading " + (Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote") + " World");
710707

711-
final File specificDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
712-
final boolean newWorld = !specificDir.exists();
708+
if (!worldPath.equals(NEIClientConfig.worldPath)) {
709+
NEIClientConfig.worldPath = worldPath;
713710

714-
if (newWorld) {
715-
specificDir.mkdirs();
716-
}
711+
logger.debug("Loading " + (Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote") + " World");
712+
713+
final File specificDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
714+
final boolean newWorld = !specificDir.exists();
717715

718-
world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg")));
719-
bootNEI(ClientUtils.getWorld());
720-
CollapsibleItems.load();
721-
ItemPanels.bookmarkPanel.load();
722-
onWorldLoad(newWorld);
716+
if (newWorld) {
717+
specificDir.mkdirs();
718+
}
719+
720+
world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg")));
721+
bootNEI(ClientUtils.getWorld());
722+
onWorldLoad(newWorld);
723+
ItemPanels.bookmarkPanel.load();
724+
}
723725
}
724726

725727
public static String getWorldPath() {
@@ -734,7 +736,6 @@ private static void onWorldLoad(boolean newWorld) {
734736
creativeInv = new ItemStack[54];
735737
LayoutManager.searchField.setText(getSearchExpression());
736738
ItemPanels.itemPanel.quantity.setText(Integer.toString(getItemQuantity()));
737-
SubsetWidget.loadHidden();
738739

739740
if (newWorld && Minecraft.getMinecraft().isSingleplayer()) world.config.getTag("inventory.cheatmode")
740741
.setIntValue(NEIClientUtils.mc().playerController.isInCreativeMode() ? 2 : 0);
@@ -818,6 +819,8 @@ public void run() {
818819
});
819820

820821
RecipeCatalysts.loadCatalystInfo();
822+
CollapsibleItems.load();
823+
SubsetWidget.loadHidden();
821824
ItemSorter.loadConfig();
822825

823826
// Set pluginNEIConfigLoaded here before posting the NEIConfigsLoadedEvent. This used to be the
@@ -831,8 +834,6 @@ public void run() {
831834
ItemList.loadItems.restart();
832835
}
833836
}.start();
834-
} else {
835-
ItemList.loadItems.restart();
836837
}
837838
}
838839

src/main/java/codechicken/nei/recipe/StackInfo.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.nbt.NBTTagCompound;
1111
import net.minecraft.nbt.NBTTagList;
1212
import net.minecraftforge.fluids.FluidContainerRegistry;
13+
import net.minecraftforge.fluids.FluidRegistry;
1314
import net.minecraftforge.fluids.FluidStack;
1415
import net.minecraftforge.fluids.IFluidContainerItem;
1516

@@ -18,19 +19,21 @@
1819
import codechicken.nei.api.IStackStringifyHandler;
1920
import codechicken.nei.recipe.stackinfo.DefaultStackStringifyHandler;
2021
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
22+
import codechicken.nei.util.ItemStackKey;
2123

2224
public class StackInfo {
2325

26+
private static final FluidStack NULL_FLUID = new FluidStack(FluidRegistry.WATER, 0);
2427
public static final ArrayList<IStackStringifyHandler> stackStringifyHandlers = new ArrayList<>();
2528
private static final HashMap<String, HashMap<String, String[]>> guidfilters = new HashMap<>();
2629
private static final ItemStackMap<String> guidcache = new ItemStackMap<>();
27-
private static final LinkedHashMap<ItemStack, FluidStack> fluidcache = new LinkedHashMap<>() {
30+
private static final LinkedHashMap<ItemStackKey, FluidStack> fluidcache = new LinkedHashMap<>() {
2831

2932
private static final long serialVersionUID = 1042213947848622164L;
3033

3134
@Override
32-
protected boolean removeEldestEntry(Map.Entry<ItemStack, FluidStack> eldest) {
33-
return size() > 20;
35+
protected boolean removeEldestEntry(Map.Entry<ItemStackKey, FluidStack> eldest) {
36+
return size() > 200;
3437
}
3538
};
3639

@@ -92,19 +95,20 @@ public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolea
9295
return true;
9396
}
9497

95-
public static FluidStack getFluid(ItemStack stack) {
96-
FluidStack fluid = fluidcache.get(stack);
98+
public static synchronized FluidStack getFluid(ItemStack stack) {
99+
ItemStackKey key = new ItemStackKey(stack);
100+
FluidStack fluid = fluidcache.get(key);
97101

98-
if (fluid == null && !fluidcache.containsKey(stack)) {
102+
if (fluid == null) {
99103

100104
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && fluid == null; i--) {
101105
fluid = stackStringifyHandlers.get(i).getFluid(stack);
102106
}
103107

104-
fluidcache.put(stack, fluid);
108+
fluidcache.put(key, fluid == null ? NULL_FLUID : fluid);
105109
}
106110

107-
return fluid;
111+
return fluid == NULL_FLUID ? null : fluid;
108112
}
109113

110114
public static boolean isFluidContainer(ItemStack stack) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package codechicken.nei.util;
2+
3+
import net.minecraft.item.Item;
4+
import net.minecraft.item.ItemStack;
5+
6+
public class ItemStackKey {
7+
8+
public final ItemStack stack;
9+
private int hashCode = 1;
10+
11+
public ItemStackKey(ItemStack stack) {
12+
this.stack = stack;
13+
14+
if (this.stack != null) {
15+
this.hashCode = 31 * this.hashCode + stack.stackSize;
16+
this.hashCode = 31 * this.hashCode + Item.getIdFromItem(stack.getItem());
17+
this.hashCode = 31 * this.hashCode + stack.getItemDamage();
18+
this.hashCode = 31 * this.hashCode + (!stack.hasTagCompound() ? 0 : stack.getTagCompound().hashCode());
19+
}
20+
}
21+
22+
@Override
23+
public int hashCode() {
24+
return this.hashCode;
25+
}
26+
27+
@Override
28+
public boolean equals(Object o) {
29+
if (o == this) return true;
30+
if (!(o instanceof ItemStackKey)) return false;
31+
return ItemStack.areItemStacksEqual(this.stack, ((ItemStackKey) o).stack);
32+
}
33+
}

0 commit comments

Comments
 (0)