1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-14 20:20:30 +00:00

Minor improvements to resetting code

- Reset state while the server is starting rather than once it has
   started. Hopefully fixes a weird issue where wireless modems wouldn't
   be "connected" on server startup.

 - Correctly reset the MainThread metrics on server start/stop.
This commit is contained in:
Jonathan Coates 2022-05-04 11:31:39 +01:00
parent e2189535b8
commit 03b0244084
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 9 additions and 11 deletions

View File

@ -23,8 +23,8 @@ import java.util.concurrent.atomic.AtomicLong;
* {@link MainThread} starts cool, and runs as many tasks as it can in the current {@link #budget}ns. Any external tasks * {@link MainThread} starts cool, and runs as many tasks as it can in the current {@link #budget}ns. Any external tasks
* (those run by tile entities, etc...) will also consume the budget * (those run by tile entities, etc...) will also consume the budget
* *
* Next tick, we put {@link ComputerCraft#maxMainGlobalTime} into our budget (and clamp it to that value to). If we're * Next tick, we add {@link ComputerCraft#maxMainGlobalTime} to our budget (clamp it to that value too). If we're still
* still over budget, then we should not execute <em>any</em> work (either as part of {@link MainThread} or externally). * over budget, then we should not execute <em>any</em> work (either as part of {@link MainThread} or externally).
*/ */
public final class MainThread public final class MainThread
{ {

View File

@ -29,7 +29,6 @@ import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppedEvent; import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
@ -90,22 +89,21 @@ public final class CommonHooks
{ {
ComputerMBean.register(); ComputerMBean.register();
} }
}
@SubscribeEvent resetState();
public static void onServerStarted( FMLServerStartedEvent event )
{
ComputerCraft.serverComputerRegistry.reset();
WirelessNetwork.resetNetworks();
Tracking.reset();
ComputerMBean.registerTracker(); ComputerMBean.registerTracker();
NetworkUtils.reset();
} }
@SubscribeEvent @SubscribeEvent
public static void onServerStopped( FMLServerStoppedEvent event ) public static void onServerStopped( FMLServerStoppedEvent event )
{
resetState();
}
private static void resetState()
{ {
ComputerCraft.serverComputerRegistry.reset(); ComputerCraft.serverComputerRegistry.reset();
MainThread.reset();
WirelessNetwork.resetNetworks(); WirelessNetwork.resetNetworks();
Tracking.reset(); Tracking.reset();
NetworkUtils.reset(); NetworkUtils.reset();