Skip to content

Commit 4d213c0

Browse files
committed
[Events] Add ServerStart Event
This event is fired before ServerInit when worlds are alredy loaded
1 parent 6bf4629 commit 4d213c0

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

src/main/java/com/minecrafttas/mctcommon/events/EventServer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
*/
1414
public interface EventServer {
1515

16+
/**
17+
* Fired, just before the server initialised, for both integrated and dedicated server.
18+
*/
19+
@FunctionalInterface
20+
public static interface EventServerStart extends EventBase {
21+
22+
/**
23+
* Fired, when the server is initialised, for both integrated and dedicated server.
24+
* @param server The server
25+
*/
26+
public void onServerStart(MinecraftServer server);
27+
}
28+
1629
/**
1730
* Fired, when the server is initialised, for both integrated and dedicated server.
1831
*/

src/main/java/com/minecrafttas/mctcommon/mixin/MixinMinecraftServer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
1010
import com.minecrafttas.mctcommon.events.EventServer.EventServerGameLoop;
1111
import com.minecrafttas.mctcommon.events.EventServer.EventServerInit;
12+
import com.minecrafttas.mctcommon.events.EventServer.EventServerStart;
1213
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
1314
import com.minecrafttas.mctcommon.events.EventServer.EventServerTick;
1415

@@ -17,6 +18,11 @@
1718
@Mixin(MinecraftServer.class)
1819
public class MixinMinecraftServer {
1920

21+
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z"))
22+
public void inject_initStart(CallbackInfo ci) {
23+
EventListenerRegistry.fireEvent(EventServerStart.class, (MinecraftServer) (Object) this);
24+
}
25+
2026
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z", shift = Shift.AFTER))
2127
public void inject_init(CallbackInfo ci) {
2228
EventListenerRegistry.fireEvent(EventServerInit.class, (MinecraftServer) (Object) this);

src/main/java/com/minecrafttas/tasmod/TASmod.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.minecrafttas.mctcommon.CommandRegistry;
99
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
1010
import com.minecrafttas.mctcommon.events.EventServer.EventServerInit;
11+
import com.minecrafttas.mctcommon.events.EventServer.EventServerStart;
1112
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
1213
import com.minecrafttas.mctcommon.networking.PacketHandlerRegistry;
1314
import com.minecrafttas.mctcommon.networking.Server;
@@ -32,8 +33,8 @@
3233
import com.minecrafttas.tasmod.registries.TASmodPackets;
3334
import com.minecrafttas.tasmod.savestates.SavestateHandlerServer;
3435
import com.minecrafttas.tasmod.savestates.handlers.SavestateResourcePackHandler;
35-
import com.minecrafttas.tasmod.savestates.storage.builtin.KTRNGSeedStorage;
3636
import com.minecrafttas.tasmod.savestates.storage.builtin.ClientMotionStorage;
37+
import com.minecrafttas.tasmod.savestates.storage.builtin.KTRNGSeedStorage;
3738
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer;
3839
import com.minecrafttas.tasmod.ticksync.TickSyncServer;
3940
import com.minecrafttas.tasmod.util.LoggerMarkers;
@@ -49,7 +50,7 @@
4950
*
5051
* @author Scribble
5152
*/
52-
public class TASmod implements ModInitializer, EventServerInit, EventServerStop {
53+
public class TASmod implements ModInitializer, EventServerStart, EventServerInit, EventServerStop {
5354

5455
public static final Logger LOGGER = LogManager.getLogger("TASmod");
5556

@@ -138,6 +139,12 @@ public void onInitialize() {
138139
registerSavestateStorage();
139140
}
140141

142+
@Override
143+
public void onServerStart(MinecraftServer server) {
144+
globalRandomness = new GlobalRandomnessTimer();
145+
EventListenerRegistry.register(globalRandomness);
146+
}
147+
141148
@Override
142149
public void onServerInit(MinecraftServer server) {
143150
LOGGER.info("Initializing server");
@@ -162,9 +169,6 @@ public void onServerInit(MinecraftServer server) {
162169
PacketHandlerRegistry.register(savestateHandlerServer);
163170
PacketHandlerRegistry.register(savestateHandlerServer.getPlayerHandler());
164171

165-
globalRandomness = new GlobalRandomnessTimer();
166-
EventListenerRegistry.register(globalRandomness);
167-
168172
if (!server.isDedicatedServer()) {
169173
TASmod.tickratechanger.ticksPerSecond = 0F;
170174
TASmod.tickratechanger.tickrateSaved = 20F;

src/main/java/com/minecrafttas/tasmod/registries/TASmodAPIRegistry.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TASmodAPIRegistry {
2020
* savestate/rerecord count and category.
2121
*
2222
* <p>Any custom class has to implement PlaybackMetadataExtension
23+
* <p><strong>Side: Client</strong></p>
2324
*/
2425
public static final PlaybackMetadataRegistry PLAYBACK_METADATA = new PlaybackMetadataRegistry();
2526

@@ -28,7 +29,7 @@ public class TASmodAPIRegistry {
2829
*
2930
* <p>File commands give the opportunity to run commands on each recorded tick and each played back tick.<br>
3031
* File commands also have access to the TASfile so that data can be stored and read in/from the TASfile.
31-
*
32+
* <p><strong>Side: Client</strong></p>
3233
*/
3334
public static final PlaybackFileCommandsRegistry PLAYBACK_FILE_COMMAND = new PlaybackFileCommandsRegistry();
3435

@@ -39,6 +40,7 @@ public class TASmodAPIRegistry {
3940
* or extend an existing flavor (like {@link Beta1Flavor}) and overwrite parts of the methods.
4041
*
4142
* <p>The resulting flavor can be registered here and can be found as a saving option with /saveTAS
43+
* <p><strong>Side: Client</strong></p>
4244
*/
4345
public static final SerialiserFlavorRegistry SERIALISER_FLAVOR = new SerialiserFlavorRegistry();
4446

@@ -47,13 +49,15 @@ public class TASmodAPIRegistry {
4749
*
4850
* <p>Create a new ClientCommand by extending {@link ClientCommandBase},<br>
4951
* then create a command like normal, as it extends from the vanilla {@link CommandBase}
52+
* <p><strong>Side: Client</strong></p>
5053
*/
5154
public static final ClientCommandRegistry CLIENT_COMMANDS = new ClientCommandRegistry();
5255

5356
/**
5457
* <p>Registry for registering additional data that should be stored or loaded during a Savestate or Loadstate respectively
5558
*
5659
* <p>Create a new SavestateStorageExtension by extending {@link SavestateStorageExtensionBase}
60+
* <p><strong>Side: Server</strong></p>
5761
*/
5862
public static final SavestateStorageExtensionRegistry SAVESTATE_STORAGE = new SavestateStorageExtensionRegistry();
5963
}

0 commit comments

Comments
 (0)