Mod will delete config if config version is incorrect.
This commit is contained in:
parent
26b48d32f3
commit
62a6ba7386
7 changed files with 78 additions and 14 deletions
|
@ -37,3 +37,6 @@ The Changelog for this mod. Standard SemVer
|
|||
|
||||
- Updated language file
|
||||
- New Cooked Egg Texture
|
||||
|
||||
## [0.1.3-dev]
|
||||
- Config is deleted if config version is set incorrectly
|
|
@ -12,7 +12,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||
fabric_version = 1.9.0+1.7.10
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.1.2-dev
|
||||
mod_version = 0.1.3-dev
|
||||
maven_group = xyz.limepot
|
||||
archives_base_name = EMB
|
||||
projchangelog = Changelog!
|
||||
|
|
|
@ -16,7 +16,7 @@ public class EMB implements ModInitializer {
|
|||
|
||||
//Mod ID
|
||||
public static final String MOD_ID = "emb";
|
||||
public static final String MOD_VER = "0.1.2-dev";
|
||||
public static final String MOD_VER = "0.1.3-dev";
|
||||
//Initialize Logger
|
||||
public static final Logger LOGGER = LogManager.getLogger("Even More Bountiful");
|
||||
|
||||
|
|
|
@ -3,13 +3,14 @@ package xyz.limepot.emb.config;
|
|||
import net.minecraft.util.Pair;
|
||||
import xyz.limepot.emb.EMB;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ModConfigs {
|
||||
public static SimpleConfig CONFIG;
|
||||
private static ModConfigProvider configs;
|
||||
public static boolean TUTORIAL_BUTTON_TOGGLE;
|
||||
public static boolean CONFIG_BUTTON_TOGGLE;
|
||||
public static boolean ENABLE_ACHIEVEMENTS;
|
||||
|
||||
public static int CONFIG_VERSION;
|
||||
|
||||
public static void registerConfigs() {
|
||||
|
@ -19,16 +20,23 @@ public class ModConfigs {
|
|||
CONFIG = SimpleConfig.of(EMB.MOD_ID).provider(configs).request();
|
||||
|
||||
assignConfigs();
|
||||
if(CONFIG_VERSION == 1){
|
||||
return;
|
||||
}
|
||||
else{
|
||||
CONFIG.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private static void createConfigs() {
|
||||
configs.addKeyValuePair(new Pair("config.version", 1), "Do Not Edit, this can break things");
|
||||
configs.addKeyValuePair(new Pair("tutorial.button.toggle", false), "True Or False - True being enable the feature, False being disable");
|
||||
configs.addKeyValuePair(new Pair("config.button.toggle", false), "True Or False - True being enable the feature, False being disable");
|
||||
configs.addKeyValuePair(new Pair("enable.achievements", false), "True Or False - True being enable the feature, False being disable");
|
||||
configs.addKeyValuePair(new Pair("config.version", 1), "DO NOT EDIT! If this value is anything other than default the mod will delete it.");
|
||||
configs.addKeyValuePair(new Pair("tutorial.button.toggle", false), "True Or False - True being enable the feature, False being disable.");
|
||||
configs.addKeyValuePair(new Pair("config.button.toggle", false), "True Or False - True being enable the feature, False being disable.");
|
||||
configs.addKeyValuePair(new Pair("enable.achievements", false), "True Or False - True being enable the feature, False being disable.");
|
||||
}
|
||||
|
||||
private static void assignConfigs() {
|
||||
CONFIG_VERSION = CONFIG.getOrDefault("config.version", 1);
|
||||
TUTORIAL_BUTTON_TOGGLE = CONFIG.getOrDefault("tutorial.button.toggle", false);
|
||||
CONFIG_BUTTON_TOGGLE = CONFIG.getOrDefault("config.button.toggle", false);
|
||||
ENABLE_ACHIEVEMENTS = CONFIG.getOrDefault("enable.achievements", false);
|
||||
|
|
|
@ -41,7 +41,7 @@ public class SimpleConfig {
|
|||
private static final Logger LOGGER = LogManager.getLogger("SimpleConfig");
|
||||
private final HashMap<String, String> config = new HashMap<>();
|
||||
private final ConfigRequest request;
|
||||
private boolean broken = false;
|
||||
private static boolean broken = false;
|
||||
|
||||
public interface DefaultConfig {
|
||||
String get( String namespace );
|
||||
|
@ -86,7 +86,7 @@ public class SimpleConfig {
|
|||
return new SimpleConfig( this );
|
||||
}
|
||||
|
||||
private String getConfig() {
|
||||
String getConfig() {
|
||||
return provider.get( filename ) + "\n";
|
||||
}
|
||||
|
||||
|
@ -101,8 +101,8 @@ public class SimpleConfig {
|
|||
*/
|
||||
public static ConfigRequest of( String filename ) {
|
||||
Path path = FabricLoader.getInstance().getConfigDir();
|
||||
//Changed from .properties to .conf by LimePotato
|
||||
return new ConfigRequest( path.resolve( filename + ".conf" ).toFile(), filename );
|
||||
//Changed from .properties to .cfg by LimePotato
|
||||
return new ConfigRequest( path.resolve( filename + ".cfg" ).toFile(), filename );
|
||||
}
|
||||
|
||||
private void createConfig() throws IOException {
|
||||
|
|
54
src/main/java/xyz/limepot/emb/gui/screen/EMBConfScreen.java
Normal file
54
src/main/java/xyz/limepot/emb/gui/screen/EMBConfScreen.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package xyz.limepot.emb.gui.screen;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.*;
|
||||
import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.client.option.GameOptions;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import xyz.limepot.emb.config.ModConfigs;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EMBConfScreen extends Screen implements IdentifiableBooleanConsumer {
|
||||
private final Screen parent;
|
||||
private final GameOptions options;
|
||||
protected String title = "EMB Configs";
|
||||
|
||||
public EMBConfScreen(Screen screen, GameOptions gameOptions) {
|
||||
this.parent = screen;
|
||||
this.options = gameOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
this.title = I18n.translate("options.embConfTitle");
|
||||
|
||||
if(ModConfigs.TUTORIAL_BUTTON_TOGGLE) {
|
||||
this.buttons.add(new ButtonWidget(900, this.width / 2 - 155, this.height / 6 + 72 - 6, 150, 20, I18n.translate("emb.options.toggle.tutorial.enable")));
|
||||
}
|
||||
else{
|
||||
this.buttons.add(new ButtonWidget(901, this.width / 2 - 155, this.height / 6 + 72 - 6, 150, 20, I18n.translate("emb.options.toggle.tutorial.disable")));
|
||||
}
|
||||
this.buttons.add(new ButtonWidget(200, this.width / 2 - 100, this.height / 6 + 168, I18n.translate("gui.done")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buttonClicked(ButtonWidget button) {
|
||||
if (button.active) {
|
||||
if (button.id == 900) {
|
||||
ModConfigs.TUTORIAL_BUTTON_TOGGLE = false;
|
||||
}
|
||||
if (button.id == 901) {
|
||||
ModConfigs.TUTORIAL_BUTTON_TOGGLE = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float tickDelta) {
|
||||
this.renderBackground();
|
||||
this.drawCenteredString(this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(mouseX, mouseY, tickDelta);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,8 +9,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import xyz.limepot.emb.config.ModConfigs;
|
||||
|
||||
import static xyz.limepot.emb.config.ModConfigs.TUTORIAL_BUTTON_TOGGLE;
|
||||
import xyz.limepot.emb.gui.screen.EMBConfScreen;
|
||||
|
||||
@Mixin(SettingsScreen.class)
|
||||
public class SettingScreenMixin extends Screen {
|
||||
|
@ -23,7 +22,7 @@ public class SettingScreenMixin extends Screen {
|
|||
|
||||
@Inject(at = @At("RETURN"), method = "buttonClicked")
|
||||
private void CustomButtonClicked(ButtonWidget par1, CallbackInfo ci) {
|
||||
if (par1.id == 13) this.client.setScreen(new SettingsScreen(this, this.client.options));
|
||||
if (par1.id == 13) this.client.setScreen(new EMBConfScreen(this, this.client.options));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue