Jump to content

[1.7.10]Config not saving


The_Fireplace

Recommended Posts

So my config option FIRSTRUN is supposed to be set to false the first time running the game with the mod installed. However, when I open up the config gui, it still shows as true. If, while in the config gui, I set it to false, and I restart the game, it is true again. The output in the console shows up like it is supposed to. Here is my code:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
    public static ModCompatBase instance;
public static Configuration config;

@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
syncConfig();
//Config checking
	if(ModCompatConfigValues.FIRSTTIME == true){
		System.out.println("[ModCompat]Doing one-time scan...");
		ModCompatConfigValues.FIRSTTIME = false;
                        //I have tried putting syncConfig() here, same result as without it
	}
}

public static void syncConfig(){
ModCompatConfigValues.FIRSTTIME = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT).getBoolean();
if(config.hasChanged()){
        config.save();
}
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

When you change FIRSTTIME, you do not mark the config as changed.

Oh, and here is a bit of information you didn't know:

[code]ModCompatConfigValues.FIRSTTIME = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT).getBoolean()

This above does not change anything in the Configuration. This only gets the value of the property from the Configuration. It cannot be used to set it to another value.

 

Instead use:

[code]
public static Property FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT, "Set this to false to repeat first time setup");
if (!FIRSTTIME_PROPERTY.getBoolean()) {
   FIRSTTIME_PROPERTY.set(true);
   // do your other code for first time
}

That sets the property and marks the configuration as changed

Link to comment
Share on other sites

When you change FIRSTTIME, you do not mark the config as changed.

Oh, and here is a bit of information you didn't know:

[code]ModCompatConfigValues.FIRSTTIME = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT).getBoolean()

This above does not change anything in the Configuration. This only gets the value of the property from the Configuration. It cannot be used to set it to another value.

 

Instead use:

[code]
public static Property FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT, "Set this to false to repeat first time setup");
if (!FIRSTTIME_PROPERTY.getBoolean()) {
   FIRSTTIME_PROPERTY.set(true);
   // do your other code for first time
}

That sets the property and marks the configuration as changed

Ok, I've re-coded it as you said, now what do I do in syncConfig() to make this work?(It now seems to do the same thing as before) Here is the new code:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;
public static void syncConfig(){
        config.load();
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
if(config.hasChanged()){
        config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
syncConfig();
//Config checking
	if(FIRSTTIME_PROPERTY.getBoolean() == true){
		System.out.println("[ModCompat]Doing one-time scan...");
		FIRSTTIME_PROPERTY.set(false);
		syncConfig();
	}
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

You are not loading your config.

Put a line with config.load() right after config = new Configuration( ....

Link to comment
Share on other sites

I suspect your syncConfig is reloading the configuration before it is first saved... thereby erasing your firsttime update.

Please repost your main class as it is now.  It is unnecessary to config.load() in syncConfig as the configuration should already be loaded and updated, it only needs to be read into variables and saved. In fact, you FIRSTTIME property check & set should be part of syncConfig anyways.

Link to comment
Share on other sites

Ok, so currently, it now switches firstrun to false, like it is supposed to, but it goes back to being true when I quit Minecraft and start it again. Here is the code:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;
public static void syncConfig(){
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
if(config.hasChanged()){
        config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
syncConfig();
//Config checking
	if(FIRSTTIME_PROPERTY.getBoolean() == true){
		System.out.println("[ModCompat]Doing one-time scan...");
		FIRSTTIME_PROPERTY.set(false);
		syncConfig();
	}
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

You're missing what I'm telling you (important parts of it, anyways.)

 

Try this:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

 

mkay?

Link to comment
Share on other sites

You're missing what I'm telling you (important parts of it, anyways.)

 

Try this:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
        
}
}

 

 

mkay?

Ok, tried that, and it now sets to false as it is supposed to, and upon reloading the game, it remains false. I have run in to another problem, however. When I set it to true again in the Config GUI, it doesn't run the code again. I set up a System.out.println("[ModCompat] Code Activated"); in the onConfigChanged code, as shown below, and it doesn't activate after setting the config in the Config GUI.

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
System.out.println("[ModCompat] Code Activated");
     if(eventArgs.modID.equals("modcompat")){
        syncConfig();
        }
}
}

 

EDIT: Initial problem is fixed, creating a new thread for the new problem

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have done this now but have got the error:   'food(net.minecraft.world.food.FoodProperties)' in 'net.minecraft.world.item.Item.Properties' cannot be applied to                '(net.minecraftforge.registries.RegistryObject<net.minecraft.world.item.Item>)' public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register( "lemon_juice", () -> new Item( new HoneyBottleItem.Properties().stacksTo(1).food( (new FoodProperties.Builder()) .nutrition(3) .saturationMod(0.25F) .effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 1500), 0.01f ) .build() ) )); The code above is from the ModFoods class, the one below from the ModItems class. public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register("lemon_juice", () -> new Item(new Item.Properties().food(ModFoods.LEMON_JUICE)));   I shall keep going between them to try and figure out the cause. I am sorry if this is too much for you to help with, though I thank you greatly for your patience and all the effort you have put in to help me.
    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
    • Hi, I'm trying to use datagen to create json files in my own mod. This is my ModRecipeProvider class. public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { public ModRecipeProvider(PackOutput pOutput) { super(pOutput); } @Override protected void buildRecipes(Consumer<FinishedRecipe> pWriter) { ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', ModItems.COMPRESSED_DIAMOND.get()) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get(),9) .requires(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .unlockedBy(getHasName(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()), has(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get())) .save(pWriter); ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', Blocks.DIAMOND_BLOCK) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); } } When I try to run the runData client, it shows an error:  Caused by: java.lang.IllegalStateException: Duplicate recipe compressed:compressed_diamond I know that it's caused by the fact that there are two recipes for the ModItems.COMPRESSED_DIAMOND. But I need both of these recipes, because I need a way to craft ModItems.COMPRESSED_DIAMOND_BLOCK and restore 9 diamond blocks from ModItems.COMPRESSED_DIAMOND. Is there a way to solve this?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.