Jump to content

Recommended Posts

Posted (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 by jredfox
Posted (edited)
8 hours ago, 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.

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

2018-04-14_23.06.56.png

Edited by jredfox
Posted (edited)
8 hours ago, 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.

 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 by jredfox
Posted (edited)
54 minutes ago, 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".

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 by jredfox
Posted
1 hour ago, diesieben07 said:

If you have buttons in a gui, save on gui close.

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

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



×
×
  • Create New...

Important Information

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