moving loading of scripts to after worlds are loaded, fixes #331

This commit is contained in:
gnembon committed 2020-06-20 23:29:50 -03:00
1 parent d838cfd32f
commit be7d7ed46e
3 files changed
+22 -3

No files matched your search

+10 -1
View File
@@ -16,11 +16,18 @@ public interface CarpetExtension
default void onGameStarted() {} default void onGameStarted() {}
/** /**
* Runs once per loaded world once the World files / gamerules etc are fully loaded * Runs once per loaded world once the server / gamerules etc are fully loaded
* but before worlds are loaded
* Can be loaded multiple times in SinglePlayer * Can be loaded multiple times in SinglePlayer
*/ */
default void onServerLoaded(MinecraftServer server) {} default void onServerLoaded(MinecraftServer server) {}
/**
* Runs once per loaded world once the World files are fully loaded
* Can be loaded multiple times in SinglePlayer
*/
default void onServerLoadedWorlds(MinecraftServer server) {}
/** /**
* Runs once per game tick, as a first thing in the tick * Runs once per game tick, as a first thing in the tick
*/ */
@@ -55,4 +62,6 @@ public interface CarpetExtension
default void registerLoggers() {} default void registerLoggers() {}
default Map<String, String> canHasTranslations(String lang) { return null;} default Map<String, String> canHasTranslations(String lang) { return null;}
} }
+6 -1
View File
@@ -58,12 +58,17 @@ public class CarpetServer // static for now - easier to handle all around the co
e.onServerLoaded(server); e.onServerLoaded(server);
}); });
scriptServer = new CarpetScriptServer(server); scriptServer = new CarpetScriptServer(server);
scriptServer.loadAllWorldScripts();
MobAI.resetTrackers(); MobAI.resetTrackers();
LoggerRegistry.initLoggers(); LoggerRegistry.initLoggers();
//TickSpeed.reset(); //TickSpeed.reset();
} }
public static void onServerLoadedWorlds(MinecraftServer minecraftServer)
{
extensions.forEach(e -> e.onServerLoadedWorlds(minecraftServer));
scriptServer.loadAllWorldScripts();
}
public static void tick(MinecraftServer server) public static void tick(MinecraftServer server)
{ {
TickSpeed.tick(server); TickSpeed.tick(server);
@@ -31,13 +31,18 @@ public abstract class MinecraftServer_coreMixin
CarpetServer.tick((MinecraftServer) (Object) this); CarpetServer.tick((MinecraftServer) (Object) this);
} }
// Dedicated server only
@Inject(method = "loadWorld", at = @At("HEAD")) @Inject(method = "loadWorld", at = @At("HEAD"))
private void serverLoaded(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci) private void serverLoaded(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci)
{ {
CarpetServer.onServerLoaded((MinecraftServer) (Object) this); CarpetServer.onServerLoaded((MinecraftServer) (Object) this);
} }
@Inject(method = "loadWorld", at = @At("RETURN"))
private void serverLoadedWorlds(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci)
{
CarpetServer.onServerLoadedWorlds((MinecraftServer) (Object) this);
}
@Inject(method = "shutdown", at = @At("HEAD")) @Inject(method = "shutdown", at = @At("HEAD"))
private void serverClosed(CallbackInfo ci) private void serverClosed(CallbackInfo ci)
{ {