add variable sync

This commit is contained in:
Sen 2025-07-11 23:01:59 +02:00
parent b6242d5de1
commit aee94aa14d
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
33 changed files with 392 additions and 200 deletions

View file

@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@ -77,15 +78,16 @@ import common.packet.SPacketDisconnect;
import common.packet.SPacketHeldItemChange;
import common.packet.SPacketJoinGame;
import common.packet.SPacketRespawn;
import common.packet.SPacketServerConfig;
import common.packet.SPacketSetExperience;
import common.packet.SPacketSkin;
import common.packet.SPacketTimeUpdate;
import common.packet.SPacketWorld;
import common.tags.TagObject;
import common.util.BlockPos;
import common.util.EncryptUtil;
import common.util.ExtMath;
import common.util.LazyLoader;
import common.util.Pair;
import common.util.PortalType;
import common.util.Position;
import common.util.Util;
@ -274,18 +276,10 @@ public final class Server implements IThreadListener, Executor {
throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!");
if(this.variables.containsKey(value.name()))
throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!");
this.variables.put(value.name(), new SVar(field, value));
this.variables.put(value.name(), new SVar(field, value, clazz == Vars.class));
}
}
}
this.setCallback(new Runnable() {
public void run() {
for(WorldServer world : Server.this.getWorlds()) {
world.updatePhysics();
}
Server.this.sendPacket(new SPacketWorld(WorldServer.clampGravity(), SVars.dayCycle, SVars.timeFlow));
}
}, "daylightCycle", "timeFlow", "gravity");
this.setCallback(new Runnable() {
public void run() {
for(WorldServer world : Server.this.getWorlds()) {
@ -495,14 +489,14 @@ public final class Server implements IThreadListener, Executor {
public void preload(WorldServer world, int bx, int bz) {
int done = 0;
int total = SVars.distance * 2 + 1;
int total = Vars.distance * 2 + 1;
total *= total;
Log.TICK.info("Generiere und lade Welt");
bx = bx >> 4;
bz = bz >> 4;
long last = System.currentTimeMillis();
for(int x = -SVars.distance; x <= SVars.distance; x++) {
for(int z = -SVars.distance; z <= SVars.distance; z++) {
for(int x = -Vars.distance; x <= Vars.distance; x++) {
for(int z = -Vars.distance; z <= Vars.distance; z++) {
long time = System.currentTimeMillis();
if(time - last > 1000L) {
Log.TICK.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%");
@ -739,10 +733,14 @@ public final class Server implements IThreadListener, Executor {
+ player.getId() + " auf " + UniverseRegistry.getName(world.dimension) + ": "
+ String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? "Charakter-Editor" : "'" + player.getCommandName() + "'") + ")");
List<Pair<String, Object>> vars = Lists.newArrayList();
for(Entry<String, SVar> var : this.variables.entrySet()) {
if(var.getValue().sync)
vars.add(new Pair(var.getKey(), var.getValue().getRaw()));
}
conn.sendPacket(new SPacketServerConfig(vars));
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(),
SVars.dayCycle, SVars.timeFlow));
this.sendPacket(new SPacketPlayerListItem(false, conn));
world.spawnEntityInWorld(player);