improve loading more than 2 zones
All checks were successful
/ Auto-Build-App (push) Successful in 1m59s

This commit is contained in:
pietru 2025-04-28 21:41:03 +02:00
parent 04549403c5
commit a6fd82b57e

View file

@ -1,37 +1,51 @@
package net.pietru.cookie_utils.mixins;
import finalforeach.cosmicreach.GameSingletons;
import finalforeach.cosmicreach.Threads;
import finalforeach.cosmicreach.TickRunner;
import finalforeach.cosmicreach.networking.netty.NettyServer;
import finalforeach.cosmicreach.world.Zone;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import static net.pietru.cookie_utils.utils.prop.get_server_property_array;
@Mixin(NettyServer.class)
public class NettyServerMixin {
@Inject(method = "Lfinalforeach/cosmicreach/networking/netty/NettyServer;<init>()V", at = @At("TAIL"))
private void on_singletons_create(CallbackInfo ci){
@Unique
private static final Timer t = new Timer();
@Inject(method = "run", at = @At("HEAD"))
private void on_singletons_create(CallbackInfo ci) {
try {
ArrayList<String> zones = get_server_property_array("zones","[]");
for (String zoneId : zones){
Zone z = GameSingletons.world.getZoneIfExists(zoneId.replace(" ",""));
ArrayList<String> zones = get_server_property_array("zones", "[]");
int i = 1;
for (String zoneId : zones) {
Zone z = GameSingletons.world.getZoneIfExists(zoneId.replace(" ", ""));
if (!zoneId.isEmpty() && z == null && GameSingletons.isHost) {
z = Zone.loadZone(GameSingletons.world, zoneId.replace(" ",""));
GameSingletons.world.addZone(z);
System.out.printf("Loading %s in %d seconds\n",zoneId,i);
t.schedule(new TimerTask() {
@Override
public void run() {
Zone z = Zone.loadZone(GameSingletons.world, zoneId.replace(" ", ""));
GameSingletons.world.addZone(z);
}
}, (long) i * 1000);
i++;
}
}
System.out.println("CookieUtils loaded additional zones...");
} catch (IOException e) {
throw new RuntimeException(e);
}
TickRunner.INSTANCE.continueTickThread();
}
}