extend dimension system, remove dim ids

This commit is contained in:
Sen 2025-06-29 19:09:47 +02:00
parent a080ed5583
commit f613bd2122
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
46 changed files with 1216 additions and 1283 deletions

View file

@ -247,7 +247,6 @@ public final class Server implements IThreadListener, Executor {
for(SVar svar : this.variables.values()) {
svar.set(svar.def, svar.noDef, false);
}
UniverseRegistry.clear();
}
}
Log.IO.info("Erstelle neue Welt und Konfiguration");
@ -374,8 +373,8 @@ public final class Server implements IThreadListener, Executor {
double posZ = tag.getDouble("PosZ");
float rotYaw = tag.getFloat("Yaw");
float rotPitch = tag.getFloat("Pitch");
int dimension = tag.getInt("Dimension");
return new Position(posX, posY, posZ, rotYaw, rotPitch, dimension);
Dimension dimension = UniverseRegistry.getDimension(tag.getString("Dimension"));
return dimension == null ? null : new Position(posX, posY, posZ, rotYaw, rotPitch, dimension);
}
public void saveAllWorlds(boolean message) {
@ -393,12 +392,12 @@ public final class Server implements IThreadListener, Executor {
}
private void unloadWorld(Dimension dim) {
WorldServer world = this.dimensions.get(dim.getDimensionId());
WorldServer world = this.dimensions.get(UniverseRegistry.getId(dim));
if(world != null && world.players.isEmpty()) {
world.saveAllChunks();
Region.finishWrite();
this.worlds.remove(world);
this.dimensions.remove(dim.getDimensionId());
this.dimensions.remove(UniverseRegistry.getId(dim));
}
}
@ -411,12 +410,12 @@ public final class Server implements IThreadListener, Executor {
}
User.loadDatabase(this.users);
this.worlds.add(this.space = new WorldServer(this, wtime, Space.INSTANCE));
this.dimensions.put(this.space.dimension.getDimensionId(), this.space);
this.dimensions.put(UniverseRegistry.getId(this.space.dimension), this.space);
new File("players").mkdirs();
this.setTpsTarget(20.0f);
for(Dimension dim : UniverseRegistry.getDimensions()) {
if(WorldServer.needsLoading(dim)) {
this.getWorld(dim.getDimensionId()).loadForcedChunks();
this.getWorld(dim).loadForcedChunks();
}
WorldServer.loadWarps(dim, this.warps);
}
@ -570,26 +569,25 @@ public final class Server implements IThreadListener, Executor {
return this.space;
}
public WorldServer getWorld(int dimension) {
WorldServer world = this.dimensions.get(dimension);
public WorldServer getWorld(Dimension dim) {
if(dim == null)
return null;
WorldServer world = this.dimensions.get(UniverseRegistry.getId(dim));
if(world == null) {
Dimension dim = UniverseRegistry.getDimension(dimension);
if(dim == null)
return null;
world = new WorldServer(this, this.space.getDayTime(), dim);
this.worlds.add(world);
this.dimensions.put(dimension, world);
this.dimensions.put(UniverseRegistry.getId(dim), world);
}
return world;
}
public WorldServer getWorldNoLoad(int dimension) {
return this.dimensions.get(dimension);
public WorldServer getWorldNoLoad(Dimension dim) {
return dim == null ? null : this.dimensions.get(UniverseRegistry.getId(dim));
}
public WorldServer getWorld(String alias) {
Dimension dim = UniverseRegistry.getDimension(alias);
return dim == null ? null : this.getWorld(dim.getDimensionId());
return dim == null ? null : this.getWorld(dim);
}
public List<WorldServer> getWorlds() {
@ -698,7 +696,7 @@ public final class Server implements IThreadListener, Executor {
int y = pos.getY();
while(world.getState(new BlockPos(pos.getX(), y, pos.getZ())).getBlock().getMaterial().blocksMovement() && y < 511)
y++;
return new Position(pos.getX() + 0.5, (double)y, pos.getZ() + 0.5, -180.0f + world.rand.floatv() * 360.0f, 0.0f, world.dimension.getDimensionId());
return new Position(pos.getX() + 0.5, (double)y, pos.getZ() + 0.5, -180.0f + world.rand.floatv() * 360.0f, 0.0f, world);
}
public void addUser(User user) {
@ -727,7 +725,7 @@ public final class Server implements IThreadListener, Executor {
this.online.put(loginUser, conn);
tag = conn.readCharacter();
WorldServer world = tag == null ? this.space : this.getWorld(tag.getInt("Dimension"));
WorldServer world = tag == null ? this.space : this.getWorld(tag.getString("Dimension"));
world = world == null ? this.space : world;
EntityNPC player = conn.createPlayer(world, tag == null ? EntityRegistry.getEntityString(EntityHuman.class) : tag.getString("id"));
if(tag != null)
@ -738,7 +736,7 @@ public final class Server implements IThreadListener, Executor {
player.moveToBlockPosAndAngles(new BlockPos(0, 16384, 0), 0.0f, 0.0f);
Log.NETWORK.info(loginUser + "[" + connection.getCutAddress() + "] hat sich mit Objekt-ID "
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": "
+ 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() + "'") + ")");
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
@ -811,7 +809,7 @@ public final class Server implements IThreadListener, Executor {
if(entity != null) {
TagObject etag = new TagObject();
entity.writeTags(etag);
etag.setInt("Dimension", entity.worldObj.dimension.getDimensionId());
etag.setString("Dimension", UniverseRegistry.getName(entity.worldObj.dimension));
etag.setString("id", EntityRegistry.getEntityString(entity));
conn.writeCharacter(etag);
}
@ -878,7 +876,7 @@ public final class Server implements IThreadListener, Executor {
nplayer.setPosition(nplayer.posX, nplayer.posY + 1.0D, nplayer.posZ);
}
}
conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
conn.sendPacket(new SPacketRespawn(world.dimension != oldWorld.dimension ? world.dimension : null, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch);
conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel));
this.updateTimeAndWeatherForPlayer(conn, world);
@ -898,7 +896,7 @@ public final class Server implements IThreadListener, Executor {
old.unmount();
TagObject oldTag = new TagObject();
old.writeTags(oldTag);
oldTag.setInt("Dimension", old.worldObj.dimension.getDimensionId());
oldTag.setString("Dimension", UniverseRegistry.getName(old.worldObj.dimension));
oldTag.setString("id", EntityRegistry.getEntityString(old));
WorldServer oldWorld = (WorldServer)old.getServerWorld();
@ -907,7 +905,7 @@ public final class Server implements IThreadListener, Executor {
oldWorld.removePlayer(old);
oldWorld.removePlayerEntityDangerously(old);
WorldServer world = tag == null ? this.space : this.getWorld(tag.getInt("Dimension"));
WorldServer world = tag == null ? this.space : this.getWorld(tag.getString("Dimension"));
world = world == null ? this.space : world;
EntityNPC nplayer = conn.createPlayer(world, tag == null ? EntityRegistry.getEntityString(clazz) : tag.getString("id"));
if(tag != null)
@ -920,7 +918,7 @@ public final class Server implements IThreadListener, Executor {
world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
world.addPlayer(nplayer);
world.spawnEntityInWorld(nplayer);
conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
conn.sendPacket(new SPacketRespawn(world.dimension != oldWorld.dimension ? world.dimension : null, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
conn.sendPacket(new SPacketSkin(nplayer.getId(), nplayer.getSkin())); // , nplayer.getModel()));
conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch);
conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel));
@ -935,7 +933,7 @@ public final class Server implements IThreadListener, Executor {
return oldTag;
}
public void transferToDimension(EntityNPC player, int dimension, BlockPos pos, float yaw, float pitch, PortalType portal) {
public void transferToDimension(EntityNPC player, Dimension dimension, BlockPos pos, float yaw, float pitch, PortalType portal) {
WorldServer oldWorld = (WorldServer)player.getServerWorld(); // this.getWorld(player.dimension);
WorldServer newWorld = this.getWorld(dimension);
player.connection.sendPacket(new SPacketRespawn(newWorld.dimension, EntityRegistry.getEntityID(player), player.connection.isInEditor()));
@ -998,32 +996,6 @@ public final class Server implements IThreadListener, Executor {
}
}
public void sendPacket(Packet packet, int dimension) {
for(Player conn : this.players) {
if(conn.getEntity() != null && conn.getEntity().worldObj.dimension.getDimensionId() == dimension) {
conn.sendPacket(packet);
}
}
}
public void sendNear(double x, double y, double z, double radius, int dimension, Packet packet) {
this.sendNearExcept(null, x, y, z, radius, dimension, packet);
}
public void sendNearExcept(EntityNPC except, double x, double y, double z, double radius, int dimension, Packet packet) {
for(Player conn : this.players) {
EntityNPC player = conn.getEntity();
if(player != null && player != except && player.worldObj.dimension.getDimensionId() == dimension) {
double dx = x - player.posX;
double dy = y - player.posY;
double dz = z - player.posZ;
if(dx * dx + dy * dy + dz * dz < radius * radius) {
conn.sendPacket(packet);
}
}
}
}
public void saveAllPlayerData(boolean message) {
if(message) {
Log.TICK.info("Speichere Spielerdaten");