mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-10-25 20:32:20 +00:00
Мove bookmarks.ini (#194)
* move bookmarks.ini * add world specific bookmarks option Co-authored-by: Serghei Borovetchi <sborovetchi@estatim.com>
This commit is contained in:
1 parent
144a37cebb
commit
cab0aff563
3 files changed
+87
-16
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import codechicken.core.CommonUtils;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
@@ -21,6 +22,10 @@ import java.awt.Point;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,6 +35,7 @@ import java.util.HashMap;
|
||||
public class BookmarkPanel extends ItemPanel
|
||||
{
|
||||
|
||||
protected File bookmarkFile;
|
||||
protected boolean bookmarksIsLoaded = false;
|
||||
public int sortedStackIndex = -1;
|
||||
public int sortedNamespaceIndex = -1;
|
||||
@@ -403,6 +409,43 @@ public class BookmarkPanel extends ItemPanel
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setBookmarkFile(String worldPath)
|
||||
{
|
||||
|
||||
final File dir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
|
||||
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
bookmarkFile = new File(dir, "bookmarks.ini");
|
||||
|
||||
if (!bookmarkFile.exists()) {
|
||||
final File globalBookmarks = new File(CommonUtils.getMinecraftDir(), "saves/NEI/global/bookmarks.ini");
|
||||
final File configBookmarks = new File(NEIClientConfig.configDir, "bookmarks.ini");
|
||||
final File defaultBookmarks = configBookmarks.exists()? configBookmarks: globalBookmarks;
|
||||
|
||||
if (defaultBookmarks.exists()) {
|
||||
|
||||
try {
|
||||
bookmarkFile.createNewFile();
|
||||
|
||||
InputStream src = new FileInputStream(defaultBookmarks);
|
||||
OutputStream dst = new FileOutputStream(bookmarkFile);
|
||||
|
||||
IOUtils.copy(src, dst);
|
||||
|
||||
src.close();
|
||||
dst.close();
|
||||
|
||||
} catch(IOException e) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bookmarksIsLoaded = false;
|
||||
}
|
||||
|
||||
public void saveBookmarks()
|
||||
{
|
||||
@@ -444,12 +487,11 @@ public class BookmarkPanel extends ItemPanel
|
||||
|
||||
}
|
||||
|
||||
File file = NEIClientConfig.bookmarkFile;
|
||||
if (file != null) {
|
||||
try(FileWriter writer = new FileWriter(file)) {
|
||||
if (bookmarkFile != null) {
|
||||
try(FileWriter writer = new FileWriter(bookmarkFile)) {
|
||||
IOUtils.writeLines(strings, "\n", writer);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save bookmarks list to file {}", file, e);
|
||||
NEIClientConfig.logger.error("Filed to save bookmarks list to file {}", bookmarkFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,17 +506,16 @@ public class BookmarkPanel extends ItemPanel
|
||||
|
||||
bookmarksIsLoaded = true;
|
||||
|
||||
File file = NEIClientConfig.bookmarkFile;
|
||||
if (file == null || !file.exists()) {
|
||||
if (bookmarkFile == null || !bookmarkFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> itemStrings;
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
NEIClientConfig.logger.info("Loading bookmarks from file {}", file);
|
||||
try (FileReader reader = new FileReader(bookmarkFile)) {
|
||||
NEIClientConfig.logger.info("Loading bookmarks from file {}", bookmarkFile);
|
||||
itemStrings = IOUtils.readLines(reader);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to load bookmarks from file {}", file, e);
|
||||
NEIClientConfig.logger.error("Failed to load bookmarks from file {}", bookmarkFile, e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import java.util.regex.Pattern;
|
||||
public class NEIClientConfig {
|
||||
private static boolean configLoaded;
|
||||
private static boolean enabledOverride;
|
||||
private static String worldPath;
|
||||
|
||||
public static Logger logger = LogManager.getLogger("NotEnoughItems");
|
||||
public static File configDir = new File(CommonUtils.getMinecraftDir(), "config/NEI/");
|
||||
@@ -60,12 +61,14 @@ public class NEIClientConfig {
|
||||
new File("saves/NEI/client.dat"),
|
||||
new ConfigFile(new File(configDir, "client.cfg")));
|
||||
public static ConfigSet world;
|
||||
public static final File bookmarkFile = new File(configDir, "bookmarks.ini");
|
||||
public static final File handlerFile = new File(configDir, "handlers.csv");
|
||||
public static final File serialHandlersFile = new File(configDir, "serialhandlers.cfg");
|
||||
public static final File heightHackHandlersFile = new File(configDir, "heighthackhandlers.cfg");
|
||||
public static final File handlerOrderingFile = new File(configDir, "handlerordering.csv");
|
||||
|
||||
@Deprecated
|
||||
public static File bookmarkFile;
|
||||
|
||||
// Set of handlers that need to be run in serial
|
||||
public static HashSet<String> serialHandlers = new HashSet<>();
|
||||
|
||||
@@ -177,6 +180,15 @@ public class NEIClientConfig {
|
||||
tag.getTag("command.heal").setDefaultValue("");
|
||||
API.addOption(new OptionTextField("command.heal"));
|
||||
|
||||
tag.getTag("inventory.worldSpecificBookmarks").setComment("Global or world specific bookmarks").getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.worldSpecificBookmarks", true) {
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
super.onClick(button);
|
||||
initBookmarkFile(worldPath);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
tag.getTag("inventory.bookmarksEnabled").setComment("Enable/disable bookmarks").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.bookmarksEnabled", true));
|
||||
tag.getTag("inventory.saveCurrentRecipeInBookmarksEnabled").setComment("Save Current Recipe in Bookmarks").getBooleanValue(true);
|
||||
@@ -262,17 +274,22 @@ public class NEIClientConfig {
|
||||
return OptionList.getOptionList("nei.options");
|
||||
}
|
||||
|
||||
public static void loadWorld(String saveName) {
|
||||
public static void loadWorld(String worldPath) {
|
||||
NEIClientConfig.worldPath = worldPath;
|
||||
|
||||
setInternalEnabled(true);
|
||||
logger.debug("Loading "+(Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote")+" World");
|
||||
bootNEI(ClientUtils.getWorld());
|
||||
|
||||
File saveDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + saveName);
|
||||
boolean newWorld = !saveDir.exists();
|
||||
if (newWorld)
|
||||
saveDir.mkdirs();
|
||||
final File specificDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
|
||||
final boolean newWorld = !specificDir.exists();
|
||||
|
||||
world = new ConfigSet(new File(saveDir, "NEI.dat"), new ConfigFile(new File(saveDir, "NEI.cfg")));
|
||||
if (newWorld) {
|
||||
specificDir.mkdirs();
|
||||
}
|
||||
|
||||
initBookmarkFile(worldPath);
|
||||
world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg")));
|
||||
onWorldLoad(newWorld);
|
||||
}
|
||||
|
||||
@@ -344,6 +361,16 @@ public class NEIClientConfig {
|
||||
ItemSorter.loadConfig();
|
||||
}
|
||||
|
||||
private static void initBookmarkFile(String worldPath)
|
||||
{
|
||||
|
||||
if (!global.config.getTag("inventory.worldSpecificBookmarks").getBooleanValue()) {
|
||||
worldPath = "global";
|
||||
}
|
||||
|
||||
ItemPanels.bookmarkPanel.setBookmarkFile(worldPath);
|
||||
}
|
||||
|
||||
public static boolean isWorldSpecific(String setting) {
|
||||
if(world == null) return false;
|
||||
ConfigTag tag = world.config.getTag(setting, false);
|
||||
|
||||
@@ -108,6 +108,9 @@ nei.options.keys.world.creative=Gamemode
|
||||
nei.options.keys.world.creative.tip=Cycle Gamemode
|
||||
|
||||
nei.options.inventory=Inventory
|
||||
nei.options.inventory.worldSpecificBookmarks=World Specific Bookmarks
|
||||
nei.options.inventory.worldSpecificBookmarks.true=Yes
|
||||
nei.options.inventory.worldSpecificBookmarks.false=No
|
||||
nei.options.inventory.bookmarksEnabled=Bookmarks Panel Visibility
|
||||
nei.options.inventory.bookmarksEnabled.true=Visible
|
||||
nei.options.inventory.bookmarksEnabled.false=Hidden
|
||||
|
||||
Reference in new issue
Block a user