Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
531e64fda2 | ||
|
|
8843ee8a53 | ||
|
|
81a4370297 | ||
|
|
5ef62d174c |
11 changed files with 135 additions and 76 deletions
|
|
@ -14,6 +14,10 @@ repositories {
|
||||||
includeGroup "maven.modrinth"
|
includeGroup "maven.modrinth"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url "https://maven.enjarai.nl/releases"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
@ -27,4 +31,5 @@ dependencies {
|
||||||
modImplementation "maven.modrinth:sodium-extra:mc1.21-0.5.7" // Sodium Extra
|
modImplementation "maven.modrinth:sodium-extra:mc1.21-0.5.7" // Sodium Extra
|
||||||
modImplementation "maven.modrinth:embeddium:1.0.2+mc1.21" // Embeddium
|
modImplementation "maven.modrinth:embeddium:1.0.2+mc1.21" // Embeddium
|
||||||
modImplementation "maven.modrinth:distanthorizons:2.1.2-a-1.21" // Distant Horizons
|
modImplementation "maven.modrinth:distanthorizons:2.1.2-a-1.21" // Distant Horizons
|
||||||
|
modImplementation "nl.enjarai:shared-resources-api:1.8.3" // Shared Resources
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,27 +4,11 @@ import com.axolotlmaid.optionsprofiles.profiles.Profiles;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
public class OptionsProfilesMod {
|
public class OptionsProfilesMod {
|
||||||
public static final String MOD_ID = "optionsprofiles";
|
public static final String MOD_ID = "optionsprofiles";
|
||||||
public static final Logger LOGGER = LogManager.getLogger("Options Profiles");
|
public static final Logger LOGGER = LogManager.getLogger("Options Profiles");
|
||||||
|
|
||||||
public static void init() {
|
public static final Profiles PROFILES_INSTANCE = new Profiles();
|
||||||
Path profilesDirectory = Paths.get("options-profiles");
|
|
||||||
|
|
||||||
if (Files.notExists(profilesDirectory)) {
|
public static void init() {}
|
||||||
try {
|
|
||||||
Files.createDirectory(profilesDirectory);
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.error("An error occurred when creating the 'options-profiles' directory.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update / add configuration for existing profiles
|
|
||||||
Profiles.updateProfiles();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package com.axolotlmaid.optionsprofiles.gui;
|
package com.axolotlmaid.optionsprofiles.gui;
|
||||||
|
|
||||||
|
import com.axolotlmaid.optionsprofiles.OptionsProfilesMod;
|
||||||
|
import com.axolotlmaid.optionsprofiles.profiles.ProfileConfiguration;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.Profiles;
|
import com.axolotlmaid.optionsprofiles.profiles.Profiles;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.*;
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
|
||||||
import net.minecraft.client.gui.components.StringWidget;
|
|
||||||
import net.minecraft.client.gui.components.Tooltip;
|
|
||||||
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
||||||
import net.minecraft.client.gui.layouts.LayoutSettings;
|
import net.minecraft.client.gui.layouts.LayoutSettings;
|
||||||
import net.minecraft.client.gui.layouts.LinearLayout;
|
import net.minecraft.client.gui.layouts.LinearLayout;
|
||||||
|
|
@ -13,10 +12,13 @@ import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.CommonComponents;
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class EditProfileScreen extends Screen {
|
public class EditProfileScreen extends Screen {
|
||||||
private final ProfilesScreen profilesScreen;
|
private final ProfilesScreen profilesScreen;
|
||||||
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 24, 33);
|
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 24, 33);
|
||||||
|
|
||||||
|
private final ProfileConfiguration profileConfiguration;
|
||||||
private final Component profileName;
|
private final Component profileName;
|
||||||
private EditBox profileNameEdit;
|
private EditBox profileNameEdit;
|
||||||
|
|
||||||
|
|
@ -24,6 +26,7 @@ public class EditProfileScreen extends Screen {
|
||||||
super(Component.literal(Component.translatable("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString()));
|
super(Component.literal(Component.translatable("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString()));
|
||||||
this.profilesScreen = profilesScreen;
|
this.profilesScreen = profilesScreen;
|
||||||
this.profileName = profileName;
|
this.profileName = profileName;
|
||||||
|
this.profileConfiguration = ProfileConfiguration.get(profileName.getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
|
@ -45,11 +48,10 @@ public class EditProfileScreen extends Screen {
|
||||||
Button.builder(
|
Button.builder(
|
||||||
Component.translatable("gui.optionsprofiles.overwrite-options"),
|
Component.translatable("gui.optionsprofiles.overwrite-options"),
|
||||||
(button) -> {
|
(button) -> {
|
||||||
Profiles.writeProfile(profileName.getString(), true);
|
OptionsProfilesMod.PROFILES_INSTANCE.writeProfile(profileName.getString(), true);
|
||||||
this.onClose();
|
this.onClose();
|
||||||
})
|
})
|
||||||
.size(150, 20)
|
.size(150, 20)
|
||||||
.pos(this.width / 2 - 75, 145)
|
|
||||||
.tooltip(Tooltip.create(Component.translatable("gui.optionsprofiles.overwrite-options.tooltip")))
|
.tooltip(Tooltip.create(Component.translatable("gui.optionsprofiles.overwrite-options.tooltip")))
|
||||||
.build(),
|
.build(),
|
||||||
LayoutSettings::alignHorizontallyCenter
|
LayoutSettings::alignHorizontallyCenter
|
||||||
|
|
@ -58,24 +60,32 @@ public class EditProfileScreen extends Screen {
|
||||||
Button.builder(
|
Button.builder(
|
||||||
Component.translatable("gui.optionsprofiles.rename-profile"),
|
Component.translatable("gui.optionsprofiles.rename-profile"),
|
||||||
(button) -> {
|
(button) -> {
|
||||||
Profiles.renameProfile(profileName.getString(), this.profileNameEdit.getValue());
|
OptionsProfilesMod.PROFILES_INSTANCE.renameProfile(profileName.getString(), this.profileNameEdit.getValue());
|
||||||
this.minecraft.setScreen(new EditProfileScreen(profilesScreen, Component.literal(this.profileNameEdit.getValue())));
|
this.minecraft.setScreen(new EditProfileScreen(profilesScreen, Component.literal(this.profileNameEdit.getValue())));
|
||||||
})
|
})
|
||||||
.size(150, 20)
|
.size(150, 20)
|
||||||
.pos(this.width / 2 - 75, 166)
|
|
||||||
.build(),
|
.build(),
|
||||||
LayoutSettings::alignHorizontallyCenter
|
LayoutSettings::alignHorizontallyCenter
|
||||||
);
|
);
|
||||||
linearLayoutButtons.addChild(
|
linearLayoutButtons.addChild(
|
||||||
Button.builder(
|
Button.builder(
|
||||||
Component.translatable("gui.optionsprofiles.options-toggle").append("..."),
|
Component.translatable("gui.optionsprofiles.options-toggle").append("..."),
|
||||||
(button) -> this.minecraft.setScreen(new OptionsToggleScreen(this, profileName)))
|
(button) -> this.minecraft.setScreen(new OptionsToggleScreen(this, profileName, profileConfiguration)))
|
||||||
.size(150, 20)
|
.size(150, 20)
|
||||||
.pos(this.width / 2 - 75, 187)
|
|
||||||
.tooltip(Tooltip.create(Component.translatable("gui.optionsprofiles.options-toggle.tooltip")))
|
.tooltip(Tooltip.create(Component.translatable("gui.optionsprofiles.options-toggle.tooltip")))
|
||||||
.build(),
|
.build(),
|
||||||
LayoutSettings::alignHorizontallyCenter
|
LayoutSettings::alignHorizontallyCenter
|
||||||
);
|
);
|
||||||
|
linearLayoutButtons.addChild(
|
||||||
|
Checkbox.builder(
|
||||||
|
Component.literal("Load on startup"),
|
||||||
|
this.font
|
||||||
|
)
|
||||||
|
.selected(profileConfiguration.isLoadOnStartup())
|
||||||
|
.onValueChange((checkbox, value) -> profileConfiguration.setLoadOnStartup(value))
|
||||||
|
.build(),
|
||||||
|
(layoutSettings) -> layoutSettings.alignHorizontallyCenter().paddingTop(5)
|
||||||
|
);
|
||||||
|
|
||||||
this.layout.addToFooter(
|
this.layout.addToFooter(
|
||||||
Button.builder(
|
Button.builder(
|
||||||
|
|
@ -89,7 +99,7 @@ public class EditProfileScreen extends Screen {
|
||||||
Component.translatable("gui.optionsprofiles.delete-profile")
|
Component.translatable("gui.optionsprofiles.delete-profile")
|
||||||
.withStyle(ChatFormatting.RED),
|
.withStyle(ChatFormatting.RED),
|
||||||
(button) -> {
|
(button) -> {
|
||||||
Profiles.deleteProfile(profileName.getString());
|
OptionsProfilesMod.PROFILES_INSTANCE.deleteProfile(profileName.getString());
|
||||||
this.onClose();
|
this.onClose();
|
||||||
})
|
})
|
||||||
.width(50)
|
.width(50)
|
||||||
|
|
@ -108,5 +118,10 @@ public class EditProfileScreen extends Screen {
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
this.minecraft.setScreen(this.profilesScreen);
|
this.minecraft.setScreen(this.profilesScreen);
|
||||||
this.profilesScreen.profilesList.refreshEntries();
|
this.profilesScreen.profilesList.refreshEntries();
|
||||||
|
|
||||||
|
// Checks if the configuration still exists and wasn't deleted
|
||||||
|
if (Files.exists(Profiles.PROFILES_DIRECTORY.resolve(profileName.getString()).resolve("configuration.json"))) {
|
||||||
|
this.profileConfiguration.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,10 +14,10 @@ public class OptionsToggleScreen extends OptionsSubScreen {
|
||||||
private OptionsToggleList optionsToggleList;
|
private OptionsToggleList optionsToggleList;
|
||||||
public ProfileConfiguration profileConfiguration;
|
public ProfileConfiguration profileConfiguration;
|
||||||
|
|
||||||
protected OptionsToggleScreen(Screen lastScreen, Component profileName) {
|
protected OptionsToggleScreen(Screen lastScreen, Component profileName, ProfileConfiguration profileConfiguration) {
|
||||||
super(lastScreen, null, Component.literal(Component.translatable("gui.optionsprofiles.options-toggle").append(": ").getString() + profileName.getString()));
|
super(lastScreen, null, Component.literal(Component.translatable("gui.optionsprofiles.options-toggle").append(": ").getString() + profileName.getString()));
|
||||||
this.profileName = profileName;
|
this.profileName = profileName;
|
||||||
this.profileConfiguration = ProfileConfiguration.get(profileName.getString());
|
this.profileConfiguration = profileConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addOptions() {}
|
protected void addOptions() {}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Prof
|
||||||
this.loadButton = Button.builder(
|
this.loadButton = Button.builder(
|
||||||
Component.translatable("gui.optionsprofiles.load-profile"),
|
Component.translatable("gui.optionsprofiles.load-profile"),
|
||||||
(button) -> {
|
(button) -> {
|
||||||
Profiles.loadProfile(profileName.getString());
|
OptionsProfilesMod.PROFILES_INSTANCE.loadProfile(profileName.getString());
|
||||||
|
|
||||||
minecraft.options.load();
|
minecraft.options.load();
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Prof
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkLoaded() {
|
protected void checkLoaded() {
|
||||||
this.loadButton.active = !Profiles.isProfileLoaded(profileName.getString());
|
this.loadButton.active = !OptionsProfilesMod.PROFILES_INSTANCE.isProfileLoaded(profileName.getString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.axolotlmaid.optionsprofiles.gui;
|
package com.axolotlmaid.optionsprofiles.gui;
|
||||||
|
|
||||||
|
import com.axolotlmaid.optionsprofiles.OptionsProfilesMod;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.Profiles;
|
import com.axolotlmaid.optionsprofiles.profiles.Profiles;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.layouts.LinearLayout;
|
import net.minecraft.client.gui.layouts.LinearLayout;
|
||||||
|
|
@ -10,7 +11,7 @@ import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
public class ProfilesScreen extends OptionsSubScreen {
|
public class ProfilesScreen extends OptionsSubScreen {
|
||||||
private Screen optionsLastScreen;
|
private final Screen optionsLastScreen;
|
||||||
public ProfilesList profilesList;
|
public ProfilesList profilesList;
|
||||||
|
|
||||||
public ProfilesScreen(Screen lastScreen, Screen optionsLastScreen) {
|
public ProfilesScreen(Screen lastScreen, Screen optionsLastScreen) {
|
||||||
|
|
@ -31,7 +32,7 @@ public class ProfilesScreen extends OptionsSubScreen {
|
||||||
Button.builder(
|
Button.builder(
|
||||||
Component.translatable("gui.optionsprofiles.save-current-options"),
|
Component.translatable("gui.optionsprofiles.save-current-options"),
|
||||||
(button -> {
|
(button -> {
|
||||||
Profiles.createProfile();
|
OptionsProfilesMod.PROFILES_INSTANCE.createProfile();
|
||||||
this.profilesList.refreshEntries();
|
this.profilesList.refreshEntries();
|
||||||
}))
|
}))
|
||||||
.build()
|
.build()
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,7 @@ public class ProfileConfiguration {
|
||||||
private static Path configurationFile;
|
private static Path configurationFile;
|
||||||
private static String profileName;
|
private static String profileName;
|
||||||
|
|
||||||
public static int configurationVersion = 1; // Used to update configuration in later revisions
|
private boolean loadOnStartup = false;
|
||||||
private int version = configurationVersion; // ^ same here - this variable is used to show it in the configuration.json file
|
|
||||||
private List<String> optionsToLoad = new ArrayList<>();
|
private List<String> optionsToLoad = new ArrayList<>();
|
||||||
|
|
||||||
public ProfileConfiguration save() {
|
public ProfileConfiguration save() {
|
||||||
|
|
@ -59,12 +58,12 @@ public class ProfileConfiguration {
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVersion() {
|
public boolean isLoadOnStartup() {
|
||||||
return version;
|
return loadOnStartup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(int version) {
|
public void setLoadOnStartup(boolean loadOnStartup) {
|
||||||
this.version = version;
|
this.loadOnStartup = loadOnStartup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getOptionsToLoad() {
|
public List<String> getOptionsToLoad() {
|
||||||
|
|
|
||||||
|
|
@ -5,28 +5,46 @@ import com.axolotlmaid.optionsprofiles.profiles.loaders.DistantHorizonsLoader;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.loaders.EmbeddiumLoader;
|
import com.axolotlmaid.optionsprofiles.profiles.loaders.EmbeddiumLoader;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumExtraLoader;
|
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumExtraLoader;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumLoader;
|
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumLoader;
|
||||||
|
import nl.enjarai.shared_resources.api.GameResourceHelper;
|
||||||
|
import nl.enjarai.shared_resources.util.GameResourceConfig;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class Profiles {
|
public class Profiles {
|
||||||
public static final Path PROFILES_DIRECTORY = Paths.get("options-profiles/");
|
public static Path PROFILES_DIRECTORY = Paths.get("options-profiles/");
|
||||||
public static final Path OPTIONS_FILE = Paths.get("options.txt");
|
public static Path OPTIONS_FILE = Paths.get("options.txt");
|
||||||
public static final Path OPTIFINE_OPTIONS_FILE = Paths.get("optionsof.txt");
|
public static final Path OPTIFINE_OPTIONS_FILE = Paths.get("optionsof.txt");
|
||||||
public static final Path SODIUM_OPTIONS_FILE = Paths.get("config/sodium-options.json");
|
public static final Path SODIUM_OPTIONS_FILE = Paths.get("config/sodium-options.json");
|
||||||
public static final Path SODIUM_EXTRA_OPTIONS_FILE = Paths.get("config/sodium-extra-options.json");
|
public static final Path SODIUM_EXTRA_OPTIONS_FILE = Paths.get("config/sodium-extra-options.json");
|
||||||
public static final Path EMBEDDIUM_OPTIONS_FILE = Paths.get("config/embeddium-options.json");
|
public static final Path EMBEDDIUM_OPTIONS_FILE = Paths.get("config/embeddium-options.json");
|
||||||
public static final Path DISTANT_HORIZONS_OPTIONS_FILE = Paths.get("config/DistantHorizons.toml");
|
public static final Path DISTANT_HORIZONS_OPTIONS_FILE = Paths.get("config/DistantHorizons.toml");
|
||||||
|
|
||||||
// This function goes through every profile and updates / adds the configuration file if it doesn't exist
|
public Profiles() {
|
||||||
public static void updateProfiles() {
|
// Create profiles directory
|
||||||
|
PROFILES_DIRECTORY = Paths.get("options-profiles/");
|
||||||
|
|
||||||
|
if (Files.notExists(PROFILES_DIRECTORY)) {
|
||||||
|
try {
|
||||||
|
Files.createDirectory(PROFILES_DIRECTORY);
|
||||||
|
} catch (IOException e) {
|
||||||
|
OptionsProfilesMod.LOGGER.error("An error occurred when creating the 'options-profiles' directory.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set profiles directory if Shared Resources mod is installed
|
||||||
|
Path sharedResourcesPath = GameResourceHelper.getPathFor(SharedResourcesProfiles.SHARED_RESOURCES_PROFILES_DIRECTORY);
|
||||||
|
|
||||||
|
if (sharedResourcesPath != null) {
|
||||||
|
PROFILES_DIRECTORY = sharedResourcesPath;
|
||||||
|
OPTIONS_FILE = sharedResourcesPath.getParent().resolve("options.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Goes through every profile and adds the configuration file if it doesn't exist
|
||||||
try (Stream<Path> paths = Files.list(PROFILES_DIRECTORY)) {
|
try (Stream<Path> paths = Files.list(PROFILES_DIRECTORY)) {
|
||||||
paths.filter(Files::isDirectory)
|
paths.filter(Files::isDirectory)
|
||||||
.forEach(path -> {
|
.forEach(path -> {
|
||||||
|
|
@ -34,36 +52,47 @@ public class Profiles {
|
||||||
|
|
||||||
// This gets the configuration but also creates the configuration file if it is not there
|
// This gets the configuration but also creates the configuration file if it is not there
|
||||||
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
||||||
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
|
Path profileOptions = profile.resolve(OPTIONS_FILE.getFileName());
|
||||||
|
|
||||||
|
// Add every option value to configuration
|
||||||
|
try (Stream<String> lines = Files.lines(profileOptions)) {
|
||||||
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
|
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
|
||||||
|
|
||||||
// Checks for updates to the configuration
|
lines.forEach((line) -> {
|
||||||
if (profileConfiguration.getVersion() != ProfileConfiguration.configurationVersion) {
|
String[] option = line.split(":");
|
||||||
Path configurationFile = path.resolve("configuration.json");
|
optionsToLoad.add(option[0]);
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
Files.delete(configurationFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: Error deleting configuration file", profileName, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the configuration.json again thus updating it
|
|
||||||
profileConfiguration = ProfileConfiguration.get(profileName);
|
|
||||||
|
|
||||||
// Add player's old configuration
|
|
||||||
profileConfiguration.setOptionsToLoad(optionsToLoad);
|
|
||||||
|
|
||||||
// Save configuration
|
|
||||||
profileConfiguration.save();
|
profileConfiguration.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when adding options to the configuration file", profileName, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionsProfilesMod.LOGGER.warn("[Profile '{}']: Profile configuration updated / added", profileName);
|
OptionsProfilesMod.LOGGER.warn("[Profile '{}']: Profile configuration added", profileName);
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
OptionsProfilesMod.LOGGER.error("An error occurred when updating profiles", e);
|
OptionsProfilesMod.LOGGER.error("An error occurred when updating profiles", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loading profiles on startup
|
||||||
|
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Profiles.PROFILES_DIRECTORY)) {
|
||||||
|
for (Path profile : directoryStream) {
|
||||||
|
String profileName = profile.getFileName().toString();
|
||||||
|
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
||||||
|
|
||||||
|
if (profileConfiguration.isLoadOnStartup()) {
|
||||||
|
OptionsProfilesMod.PROFILES_INSTANCE.loadProfile(profileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
OptionsProfilesMod.LOGGER.error("An error occurred when loading startup profiles", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createProfile() {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createProfile() {
|
||||||
String profileName = "Profile 1";
|
String profileName = "Profile 1";
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
|
|
||||||
|
|
@ -87,7 +116,7 @@ public class Profiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyOptionFile(Path profile, Path options) {
|
private void copyOptionFile(Path profile, Path options) {
|
||||||
if (Files.exists(options)) {
|
if (Files.exists(options)) {
|
||||||
Path profileOptions = profile.resolve(options.getFileName());
|
Path profileOptions = profile.resolve(options.getFileName());
|
||||||
|
|
||||||
|
|
@ -100,7 +129,7 @@ public class Profiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeProfile(String profileName, boolean overwriting) {
|
public void writeProfile(String profileName, boolean overwriting) {
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
Path profileOptions = profile.resolve("options.txt");
|
Path profileOptions = profile.resolve("options.txt");
|
||||||
|
|
||||||
|
|
@ -146,13 +175,13 @@ public class Profiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isProfileLoaded(String profileName) {
|
public boolean isProfileLoaded(String profileName) {
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
|
|
||||||
List<Path> optionFiles = new ArrayList<>();
|
List<Path> optionFiles = new ArrayList<>();
|
||||||
optionFiles.add(OPTIONS_FILE);
|
optionFiles.add(OPTIONS_FILE);
|
||||||
|
|
||||||
// The next few lines check if the specified file exists. If so, it adds it to the optionFiles ArrayList.
|
// These lines check if the specified file exists. If so, it adds it to the optionFiles ArrayList.
|
||||||
Optional.of(OPTIFINE_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add);
|
Optional.of(OPTIFINE_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add);
|
||||||
Optional.of(SODIUM_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add);
|
Optional.of(SODIUM_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add);
|
||||||
Optional.of(SODIUM_EXTRA_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add);
|
Optional.of(SODIUM_EXTRA_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add);
|
||||||
|
|
@ -175,7 +204,7 @@ public class Profiles {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadOptionFile(String profileName, Path options) {
|
private void loadOptionFile(String profileName, Path options) {
|
||||||
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
||||||
|
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
|
|
@ -244,7 +273,7 @@ public class Profiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadOptionFile(String profileName, Path options, Consumer<Path> loader) {
|
private void loadOptionFile(String profileName, Path options, Consumer<Path> loader) {
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
Path profileOptions = profile.resolve(options.getFileName());
|
Path profileOptions = profile.resolve(options.getFileName());
|
||||||
|
|
||||||
|
|
@ -254,7 +283,7 @@ public class Profiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadProfile(String profileName) {
|
public void loadProfile(String profileName) {
|
||||||
loadOptionFile(profileName, OPTIONS_FILE);
|
loadOptionFile(profileName, OPTIONS_FILE);
|
||||||
loadOptionFile(profileName, OPTIFINE_OPTIONS_FILE);
|
loadOptionFile(profileName, OPTIFINE_OPTIONS_FILE);
|
||||||
loadOptionFile(profileName, SODIUM_OPTIONS_FILE, SodiumLoader::load);
|
loadOptionFile(profileName, SODIUM_OPTIONS_FILE, SodiumLoader::load);
|
||||||
|
|
@ -265,7 +294,7 @@ public class Profiles {
|
||||||
loadOptionFile(profileName, DISTANT_HORIZONS_OPTIONS_FILE, DistantHorizonsLoader::load); // Tell Distant Horizons mod to reload configuration
|
loadOptionFile(profileName, DISTANT_HORIZONS_OPTIONS_FILE, DistantHorizonsLoader::load); // Tell Distant Horizons mod to reload configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renameProfile(String profileName, String newProfileName) {
|
public void renameProfile(String profileName, String newProfileName) {
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
Path newProfile = PROFILES_DIRECTORY.resolve(newProfileName);
|
Path newProfile = PROFILES_DIRECTORY.resolve(newProfileName);
|
||||||
|
|
||||||
|
|
@ -282,7 +311,7 @@ public class Profiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteProfile(String profileName) {
|
public void deleteProfile(String profileName) {
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.axolotlmaid.optionsprofiles.profiles;
|
||||||
|
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import nl.enjarai.shared_resources.api.GameResourceRegistry;
|
||||||
|
import nl.enjarai.shared_resources.api.ResourceDirectory;
|
||||||
|
import nl.enjarai.shared_resources.api.ResourceDirectoryBuilder;
|
||||||
|
import nl.enjarai.shared_resources.api.SharedResourcesEntrypoint;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public class SharedResourcesProfiles implements SharedResourcesEntrypoint {
|
||||||
|
public static final ResourceDirectory SHARED_RESOURCES_PROFILES_DIRECTORY = new ResourceDirectoryBuilder("options-profiles")
|
||||||
|
.setDisplayName(Component.translatable("gui.optionsprofiles"))
|
||||||
|
.defaultEnabled(true)
|
||||||
|
.isExperimental()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerResources(GameResourceRegistry registry) {
|
||||||
|
registry.register(ResourceLocation.fromNamespaceAndPath("optionsprofiles", "profiles_directory"), SHARED_RESOURCES_PROFILES_DIRECTORY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"gui.optionsprofiles": "Options Profiles",
|
||||||
|
|
||||||
"gui.optionsprofiles.profiles-menu": "Profiles",
|
"gui.optionsprofiles.profiles-menu": "Profiles",
|
||||||
"gui.optionsprofiles.save-current-options": "Save Current Options",
|
"gui.optionsprofiles.save-current-options": "Save Current Options",
|
||||||
"gui.optionsprofiles.load-profile": "✔ (Load)",
|
"gui.optionsprofiles.load-profile": "✔ (Load)",
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"main": [
|
||||||
"com.axolotlmaid.optionsprofiles.fabric.OptionsProfilesModFabric"
|
"com.axolotlmaid.optionsprofiles.fabric.OptionsProfilesModFabric"
|
||||||
|
],
|
||||||
|
"shared-resources": [
|
||||||
|
"com.axolotlmaid.optionsprofiles.profiles.SharedResourcesProfiles"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue