jredfox Posted April 15, 2018 Posted April 15, 2018 (edited) How to: On Minecraft X/Quite Button Save Data? I see a on world save event but, what about the quit button? I store gui main menu data that needs to only be saved once the game closes how is this accomplished? Edit: I looked at the minecraft class the button says is running false and then next thing you know it calls a method to use System.exit() I see no forge hooks on saving app is there a work around for this? Edited April 15, 2018 by jredfox Quote
jredfox Posted April 15, 2018 Author Posted April 15, 2018 (edited) On 4/15/2018 at 11:48 AM, diesieben07 said: You should save your data whenever it changes, not when the game is about to be closed. This way you can avoid data loss in case of a crash or another unexpected shutdown. Expand Well if that were to occur and if your like me menu saving would occur 100 times in 20 seconds but, I could make a gui to save the order. Aether menu test 1.12.2 also tested with my own panoramic menu Edited April 15, 2018 by jredfox Quote
jredfox Posted April 15, 2018 Author Posted April 15, 2018 (edited) On 4/15/2018 at 11:48 AM, diesieben07 said: You should save your data whenever it changes, not when the game is about to be closed. This way you can avoid data loss in case of a crash or another unexpected shutdown. Expand if (world != null) net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Unload(world)); Forge specifically ignores minecraft unloading the game as null the only time it's ever called when null is minecraft game is saving and does nothing with it. This is stupid I can't properly write to the minecraft app on save if I can't detect if the world is null or not under minecraft shutdown Is this a reliable way to detect mc is closing it prints but, I don't know if it will print every time? @SubscribeEvent public void onCloseApp(ClientTickEvent event) { Boolean b = (Boolean) ReflectionUtil.getObject(Minecraft.getMinecraft(), Minecraft.class, FieldAcess.running); if(!b) { for(int i=0;i<2;i++) System.out.println("Minecraft Is shutting down isRunning:" + b); } } Edited April 15, 2018 by jredfox Quote
jredfox Posted April 15, 2018 Author Posted April 15, 2018 (edited) On 4/15/2018 at 8:56 PM, diesieben07 said: I said to save the data when it changes. If your data seriously changes 100 times in 20 seconds, you need to employ some buffering, e.g. only save once every 20 seconds. But I doubt this is the case. Why would it fire WorldEvent.Unload if there is no world? WorldEvent.Unload only makes sense if a world is being unloaded. Nothing about this is "stupid". Expand well they should have on mc close for data that doesn't want to constantly write to the disk. My client tick code failed twice out of 30 tests so I took your advice and every update write to the disk (unoptimized). The users might play with the gui buttons and change them 100 times in 20 seconds is what I am saying but, yes it saves to the disk every time now. Edit: what is forge doing that my ConfigBase isn't? It says 3-4ms alot of the times and my config base says 7-14ms. I use Files.readAllLines(utf-8) and Files.write(utf-8). Now I do parse lines and have checkers but, that's about it: https://github.com/jredfox/evilnotchlib/blob/master/src/main/java/com/EvilNotch/lib/util/Line/ConfigBase.java public static void saveMenuIndex() { long stamp = System.currentTimeMillis(); Configuration config = new Configuration(cfg); config.load(); Property prop = config.get("menulib", "CurrentMenuIndex", "minecraft:mainmenu"); ResourceLocation loc = MenuRegistry.getCurrentMenu().getId(); prop.set(loc.toString()); currentMenuIndex = loc; config.save(); JavaUtil.printTime(stamp, "Saved Current Menu:"); } Edited April 15, 2018 by jredfox Quote
jredfox Posted April 15, 2018 Author Posted April 15, 2018 On 4/15/2018 at 10:22 PM, diesieben07 said: If you have buttons in a gui, save on gui close. Expand I overlay the buttons to any gui so on button activated via forge event I save it same concept. The buttons next and previous are for the next gui in the array list of menus Quote
Recommended Posts
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.