Fixed NEI reload when changing dimension (#583)

Co-authored-by: slprime <history-21@yandex.ru>
This commit is contained in:
slprimeandslprime authored and GitHub committed 2024-12-31 19:33:21 +01:00
1 parent 8dd36f1c4a
commit 6374c162ba
3 files changed
+62 -24

No files matched your search

@@ -703,23 +703,25 @@ public class NEIClientConfig {
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();
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();
}
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);
}
public static String getWorldPath() {
@@ -734,7 +736,6 @@ public class NEIClientConfig {
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 class NEIClientConfig {
});
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 class NEIClientConfig {
ItemList.loadItems.restart();
}
}.start();
} else {
ItemList.loadItems.restart();
}
}
@@ -10,6 +10,7 @@ import net.minecraft.nbt.NBTBase;
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;
@@ -18,19 +19,21 @@ import codechicken.nei.ItemStackMap;
import codechicken.nei.api.IStackStringifyHandler;
import codechicken.nei.recipe.stackinfo.DefaultStackStringifyHandler;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
import codechicken.nei.util.ItemStackKey;
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<>();
private static final LinkedHashMap<ItemStack, FluidStack> fluidcache = new LinkedHashMap<>() {
private static final LinkedHashMap<ItemStackKey, FluidStack> fluidcache = new LinkedHashMap<>() {
private static final long serialVersionUID = 1042213947848622164L;
@Override
protected boolean removeEldestEntry(Map.Entry<ItemStack, FluidStack> eldest) {
return size() > 20;
protected boolean removeEldestEntry(Map.Entry<ItemStackKey, FluidStack> eldest) {
return size() > 200;
}
};
@@ -92,19 +95,20 @@ public class StackInfo {
return true;
}
public static FluidStack getFluid(ItemStack stack) {
FluidStack fluid = fluidcache.get(stack);
public static synchronized FluidStack getFluid(ItemStack stack) {
ItemStackKey key = new ItemStackKey(stack);
FluidStack fluid = fluidcache.get(key);
if (fluid == null && !fluidcache.containsKey(stack)) {
if (fluid == null) {
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && fluid == null; i--) {
fluid = stackStringifyHandlers.get(i).getFluid(stack);
}
fluidcache.put(stack, fluid);
fluidcache.put(key, fluid == null ? NULL_FLUID : fluid);
}
return fluid;
return fluid == NULL_FLUID ? null : fluid;
}
public static boolean isFluidContainer(ItemStack stack) {
@@ -0,0 +1,33 @@
package codechicken.nei.util;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ItemStackKey {
public final ItemStack stack;
private int hashCode = 1;
public ItemStackKey(ItemStack stack) {
this.stack = stack;
if (this.stack != null) {
this.hashCode = 31 * this.hashCode + stack.stackSize;
this.hashCode = 31 * this.hashCode + Item.getIdFromItem(stack.getItem());
this.hashCode = 31 * this.hashCode + stack.getItemDamage();
this.hashCode = 31 * this.hashCode + (!stack.hasTagCompound() ? 0 : stack.getTagCompound().hashCode());
}
}
@Override
public int hashCode() {
return this.hashCode;
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof ItemStackKey)) return false;
return ItemStack.areItemStacksEqual(this.stack, ((ItemStackKey) o).stack);
}
}