Posted December 10, 20168 yr 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)
December 10, 20168 yr what are you trying to do? Where are you trying to store this boolean? On a block? Item? Entity? World? Explain yourself, show code
December 10, 20168 yr Author 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); }
December 10, 20168 yr Author 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?
December 10, 20168 yr Author 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();
December 10, 20168 yr Author 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); }
December 10, 20168 yr 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.
December 10, 20168 yr Author You should probably start invoking those methods, yes. But how? Can you give me an example?
December 10, 20168 yr 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.
December 11, 20168 yr Author 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.
December 11, 20168 yr 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.
December 11, 20168 yr Author 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?
December 11, 20168 yr 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.
December 11, 20168 yr Author 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
December 11, 20168 yr 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.
December 11, 20168 yr Author 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
December 11, 20168 yr 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.
December 11, 20168 yr Author 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)
December 11, 20168 yr 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.
December 11, 20168 yr Author 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?
December 11, 20168 yr 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.
December 11, 20168 yr Author 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 }
December 11, 20168 yr yeah true i updated my comment . you cannot use config that way 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.
December 11, 20168 yr Author yeah true i updated my comment . you cannot use config that way i misunderstood what you meant . you need to use NBT or save to a file Do you know how to do that?
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.