From 03b0244084755b955cd427ba49f9c16bb8417c65 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 4 May 2022 11:31:39 +0100 Subject: [PATCH] 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. --- .../computercraft/core/computer/MainThread.java | 4 ++-- .../dan200/computercraft/shared/CommonHooks.java | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/computer/MainThread.java b/src/main/java/dan200/computercraft/core/computer/MainThread.java index c1658aa67..222abb274 100644 --- a/src/main/java/dan200/computercraft/core/computer/MainThread.java +++ b/src/main/java/dan200/computercraft/core/computer/MainThread.java @@ -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 * (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 - * still over budget, then we should not execute any work (either as part of {@link MainThread} or externally). + * Next tick, we add {@link ComputerCraft#maxMainGlobalTime} to our budget (clamp it to that value too). If we're still + * over budget, then we should not execute any work (either as part of {@link MainThread} or externally). */ public final class MainThread { diff --git a/src/main/java/dan200/computercraft/shared/CommonHooks.java b/src/main/java/dan200/computercraft/shared/CommonHooks.java index 842a8af3d..864772eba 100644 --- a/src/main/java/dan200/computercraft/shared/CommonHooks.java +++ b/src/main/java/dan200/computercraft/shared/CommonHooks.java @@ -29,7 +29,6 @@ import net.minecraftforge.event.*; import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; 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.FMLServerStoppedEvent; @@ -90,22 +89,21 @@ public final class CommonHooks { ComputerMBean.register(); } - } - @SubscribeEvent - public static void onServerStarted( FMLServerStartedEvent event ) - { - ComputerCraft.serverComputerRegistry.reset(); - WirelessNetwork.resetNetworks(); - Tracking.reset(); + resetState(); ComputerMBean.registerTracker(); - NetworkUtils.reset(); } @SubscribeEvent public static void onServerStopped( FMLServerStoppedEvent event ) + { + resetState(); + } + + private static void resetState() { ComputerCraft.serverComputerRegistry.reset(); + MainThread.reset(); WirelessNetwork.resetNetworks(); Tracking.reset(); NetworkUtils.reset();