Files
NotEnoughItems/src/main/java/codechicken/nei/NEIClientConfig.java
T

708 lines
27 KiB
Java
Raw Normal View History

2014-04-29 10:54:20 +10:00
package codechicken.nei;
2019-12-24 13:37:41 -08:00
import codechicken.core.CCUpdateChecker;
import codechicken.core.ClassDiscoverer;
import codechicken.core.ClientUtils;
import codechicken.core.CommonUtils;
2014-04-29 10:54:20 +10:00
import codechicken.lib.config.ConfigFile;
import codechicken.lib.config.ConfigTag;
import codechicken.lib.config.ConfigTagParent;
2019-12-24 13:37:41 -08:00
import codechicken.nei.api.API;
import codechicken.nei.api.GuiInfo;
import codechicken.nei.api.IConfigureNEI;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.api.NEIInfo;
import codechicken.nei.config.ConfigSet;
import codechicken.nei.config.GuiHighlightTips;
import codechicken.nei.config.GuiNEIOptionList;
import codechicken.nei.config.GuiOptionList;
2022-05-06 22:41:45 +03:00
import codechicken.nei.config.GuiPanelSettings;
2019-12-24 13:37:41 -08:00
import codechicken.nei.config.OptionCycled;
import codechicken.nei.config.OptionGamemodes;
import codechicken.nei.config.OptionList;
import codechicken.nei.config.OptionOpenGui;
import codechicken.nei.config.OptionTextField;
import codechicken.nei.config.OptionToggleButton;
2021-03-20 22:38:46 -07:00
import codechicken.nei.config.OptionToggleButtonBoubs;
2019-12-24 13:37:41 -08:00
import codechicken.nei.config.OptionUtilities;
2021-08-13 22:49:00 +03:00
import codechicken.nei.event.NEIConfigsLoadedEvent;
2021-03-28 00:12:17 -07:00
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.IRecipeHandler;
2022-01-31 01:01:12 +09:00
import codechicken.nei.recipe.RecipeCatalysts;
2014-04-29 10:54:20 +10:00
import codechicken.nei.recipe.RecipeInfo;
import codechicken.obfuscator.ObfuscationRun;
import com.google.common.base.Objects;
import java.io.File;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.function.Function;
import java.util.regex.Pattern;
2014-04-29 10:54:20 +10:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
2014-04-29 10:54:20 +10:00
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.storage.SaveFormatComparator;
2021-08-13 22:49:00 +03:00
import net.minecraftforge.common.MinecraftForge;
2014-04-29 10:54:20 +10:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
public class NEIClientConfig {
2014-04-29 10:54:20 +10:00
private static boolean configLoaded;
private static boolean enabledOverride;
2022-01-09 19:05:30 +02:00
private static String worldPath;
2014-04-29 10:54:20 +10:00
public static Logger logger = LogManager.getLogger("NotEnoughItems");
public static File configDir = new File(CommonUtils.getMinecraftDir(), "config/NEI/");
public static ConfigSet global =
new ConfigSet(new File("saves/NEI/client.dat"), new ConfigFile(new File(configDir, "client.cfg")));
2014-04-29 10:54:20 +10:00
public static ConfigSet world;
2021-03-28 00:12:17 -07:00
public static final File handlerFile = new File(configDir, "handlers.csv");
2022-01-31 01:01:12 +09:00
public static final File catalystFile = new File(configDir, "catalysts.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");
2022-01-09 19:05:30 +02:00
@Deprecated
public static File bookmarkFile;
// Set of handlers that need to be run in serial
public static HashSet<String> serialHandlers = new HashSet<>();
// Set of regexes matching handler ID of handlers that need the hack in GuiRecipe.startHeightHack().
// We use regex here so that we can apply the height hack to entire mods with one entry.
public static HashSet<Pattern> heightHackHandlerRegex = new HashSet<>();
// Map of handler ID to sort order.
// Handlers will be sorted in ascending order, so smaller numbers show up earlier.
// Any handler not in the map will be assigned to 0, and negative numbers are fine.
public static HashMap<String, Integer> handlerOrdering = new HashMap<>();
// Function that extracts the handler ID from a handler, with special logic for
// TemplateRecipeHandler: prefer using the overlay ID if it exists.
public static final Function<IRecipeHandler, String> HANDLER_ID_FUNCTION =
handler -> Objects.firstNonNull(handler.getOverlayIdentifier(), handler.getHandlerId());
public static int getHandlerOrder(IRecipeHandler handler) {
if (handlerOrdering.get(handler.getOverlayIdentifier()) != null) {
return handlerOrdering.get(handler.getOverlayIdentifier());
}
if (handlerOrdering.get(handler.getHandlerId()) != null) {
return handlerOrdering.get(handler.getHandlerId());
}
return 0;
}
// Comparator that compares handlers using the handlerOrdering map.
public static final Comparator<IRecipeHandler> HANDLER_COMPARATOR =
Comparator.comparingInt(NEIClientConfig::getHandlerOrder);
2014-04-29 10:54:20 +10:00
2019-12-24 13:37:41 -08:00
public static ItemStack[] creativeInv;
2014-04-29 10:54:20 +10:00
public static boolean hasSMPCounterpart;
2019-12-30 20:19:16 -08:00
public static HashSet<String> permissableActions = new HashSet<>();
public static HashSet<String> disabledActions = new HashSet<>();
public static HashSet<String> enabledActions = new HashSet<>();
2014-04-29 10:54:20 +10:00
public static ItemStackSet bannedBlocks = new ItemStackSet();
static {
if (global.config.getTag("checkUpdates").getBooleanValue(true)) CCUpdateChecker.updateCheck("NotEnoughItems");
2014-04-29 10:54:20 +10:00
linkOptionList();
setDefaults();
}
private static void setDefaults() {
ConfigTagParent tag = global.config;
tag.setComment(
"Main configuration of NEI.\nMost of these options can be changed ingame.\nDeleting any element will restore it to it's default value");
2014-04-29 10:54:20 +10:00
tag.getTag("command")
.useBraces()
.setComment(
"Change these options if you have a different mod installed on the server that handles the commands differently, Eg. Bukkit Essentials");
2014-04-29 10:54:20 +10:00
tag.setNewLineMode(1);
tag.getTag("inventory.widgetsenabled").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.widgetsenabled"));
2021-11-22 05:31:02 +02:00
2014-04-29 10:54:20 +10:00
tag.getTag("inventory.hidden").getBooleanValue(false);
tag.getTag("inventory.cheatmode").getIntValue(2);
tag.getTag("inventory.lockmode")
.setComment(
"For those who can't help themselves.\nSet this to a mode and you will be unable to change it ingame")
.getIntValue(-1);
API.addOption(new OptionCycled("inventory.cheatmode", 3) {
2014-04-29 10:54:20 +10:00
@Override
public boolean optionValid(int index) {
return getLockedMode() == -1 || getLockedMode() == index && NEIInfo.isValidMode(index);
}
});
checkCheatMode();
tag.getTag("inventory.utilities").setDefaultValue("delete, magnet");
API.addOption(new OptionUtilities("inventory.utilities"));
tag.getTag("inventory.gamemodes").setDefaultValue("creative, creative+, adventure");
API.addOption(new OptionGamemodes("inventory.gamemodes"));
ItemSorter.initConfig(tag);
2014-04-29 10:54:20 +10:00
tag.getTag("inventory.itemIDs").getIntValue(1);
API.addOption(new OptionCycled("inventory.itemIDs", 3, true));
tag.getTag("inventory.searchmode").getIntValue(1);
API.addOption(new OptionCycled("inventory.searchmode", 3, true));
2014-04-29 10:54:20 +10:00
tag.getTag("world.highlight_tips").getBooleanValue(false);
tag.getTag("world.highlight_tips.x").getIntValue(5000);
tag.getTag("world.highlight_tips.y").getIntValue(100);
API.addOption(new OptionOpenGui("world.highlight_tips", GuiHighlightTips.class));
2014-04-29 10:54:20 +10:00
2022-05-06 22:41:45 +03:00
tag.getTag("world.panels.bookmarks.left").getIntValue(0);
tag.getTag("world.panels.bookmarks.right").getIntValue(0);
tag.getTag("world.panels.bookmarks.top").getIntValue(0);
tag.getTag("world.panels.bookmarks.bottom").getIntValue(0);
tag.getTag("world.panels.items.left").getIntValue(0);
tag.getTag("world.panels.items.right").getIntValue(0);
tag.getTag("world.panels.items.top").getIntValue(0);
tag.getTag("world.panels.items.bottom").getIntValue(0);
API.addOption(new OptionOpenGui("world.panels", GuiPanelSettings.class));
2014-04-29 10:54:20 +10:00
tag.getTag("inventory.profileRecipes").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.profileRecipes", true));
tag.getTag("inventory.disableMouseScrollTransfer").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.disableMouseScrollTransfer", true));
tag.getTag("inventory.invertMouseScrollTransfer").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.invertMouseScrollTransfer", true) {
@Override
public boolean isEnabled() {
return isMouseScrollTransferEnabled();
}
});
tag.getTag("inventory.cacheItemRendering").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.cacheItemRendering", true));
2021-10-16 06:07:25 +02:00
tag.getTag("itemLoadingTimeout").getIntValue(500);
2014-04-29 10:54:20 +10:00
tag.getTag("command.creative").setDefaultValue("/gamemode {0} {1}");
API.addOption(new OptionTextField("command.creative"));
tag.getTag("command.item").setDefaultValue("/give {0} {1} {2} {3} {4}");
2014-04-29 10:54:20 +10:00
API.addOption(new OptionTextField("command.item"));
tag.getTag("command.time").setDefaultValue("/time set {0}");
API.addOption(new OptionTextField("command.time"));
tag.getTag("command.rain").setDefaultValue("/toggledownfall");
API.addOption(new OptionTextField("command.rain"));
tag.getTag("command.heal").setDefaultValue("");
API.addOption(new OptionTextField("command.heal"));
2021-11-22 05:31:02 +02:00
tag.getTag("inventory.worldSpecificBookmarks")
.setComment("Global or world specific bookmarks")
.getBooleanValue(false);
2022-01-09 19:05:30 +02:00
API.addOption(new OptionToggleButton("inventory.worldSpecificBookmarks", true) {
@Override
public boolean onClick(int button) {
super.onClick(button);
initBookmarkFile(worldPath);
return true;
}
});
2022-02-06 17:42:11 +02:00
tag.getTag("inventory.worldSpecificPresets")
.setComment("Global or world specific presets")
.getBooleanValue(false);
2022-02-06 17:42:11 +02:00
API.addOption(new OptionToggleButton("inventory.worldSpecificPresets", true) {
@Override
public boolean onClick(int button) {
super.onClick(button);
initPresetsFile(worldPath);
return true;
}
});
tag.getTag("inventory.bookmarksEnabled")
.setComment("Enable/disable bookmarks")
.getBooleanValue(true);
2021-03-20 22:38:46 -07:00
API.addOption(new OptionToggleButton("inventory.bookmarksEnabled", true));
tag.getTag("inventory.useNBTInBookmarks")
.setComment("Use NBT in Bookmarks")
.getBooleanValue(true);
2021-11-22 05:31:02 +02:00
API.addOption(new OptionToggleButton("inventory.useNBTInBookmarks", true));
tag.getTag("inventory.bookmarksAnimationEnabled")
.setComment("REI Style Animation in Bookmarks")
.getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.bookmarksAnimationEnabled", true));
tag.getTag("inventory.showRecipeMarker")
.setComment("Show Recipe Marker")
.getBooleanValue(false);
2022-05-06 22:41:45 +03:00
API.addOption(new OptionToggleButton("inventory.showRecipeMarker", true));
2021-11-22 05:31:02 +02:00
tag.getTag("inventory.showItemQuantityWidget")
.setComment("Show Item Quantity Widget")
.getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.showItemQuantityWidget", true));
tag.getTag("inventory.jei_style_tabs")
.setComment("Enable/disable JEI Style Tabs")
.getBooleanValue(true);
2021-03-20 22:38:46 -07:00
API.addOption(new OptionToggleButtonBoubs("inventory.jei_style_tabs", true));
tag.getTag("inventory.jei_style_item_presence_overlay")
.setComment("Enable/disable JEI Style item presence overlay on ?-hover")
.getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.jei_style_item_presence_overlay", true));
tag.getTag("inventory.jei_style_recipe_catalyst")
.setComment("Enable/disable JEI Style Recipe Catalysts")
.getBooleanValue(true);
2022-01-22 13:16:28 +09:00
API.addOption(new OptionToggleButton("inventory.jei_style_recipe_catalyst", true));
2021-11-22 05:31:02 +02:00
tag.getTag("inventory.creative_tab_style")
.setComment("Creative or JEI style tabs")
.getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.creative_tab_style", true));
2021-03-28 00:12:17 -07:00
tag.getTag("inventory.ignore_potion_overlap")
.setComment("Ignore overlap with potion effect HUD")
.getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.ignore_potion_overlap", true));
tag.getTag("tools.handler_load_from_config")
.setComment("ADVANCED: Load handlers from config")
.getBooleanValue(false);
2021-03-28 00:12:17 -07:00
API.addOption(new OptionToggleButton("tools.handler_load_from_config", true) {
@Override
public boolean onClick(int button) {
super.onClick(button);
GuiRecipeTab.loadHandlerInfo();
return true;
}
});
2022-01-31 01:01:12 +09:00
tag.getTag("tools.catalyst_load_from_config")
.setComment("ADVANCED: Load catalysts from config")
.getBooleanValue(false);
2022-01-31 01:01:12 +09:00
API.addOption(new OptionToggleButton("tools.catalyst_load_from_config", true) {
@Override
public boolean onClick(int button) {
super.onClick(button);
RecipeCatalysts.loadCatalystInfo();
return true;
}
});
2014-04-29 10:54:20 +10:00
setDefaultKeyBindings();
}
private static void linkOptionList() {
OptionList.setOptionList(new OptionList("nei.options") {
@Override
public ConfigSet globalConfigSet() {
return global;
}
2014-04-29 10:54:20 +10:00
@Override
public ConfigSet worldConfigSet() {
return world;
}
@Override
public OptionList configBase() {
return this;
}
@Override
public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) {
return new GuiNEIOptionList(parent, list, world);
2014-04-29 10:54:20 +10:00
}
});
}
private static void setDefaultKeyBindings() {
API.addHashBind("gui.recipe", Keyboard.KEY_R);
API.addHashBind("gui.usage", Keyboard.KEY_U);
2014-04-29 10:54:20 +10:00
API.addKeyBind("gui.back", Keyboard.KEY_BACK);
API.addHashBind("gui.enchant", Keyboard.KEY_X);
API.addHashBind("gui.potion", Keyboard.KEY_P);
2014-04-29 10:54:20 +10:00
API.addKeyBind("gui.prev", Keyboard.KEY_PRIOR);
API.addKeyBind("gui.next", Keyboard.KEY_NEXT);
2020-01-02 21:00:34 -08:00
API.addKeyBind("gui.prev_machine", Keyboard.KEY_UP);
API.addKeyBind("gui.next_machine", Keyboard.KEY_DOWN);
API.addKeyBind("gui.prev_recipe", Keyboard.KEY_LEFT);
API.addKeyBind("gui.next_recipe", Keyboard.KEY_RIGHT);
API.addHashBind("gui.hide", Keyboard.KEY_O);
API.addHashBind("gui.search", Keyboard.KEY_F);
API.addHashBind("gui.bookmark", Keyboard.KEY_A);
API.addHashBind("gui.bookmark_recipe", Keyboard.KEY_A + NEIClientUtils.SHIFT_HASH);
API.addHashBind("gui.bookmark_count", Keyboard.KEY_A + NEIClientUtils.CTRL_HASH);
API.addHashBind(
"gui.bookmark_recipe_count", Keyboard.KEY_A + NEIClientUtils.SHIFT_HASH + NEIClientUtils.CTRL_HASH);
API.addHashBind("gui.overlay", Keyboard.KEY_S);
API.addHashBind("gui.overlay_use", Keyboard.KEY_S + NEIClientUtils.SHIFT_HASH);
API.addHashBind("gui.overlay_hide", Keyboard.KEY_S + NEIClientUtils.CTRL_HASH);
API.addHashBind("gui.hide_bookmarks", Keyboard.KEY_B);
2022-09-11 01:35:48 +09:00
API.addKeyBind("gui.getprevioussearch", Keyboard.KEY_UP);
API.addKeyBind("gui.getnextsearch", Keyboard.KEY_DOWN);
2014-04-29 10:54:20 +10:00
API.addKeyBind("world.chunkoverlay", Keyboard.KEY_F9);
API.addKeyBind("world.moboverlay", Keyboard.KEY_F7);
API.addKeyBind("world.highlight_tips", Keyboard.KEY_NUMPAD0);
API.addKeyBind("world.dawn", 0);
API.addKeyBind("world.noon", 0);
API.addKeyBind("world.dusk", 0);
API.addKeyBind("world.midnight", 0);
API.addKeyBind("world.rain", 0);
API.addKeyBind("world.heal", 0);
API.addKeyBind("world.creative", 0);
}
public static OptionList getOptionList() {
return OptionList.getOptionList("nei.options");
}
2022-01-09 19:05:30 +02:00
public static void loadWorld(String worldPath) {
NEIClientConfig.worldPath = worldPath;
2014-04-29 10:54:20 +10:00
setInternalEnabled(true);
logger.debug("Loading " + (Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote") + " World");
2014-04-29 10:54:20 +10:00
bootNEI(ClientUtils.getWorld());
2022-01-09 19:05:30 +02:00
final File specificDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
final boolean newWorld = !specificDir.exists();
if (newWorld) {
specificDir.mkdirs();
}
2014-04-29 10:54:20 +10:00
2022-01-09 19:05:30 +02:00
initBookmarkFile(worldPath);
2022-02-06 17:42:11 +02:00
initPresetsFile(worldPath);
2022-01-09 19:05:30 +02:00
world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg")));
2014-04-29 10:54:20 +10:00
onWorldLoad(newWorld);
}
private static void onWorldLoad(boolean newWorld) {
world.config.setComment(
"World based configuration of NEI.\nMost of these options can be changed ingame.\nDeleting any element will restore it to it's default value");
2014-04-29 10:54:20 +10:00
setWorldDefaults();
creativeInv = new ItemStack[54];
LayoutManager.searchField.setText(getSearchExpression());
2022-05-06 22:41:45 +03:00
ItemPanels.itemPanel.quantity.setText(Integer.toString(getItemQuantity()));
2014-07-03 19:28:59 +10:00
SubsetWidget.loadHidden();
2014-04-29 10:54:20 +10:00
if (newWorld && Minecraft.getMinecraft().isSingleplayer())
world.config
.getTag("inventory.cheatmode")
.setIntValue(NEIClientUtils.mc().playerController.isInCreativeMode() ? 2 : 0);
2014-04-29 10:54:20 +10:00
NEIInfo.load(ClientUtils.getWorld());
}
private static void setWorldDefaults() {
NBTTagCompound nbt = world.nbt;
if (!nbt.hasKey("search")) nbt.setString("search", "");
if (!nbt.hasKey("quantity")) nbt.setInteger("quantity", 0);
if (!nbt.hasKey("validateenchantments")) nbt.setBoolean("validateenchantments", false);
world.saveNBT();
}
public static int getKeyBinding(String string) {
return getSetting("keys." + string).getIntValue();
}
public static void setDefaultKeyBinding(String string, int key) {
getSetting("keys." + string).getIntValue(key);
}
public static boolean isKeyHashDown(String string) {
final int hash = getKeyBinding(string);
return hash != Keyboard.CHAR_NONE && hash == NEIClientUtils.getKeyHash();
}
2014-04-29 10:54:20 +10:00
public static void bootNEI(World world) {
if (configLoaded) return;
2014-04-29 10:54:20 +10:00
ItemInfo.load(world);
GuiInfo.load();
RecipeInfo.load();
LayoutManager.load();
NEIController.load();
2022-01-31 01:01:12 +09:00
RecipeCatalysts.loadCatalystInfo();
2014-04-29 10:54:20 +10:00
configLoaded = true;
2020-07-29 08:03:43 +00:00
new Thread("NEI Plugin Loader") {
@Override
public void run() {
ClassDiscoverer classDiscoverer = new ClassDiscoverer(
test -> test.startsWith("NEI") && test.endsWith("Config.class"), IConfigureNEI.class);
2020-07-29 08:03:43 +00:00
classDiscoverer.findClasses();
for (Class<?> clazz : classDiscoverer.classes) {
try {
IConfigureNEI config = (IConfigureNEI) clazz.newInstance();
config.loadConfig();
NEIModContainer.plugins.add(config);
logger.debug("Loaded " + clazz.getName());
} catch (Exception e) {
logger.error("Failed to Load " + clazz.getName(), e);
}
}
2021-08-13 22:49:00 +03:00
MinecraftForge.EVENT_BUS.post(new NEIConfigsLoadedEvent());
2014-04-29 10:54:20 +10:00
}
2020-07-29 08:03:43 +00:00
}.start();
ItemSorter.loadConfig();
2014-04-29 10:54:20 +10:00
}
private static void initBookmarkFile(String worldPath) {
2022-01-09 19:05:30 +02:00
if (!global.config.getTag("inventory.worldSpecificBookmarks").getBooleanValue()) {
worldPath = "global";
}
ItemPanels.bookmarkPanel.setBookmarkFile(worldPath);
}
private static void initPresetsFile(String worldPath) {
2022-02-06 17:42:11 +02:00
if (!global.config.getTag("inventory.worldSpecificPresets").getBooleanValue()) {
worldPath = "global";
}
PresetsWidget.loadPresets(worldPath);
}
2014-04-29 10:54:20 +10:00
public static boolean isWorldSpecific(String setting) {
if (world == null) return false;
2014-12-14 14:32:30 +10:00
ConfigTag tag = world.config.getTag(setting, false);
return tag != null && tag.value != null;
2014-04-29 10:54:20 +10:00
}
public static ConfigTag getSetting(String s) {
return isWorldSpecific(s) ? world.config.getTag(s) : global.config.getTag(s);
}
public static boolean getBooleanSetting(String s) {
return getSetting(s).getBooleanValue();
}
public static boolean isHidden() {
return !enabledOverride || getBooleanSetting("inventory.hidden");
}
2021-03-14 12:22:27 -07:00
public static boolean isBookmarkPanelHidden() {
2021-03-20 22:38:46 -07:00
return !getBooleanSetting("inventory.bookmarksEnabled");
}
2021-11-22 05:31:02 +02:00
public static boolean useNBTInBookmarks() {
return getBooleanSetting("inventory.useNBTInBookmarks");
}
public static boolean areBookmarksAnimated() {
return getBooleanSetting("inventory.bookmarksAnimationEnabled");
}
2022-05-06 22:41:45 +03:00
public static boolean showRecipeMarker() {
return getBooleanSetting("inventory.showRecipeMarker");
}
public static boolean showItemQuantityWidget() {
return getBooleanSetting("inventory.showItemQuantityWidget");
}
2021-03-20 22:38:46 -07:00
public static boolean areJEIStyleTabsVisible() {
return getBooleanSetting("inventory.jei_style_tabs");
2021-03-14 12:22:27 -07:00
}
public static boolean isJEIStyleItemPresenceOverlayVisible() {
return getBooleanSetting("inventory.jei_style_item_presence_overlay");
}
2022-01-22 13:16:28 +09:00
public static boolean areJEIStyleRecipeCatalystsVisible() {
return getBooleanSetting("inventory.jei_style_recipe_catalyst");
}
public static boolean useCreativeTabStyle() {
return getBooleanSetting("inventory.creative_tab_style");
}
public static boolean ignorePotionOverlap() {
return getBooleanSetting("inventory.ignore_potion_overlap");
}
2014-04-29 10:54:20 +10:00
public static boolean isEnabled() {
return enabledOverride && getBooleanSetting("inventory.widgetsenabled");
}
2021-03-28 00:12:17 -07:00
public static boolean loadHandlersFromJar() {
2021-11-22 05:31:02 +02:00
return !getBooleanSetting("tools.handler_load_from_config");
2021-03-28 00:12:17 -07:00
}
2022-01-31 01:01:12 +09:00
public static boolean loadCatalystsFromJar() {
return !getBooleanSetting("tools.catalyst_load_from_config");
}
2014-04-29 10:54:20 +10:00
public static void setEnabled(boolean flag) {
getSetting("inventory.widgetsenabled").setBooleanValue(flag);
}
public static int getItemQuantity() {
return world.nbt.getInteger("quantity");
}
public static int getCheatMode() {
return getIntSetting("inventory.cheatmode");
}
private static void checkCheatMode() {
if (getLockedMode() != -1) setIntSetting("inventory.cheatmode", getLockedMode());
2014-04-29 10:54:20 +10:00
}
public static int getLockedMode() {
return getIntSetting("inventory.lockmode");
}
public static int getLayoutStyle() {
return getIntSetting("inventory.layoutstyle");
}
public static String getStringSetting(String s) {
return getSetting(s).getValue();
}
public static boolean showIDs() {
int i = getIntSetting("inventory.itemIDs");
return i == 2 || (i == 1 && isEnabled() && !isHidden());
}
2021-10-16 06:07:25 +02:00
public static int getItemLoadingTimeout() {
return getIntSetting("itemLoadingTimeout");
}
2014-04-29 10:54:20 +10:00
public static void toggleBooleanSetting(String setting) {
ConfigTag tag = getSetting(setting);
tag.setBooleanValue(!tag.getBooleanValue());
}
public static void cycleSetting(String setting, int max) {
ConfigTag tag = getSetting(setting);
tag.setIntValue((tag.getIntValue() + 1) % max);
}
public static int getIntSetting(String setting) {
return getSetting(setting).getIntValue();
}
public static void setIntSetting(String setting, int val) {
getSetting(setting).setIntValue(val);
}
public static String getSearchExpression() {
return world.nbt.getString("search");
}
public static void setSearchExpression(String expression) {
world.nbt.setString("search", expression);
world.saveNBT();
}
public static boolean isMouseScrollTransferEnabled() {
return !getBooleanSetting("inventory.disableMouseScrollTransfer");
}
public static boolean shouldInvertMouseScrollTransfer() {
return !getBooleanSetting("inventory.invertMouseScrollTransfer");
}
2021-11-22 05:31:02 +02:00
public static boolean shouldCacheItemRendering() {
return getBooleanSetting("inventory.cacheItemRendering") && OpenGlHelper.framebufferSupported;
}
2014-04-29 10:54:20 +10:00
public static boolean getMagnetMode() {
return enabledActions.contains("magnet");
}
public static boolean invCreativeMode() {
return enabledActions.contains("creative+") && canPerformAction("creative+");
}
public static boolean areDamageVariantsShown() {
return hasSMPCounterPart() || getSetting("command.item").getValue().contains("{3}");
}
public static boolean hasSMPCounterPart() {
return hasSMPCounterpart;
}
public static void setHasSMPCounterPart(boolean flag) {
hasSMPCounterpart = flag;
permissableActions.clear();
bannedBlocks.clear();
disabledActions.clear();
enabledActions.clear();
}
public static boolean canCheatItem(ItemStack stack) {
return canPerformAction("item") && !bannedBlocks.contains(stack);
}
2014-04-29 10:54:20 +10:00
public static boolean canPerformAction(String name) {
if (!isEnabled()) return false;
2014-04-29 10:54:20 +10:00
if (!modePermitsAction(name)) return false;
2014-04-29 10:54:20 +10:00
String base = NEIActions.base(name);
if (hasSMPCounterpart) return permissableActions.contains(base);
2014-04-29 10:54:20 +10:00
if (NEIActions.smpRequired(name)) return false;
2014-04-29 10:54:20 +10:00
String cmd = getStringSetting("command." + base);
2019-12-24 13:37:41 -08:00
return cmd != null && cmd.startsWith("/");
2014-04-29 10:54:20 +10:00
}
private static boolean modePermitsAction(String name) {
if (getCheatMode() == 0) return false;
if (getCheatMode() == 2) return true;
String[] actions = getStringArrSetting("inventory.utilities");
for (String action : actions) if (action.equalsIgnoreCase(name)) return true;
2014-04-29 10:54:20 +10:00
return false;
}
public static String[] getStringArrSetting(String s) {
return getStringSetting(s).replace(" ", "").split(",");
}
public static void setInternalEnabled(boolean b) {
enabledOverride = b;
}
public static void reloadSaves() {
File saveDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/local");
if (!saveDir.exists()) return;
2014-04-29 10:54:20 +10:00
List<SaveFormatComparator> saves;
try {
saves = Minecraft.getMinecraft().getSaveLoader().getSaveList();
} catch (Exception e) {
logger.error("Error loading saves", e);
2014-04-29 10:54:20 +10:00
return;
}
2019-12-30 20:19:16 -08:00
HashSet<String> saveFileNames = new HashSet<>();
for (SaveFormatComparator save : saves) saveFileNames.add(save.getFileName());
2014-04-29 10:54:20 +10:00
for (File file : saveDir.listFiles())
if (file.isDirectory() && !saveFileNames.contains(file.getName())) ObfuscationRun.deleteDir(file, true);
2014-04-29 10:54:20 +10:00
}
}