Jump to content

[1.8]Make booleans stay after quitting Minecraft


Trusak

Recommended Posts

Hey, while making my mod I ran into a stupid problem: Each time I restart Minecraft, my booleans get reset to default. I would like to make them stay like they are even after restarting Minecraft, but I cant find a way on how to do it. I already tried to make it via a config but I dont want to change the config manually (via a text editor) but with a button. I hope you can help me and tell me if you need anything! (Some code or my config)

Link to comment
Share on other sites

  • Replies 90
  • Created
  • Last Reply

Top Posters In This Topic

Whenever I push a button, I want my boolean to change AND STAY AFTER QUITTING MINECRAFT. Example:

private static boolean instantRejoin = false;
public static boolean instaRejoinEnabled(){
    return (instantRejoin = !instantRejoin);
}
public static boolean instaRejoinInfo(){
    return (instantRejoin);
}

Link to comment
Share on other sites

Does it also work if I am using it in the preInit?

@EventHandler
public static void preInit(FMLPreInitializationEvent event)
{
	//NoToxic.init();
	//NoToxic.register();
	Configuration config1= new Configuration(event.getSuggestedConfigurationFile());
	config1.load();

	FastExamples.NotResetVariables.PMs = config1.getBoolean("PMs", "Booleans", false, "Disable to disable by default");
	FastExamples.NotResetVariables.PMs = config1.getBoolean("InstantRejoin", "Booleans", false, "Disable to disable by default");
	FastExamples.NotResetVariables.PMs = config1.getBoolean("ShowPartyChat", "Booleans", false, "Disable to disable by default");
	FastExamples.NotResetVariables.PMs = config1.getBoolean("ShowGuildChat", "Booleans", false, "Disable to disable by default");
	config1.save();
}

And if yes, how can I change it inside an event?

Link to comment
Share on other sites

Yes, I have seen that, but I can't find what to do when I want a button inside of a GUI to change it:

if(button == button23) {
            boolean State1 = FastExamples.NotResetVariables.AnnoyingMessagesEnabled();
            Minecraft.getMinecraft().displayGuiScreen(new GUI());
//Here I want that Boolean1, which is "false" by default to change to "true" when I click the button
config1.load();

	Boolean1 = config1.getBoolean("PMs", "Booleans", false, "Disable to disable by default");
	config1.save();
            

Link to comment
Share on other sites

You can change the values in the config file by first getting them as Property instances, check the methods in Configuration.

I am kinda new to modding and dont't know how to do that :(. (Yet) Anyway, from the methods I figured out that I should probably be using

public Property get(String category, String key, boolean defaultValue)
    {
        return get(category, key, defaultValue, (String) null);
    }

Link to comment
Share on other sites

You should probably start invoking those methods, yes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Property prop = config.get("name","category",false);

prop.getBoolean();

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Property prop = config.get("name","category",false);

prop.getBoolean();

And how can I put it into the button? It only works when it is in the preInit.

doesStuff = config.get(name, category, false, "").getBoolean();

Loads a boolean called doesStuff into code. Then I can change that boolean and it will change in the file. In case of a button you use Gui#actionPerformed(GuiButton). Check if the button is the button you want then change the boolean called doesStuff in this example.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Property prop = config.get("name","category",false);

prop.getBoolean();

And how can I put it into the button? It only works when it is in the preInit.

doesStuff = config.get(name, category, false, "").getBoolean();

Loads a boolean called doesStuff into code. Then I can change that boolean and it will change in the file. In case of a button you use Gui#actionPerformed(GuiButton). Check if the button is the button you want then change the boolean called doesStuff in this example.

I just tried

@Override
protected void actionPerformed(GuiButton button) throws IOException {
	if(button == button2) {
		Minecraft.getMinecraft().displayGuiScreen(new GUI2());
		doesStuff = config1.get(name, category, false, "").getBoolean();
	}

but it doesnt work. Am I doing something wrong?

Link to comment
Share on other sites

Ok, in preInit load your config into static variables ie

public static boolean doesStuff;

public void preInit(FMLPreInitializationEvent event) {
     Configuration config = new Configuration(event.getSuggestedConfigurationFile());
     doesStuff = config.get(name, category, defaultValue, comment);
}

Then in your Gui#actionPerformed(GuiButton) change doesStuff to what you want to.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Ok, in preInit load your config into static variables ie

public static boolean doesStuff;

public void preInit(FMLPreInitializationEvent event) {
     Configuration config = new Configuration(event.getSuggestedConfigurationFile());
     doesStuff = config.get(name, category, defaultValue, comment);
}

Then in your Gui#actionPerformed(GuiButton) change doesStuff to what you want to.

It says

Cannot convert from Property to Boolean
Link to comment
Share on other sites

Ok, in preInit load your config into static variables ie

public static boolean doesStuff;

public void preInit(FMLPreInitializationEvent event) {
     Configuration config = new Configuration(event.getSuggestedConfigurationFile());
     doesStuff = config.get(name, category, defaultValue, comment);
}

Then in your Gui#actionPerformed(GuiButton) change doesStuff to what you want to.

It says

Cannot convert from Property to Boolean

Do you not know what that means?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Ok, in preInit load your config into static variables ie

public static boolean doesStuff;

public void preInit(FMLPreInitializationEvent event) {
     Configuration config = new Configuration(event.getSuggestedConfigurationFile());
     doesStuff = config.get(name, category, defaultValue, comment);
}

Then in your Gui#actionPerformed(GuiButton) change doesStuff to what you want to.

It says

Cannot convert from Property to Boolean

Do you not know what that means?

I guess I should make it

public static Property doesStuff;

public void preInit(FMLPreInitializationEvent event) {
     Configuration config = new Configuration(event.getSuggestedConfigurationFile());
     doesStuff = config.get(name, category, defaultValue, comment);
}

but then I can't get it in the Button

Link to comment
Share on other sites

If your GUI is something you made for a block then  use TileEntity and store your booleans as NBT tags. 

 

 

However you do this you must realize that ALL variables in the game are reset to 0 every time you restart the game unless you store them periodically such as a file, config, NBT or meta. To get them back you need to set properties at object construction time with the data you get from all those areas you saved them to. All of this requires  extra code to make them restore data .

 

For ex to restore meta in a block you need to actually have a functions get state from meta and meta from state. To restore NBT you need to read and write NBT .

 

In short

Nothing you place there stays placed there unless you save it. 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

If your GUI is something you made for a block then  use TileEntity and store your booleans as NBT tags. 

 

 

However you do this you must realize that all variables in the game are reset to 0 every time you restart the game unless you store them periodically such as a file, config, NBT or meta. To get them back you need to set properties at object construction time with the data you get from all those areas you saved them to. All of these require code to make them restore data .

I have already made a config with these values but I dont't know how to override them. (When the boolean changes)

Link to comment
Share on other sites

I have already made a config with these values but I dont't know how to override them. (When the boolean changes)

 

To override them in gui constructor you do something like

 

 

Gui MyGui {

Boolean boolean1

Boolean boolean2

 

public MyGui() {

boolean1 = Config.getmyBoolean1

boolean2 = Config.getmyBoolean2

}

 

all other gui code here

 

}

 

of course how to set up boolean or what type of boolean you use changes how you assign it. but essentially that's how you do it.

 

So when you boot up the game again your gui is set to your variables saved from last time.

 

Everytime the Gui is constructred it will first populate all your variables.

 

Ideally you wanna do Config load/write before everything then do construction. ALL in preInit()

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

I have already made a config with these values but I dont't know how to override them. (When the boolean changes)

 

To override them in gui constructor you do something like

 

 

Gui MyGui {

Boolean boolean1

Boolean boolean2

 

public MyGui() {

boolean1 = Config.getmyBoolean1

boolean2 = Config.getmyBoolean2

}

 

all other gui code here

 

}

 

of course how to set up boolean or what type of boolean you use changes how you assign it. but essentially that's how you do it.

 

So when you boot up the game again your gui is set to your variables saved from last time.

 

Everytime the Gui is constructred it will first populate all your variables.

 

Ideally you wanna do Config load/write before everything then do construction. ALL in preInit()

I do know that already, but how do I change the variable in the config by clicking a button?

Link to comment
Share on other sites

Oh ahah ok ok

 

that's actually a good point. maybe config is not for you then

 

You need to save stuff to config . config only does it the other way around takes it out of config from what the user changed. you need to save to a file your booleans  or save to NBT data or something like that.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Oh ahah ok ok

 

that's actually really easy

 

config = new Configuration(e.getSuggestedConfigurationFile());

config.load();

 

boolean1  = config.getBoolean("bool1", "savedBooleansCategory", myGui.myBoolean1, "");

 

config.save();

 

if what is inside the config is different it will be re-written with your new value automatically . the value you set overrides the value you get . save and load is all done in one pass. the save is done when you do config.save()]

 

so you need a whole new set of temporary values someplace in the config to check against

But I can only do that in the preInit, dont I? I want to do that in an actionPerformed event

@Override
protected void actionPerformed(GuiButton button) throws IOException {
	if(button == button2) {
		Minecraft.getMinecraft().displayGuiScreen(new GUI2());
                        //Here should be the config change
	}

Link to comment
Share on other sites

yeah true i updated my comment . you cannot use config that way :D i misunderstood what you meant . you need to use NBT or save to a file

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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