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");

View file

@ -16,15 +16,6 @@ public class DimensionParser extends CompletingParser {
public Object parse(CommandEnvironment env, String input) {
Dimension dim = UniverseRegistry.getDimension(input);
if(dim != null)
return dim;
int id = Integer.MIN_VALUE;
try {
id = Integer.parseInt(input);
}
catch(NumberFormatException e) {
}
dim = UniverseRegistry.getDimension(id);
if(dim == null)
throw new RunException("Unbekannte Dimension '%s'", input);
return dim;
@ -34,7 +25,7 @@ public class DimensionParser extends CompletingParser {
if(!this.useSender)
return null;
Position pos = env.getExecutor().getExecPos();
return pos == null ? null : UniverseRegistry.getDimension(pos.dim());
return pos == null ? null : pos.getDimension();
// if(dim == null)
// throw new ScriptException("Unbekannte Dimension '%s'");
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import common.collect.Lists;
import common.dimension.Dimension;
import common.init.UniverseRegistry;
import server.world.WorldServer;
public class WorldParser extends DimensionParser {
@ -17,7 +18,7 @@ public class WorldParser extends DimensionParser {
public WorldServer parse(CommandEnvironment env, String input) {
Dimension dim = (Dimension)super.parse(env, input);
WorldServer world = this.loadedOnly ? env.getServer().getWorldNoLoad(dim.getDimensionId()) : env.getServer().getWorld(dim.getDimensionId());
WorldServer world = this.loadedOnly ? env.getServer().getWorldNoLoad(dim) : env.getServer().getWorld(dim);
if(world == null)
throw new RunException("Dimension '%s' ist nicht geladen", dim.getFormattedName(false));
return world;
@ -27,7 +28,7 @@ public class WorldParser extends DimensionParser {
Dimension dim = (Dimension)super.getDefault(env);
if(dim == null)
return null;
return this.loadedOnly ? env.getServer().getWorldNoLoad(dim.getDimensionId()) : env.getServer().getWorld(dim.getDimensionId());
return this.loadedOnly ? env.getServer().getWorldNoLoad(dim) : env.getServer().getWorld(dim);
// if(world == null)
// throw new ScriptException("Dimension '%s' ist nicht geladen", dim.getFormattedName(false));
// return world;
@ -37,7 +38,7 @@ public class WorldParser extends DimensionParser {
if(this.loadedOnly) {
List<String> loaded = Lists.newArrayList();
for(WorldServer world : env.getServer().getWorlds()) {
loaded.add(world.dimension.getDimensionName());
loaded.add(UniverseRegistry.getName(world.dimension));
}
return loaded;
}

View file

@ -4,7 +4,6 @@ import java.util.List;
import common.entity.Entity;
import common.entity.npc.EntityNPC;
import common.init.UniverseRegistry;
import common.util.Position;
import server.command.Command;
import server.command.CommandEnvironment;
@ -28,7 +27,7 @@ public class CommandDeathspot extends Command {
throw new RunException("%s hat keinen letzten Todespunkt", player.getCommandName());
for(Entity entity : entities) {
entity.teleport(pos);
exec.log("%s zum Todespunkt von %s (%d, %d, %d in %s) teleportiert", entity.getCommandName(), player.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false));
exec.log("%s zum Todespunkt von %s (%d, %d, %d in %s) teleportiert", entity.getCommandName(), player.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), pos.getDimension().getFormattedName(false));
}
return entities.size();
}

View file

@ -53,7 +53,7 @@ public class CommandLoad extends Command {
long orbit, long rotation, double offset, double gravity, double temperature, int brightness) {
if(teleport && !exec.isPlayer())
throw new RunException("Nur Spieler können teleportiert werden");
if(UniverseRegistry.getDimension(name) != null)
if(UniverseRegistry.isRegistered(name))
throw new RunException("Dimension '%s' existiert bereits", name);
if(name.equals(this.loadingDim))
throw new RunException("Dimension '%s' wird gerade geladen", name);
@ -76,7 +76,7 @@ public class CommandLoad extends Command {
if(teleport && pos != null) {
Player player = env.getServer().getPlayer(((Player)exec).getUser());
if(player != null && player.getPresentEntity() != null)
player.getPresentEntity().teleport(CommandWorld.adjust(env.getServer().getWorld(planet.getDimensionId()), pos), planet.getDimensionId());
player.getPresentEntity().teleport(CommandWorld.adjust(env.getServer().getWorld(planet), pos), planet);
}
})) == null) {
this.loadingDim = null;
@ -91,6 +91,6 @@ public class CommandLoad extends Command {
planet.setBiome(biome);
exec.log(TextColor.GREEN + "Dimension '%s' wurde registriert", display);
if(teleport && ((Player)exec).getPresentEntity() != null)
((Player)exec).getPresentEntity().teleport(CommandWorld.adjust(env.getServer().getWorld(planet.getDimensionId()), ((Player)exec).getPresentEntity().getPosition()), planet.getDimensionId());
((Player)exec).getPresentEntity().teleport(CommandWorld.adjust(env.getServer().getWorld(planet), ((Player)exec).getPresentEntity().getPosition()), planet);
}
}

View file

@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.List;
import common.entity.Entity;
import common.init.UniverseRegistry;
import common.util.Position;
import server.command.Command;
import server.command.CommandEnvironment;
@ -34,7 +33,7 @@ public class CommandOfflinetp extends Command {
throw new RunException("Spieler '%s' konnte nicht gefunden werden", user);
for(Entity entity : entities) {
entity.teleport(pos);
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false));
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), pos.getDimension().getFormattedName(false));
}
return entities.size();
}

View file

@ -3,7 +3,6 @@ package server.command.commands;
import java.util.List;
import common.entity.npc.EntityNPC;
import common.init.UniverseRegistry;
import common.util.Position;
import server.command.Command;
import server.command.CommandEnvironment;
@ -24,7 +23,7 @@ public class CommandReturn extends Command {
Position pos = ((Player)player.connection).getLastTeleport();
if(pos != null) {
player.teleport(pos);
exec.log("%s zum letzten Punkt (%d, %d, %d in %s) teleportiert", player.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false));
exec.log("%s zum letzten Punkt (%d, %d, %d in %s) teleportiert", player.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), pos.getDimension().getFormattedName(false));
done++;
}
}

View file

@ -26,7 +26,7 @@ public class CommandTele extends Command {
public Object exec(CommandEnvironment env, Executor exec, Vec3 position, Dimension dim, Double yaw, Double pitch, List<Entity> entities) {
for(Entity entity : entities) {
entity.teleport(position.xCoord, position.yCoord, position.zCoord, yaw == null ? entity.rotYaw : yaw.floatValue(), pitch == null ? entity.rotPitch : pitch.floatValue(), dim.getDimensionId());
entity.teleport(position.xCoord, position.yCoord, position.zCoord, yaw == null ? entity.rotYaw : yaw.floatValue(), pitch == null ? entity.rotPitch : pitch.floatValue(), dim);
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)position.xCoord, (int)position.yCoord, (int)position.zCoord, dim.getFormattedName(false));
}
return entities.size();

View file

@ -70,7 +70,7 @@ public class CommandTime extends Command {
public Object exec(CommandEnvironment env, Executor exec, String timeStr, boolean absolute) {
Position pos = exec.getExecPos();
WorldServer world = pos == null ? env.getServer().getSpace() : env.getServer().getWorld(pos.dim());
WorldServer world = pos == null ? env.getServer().getSpace() : env.getServer().getWorld(pos.getDimension());
long time = absolute ? 0L : world.getDayTime();
long fwd = parseDayTime(world.dimension, timeStr);
if(fwd >= 0L) {

View file

@ -3,7 +3,6 @@ package server.command.commands;
import java.util.List;
import common.entity.Entity;
import common.init.UniverseRegistry;
import common.util.Position;
import server.command.Command;
import server.command.CommandEnvironment;
@ -23,7 +22,7 @@ public class CommandTp extends Command {
Position pos = target.getPos();
for(Entity entity : entities) {
entity.teleport(pos);
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false));
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), pos.getDimension().getFormattedName(false));
}
return entities.size();
}

View file

@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.List;
import common.entity.Entity;
import common.init.UniverseRegistry;
import common.util.Position;
import server.command.Command;
import server.command.CommandEnvironment;
@ -43,12 +42,12 @@ public class CommandWarp extends Command {
pos = env.getServer().getWarps().get(warp);
if(pos == null)
throw new RunException("Warp '%s' existiert nicht", warp);
else if(env.getServer().getWorld(pos.dim()) == null)
throw new RunException("Warp '%s' hat kein Level (%s)", warp, pos.dim());
else if(pos.getDimension() == null)
throw new RunException("Warp '%s' hat keine Dimension", warp);
// }
for(Entity entity : entities) {
entity.teleport(pos);
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false));
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), pos.getDimension().getFormattedName(false));
}
return entities.size();
}

View file

@ -22,7 +22,7 @@ public class CommandWorld extends Command {
public Object exec(CommandEnvironment env, Executor exec, WorldServer world, List<Entity> entities) {
for(Entity entity : entities) {
BlockPos pos = adjust(world, entity.getPosition());
entity.teleport(pos, world.dimension.getDimensionId());
entity.teleport(pos, world);
exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), world.dimension.getFormattedName(false));
}
return entities.size();

View file

@ -628,21 +628,21 @@ public class Player extends User implements ICrafting, Executor, IPlayer
this.lastExperience = -1;
}
public void travelToDimension(int dimensionId, BlockPos pos, float yaw, float pitch, PortalType portal)
public void travelToDimension(Dimension dimensionId, BlockPos pos, float yaw, float pitch, PortalType portal)
{
this.server.transferToDimension(this.entity, dimensionId, pos, yaw, pitch, portal);
this.lastExperience = -1;
this.lastHealth = -1.0F;
}
public void teleport(double x, double y, double z, float yaw, float pitch, int dimension) {
public void teleport(double x, double y, double z, float yaw, float pitch, Dimension dimension) {
this.teleportPos = this.entity.getPos();
x = ExtMath.clampd(x, -World.MAX_SIZE + 1, World.MAX_SIZE - 1);
z = ExtMath.clampd(z, -World.MAX_SIZE + 1, World.MAX_SIZE - 1);
// this.setLastTeleport(this.getLocation());
this.entity.unmount();
// this.mountEntity(null);
if(this.entity.worldObj.dimension.getDimensionId() != dimension)
if(this.entity.worldObj.dimension != dimension)
this.travelToDimension(dimension, new BlockPos(x, y, z), yaw, pitch, null);
this.setPlayerLocation(x, y, z, yaw, pitch);
this.entity.setRotationYawHead(yaw);
@ -816,7 +816,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer
public void playSound(SoundEvent name, float volume)
{
this.server.sendNearExcept(this.entity, this.entity.posX, this.entity.posY, this.entity.posZ, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, this.entity.worldObj.dimension.getDimensionId(), new SPacketSoundEffect(name, this.entity.posX, this.entity.posY, this.entity.posZ, volume));
this.getEntityWorld().sendNearExcept(this.entity, this.entity.posX, this.entity.posY, this.entity.posZ, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, new SPacketSoundEffect(name, this.entity.posX, this.entity.posY, this.entity.posZ, volume));
}
@ -1362,8 +1362,8 @@ public class Player extends User implements ICrafting, Executor, IPlayer
}
private String selectPoint(BlockPos position, boolean second) {
if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != this.entity.worldObj.dimension.getDimensionId()) {
this.selectionDim = this.entity.worldObj.dimension.getDimensionId();
if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != UniverseRegistry.getId(this.entity.worldObj.dimension)) {
this.selectionDim = UniverseRegistry.getId(this.entity.worldObj.dimension);
this.selPos1 = null;
this.selPos2 = null;
}
@ -1390,13 +1390,16 @@ public class Player extends User implements ICrafting, Executor, IPlayer
msg += String.format("; Zwischenablage: %dx%dx%d (%d)", nx, ny, nz, nx * ny * nz);
}
if(this.edit == EditAction.SELECT && this.selectionDim != Integer.MIN_VALUE && (this.selPos1 != null || this.selPos2 != null)) {
msg += "; Bereich Level " + this.selectionDim + ": ";
msg += (this.selPos1 != null ? this.selPos1 : "*") + " -> " + (this.selPos2 != null ? this.selPos2 : "*");
if(this.selPos1 != null && this.selPos2 != null) {
msg += " = " + (1 + Math.max(this.selPos1.getX(), this.selPos2.getX()) - Math.min(this.selPos1.getX(), this.selPos2.getX())) +
"x" + (1 + Math.max(this.selPos1.getY(), this.selPos2.getY()) - Math.min(this.selPos1.getY(), this.selPos2.getY())) +
"x" + (1 + Math.max(this.selPos1.getZ(), this.selPos2.getZ()) - Math.min(this.selPos1.getZ(), this.selPos2.getZ())) + " (" + this.getSelectionArea() + ")";
}
Dimension dim = UniverseRegistry.getDimension(this.selectionDim);
if(dim != null) {
msg += "; Bereich " + dim.getFormattedName(false) + ": ";
msg += (this.selPos1 != null ? this.selPos1 : "*") + " -> " + (this.selPos2 != null ? this.selPos2 : "*");
if(this.selPos1 != null && this.selPos2 != null) {
msg += " = " + (1 + Math.max(this.selPos1.getX(), this.selPos2.getX()) - Math.min(this.selPos1.getX(), this.selPos2.getX())) +
"x" + (1 + Math.max(this.selPos1.getY(), this.selPos2.getY()) - Math.min(this.selPos1.getY(), this.selPos2.getY())) +
"x" + (1 + Math.max(this.selPos1.getZ(), this.selPos2.getZ()) - Math.min(this.selPos1.getZ(), this.selPos2.getZ())) + " (" + this.getSelectionArea() + ")";
}
}
}
if(this.edit == EditAction.TRANSFORM && (this.rotation != 0 || this.flipX || this.flipZ))
msg += "; " + this.getRotationInfo();
@ -1487,7 +1490,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer
}
private boolean copyClipboard() {
if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != this.entity.worldObj.dimension.getDimensionId() ||
if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != UniverseRegistry.getId(this.entity.worldObj.dimension) ||
this.selPos1 == null || this.selPos2 == null)
return false;
WorldServer source = this.getEntityWorld();
@ -1591,7 +1594,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer
if(info != null && info.isEmpty())
info = null;
Alignment align = Alignment.getByName(tag.getString("Align"));
Dimension dimension = UniverseRegistry.getDimension(tag.getInt("Dimension"));
Dimension dimension = UniverseRegistry.getDimension(tag.getString("Dimension"));
String dim = dimension == null ? "???" : dimension.getFormattedName(false);
BlockPos pos = new BlockPos(tag.getDouble("PosX"), tag.getDouble("PosY"), tag.getDouble("PosZ"));
String type = EntityRegistry.getEntityName(tag.getString("id"));
@ -2452,10 +2455,9 @@ public class Player extends User implements ICrafting, Executor, IPlayer
this.charEditor = false;
this.selected = this.characters.size();
this.characters.add(new TagObject());
WorldServer world = this.server.getWorld(packetIn.getAuxData());
WorldServer world = this.server.getWorld(UniverseRegistry.getDimension(packetIn.getAuxData()));
world = world == null ? this.server.getSpace() : world;
WorldPos origin = new WorldPos(world.rand.range(-SVars.originRadius, SVars.originRadius), 64, world.rand.range(-SVars.originRadius, SVars.originRadius),
world.dimension.getDimensionId());
WorldPos origin = new WorldPos(world.rand.range(-SVars.originRadius, SVars.originRadius), 64, world.rand.range(-SVars.originRadius, SVars.originRadius), world);
this.entity.setOrigin(origin);
Position pos = this.server.getRandomSpawnPosition(origin);
this.entity.teleport(pos);
@ -2757,7 +2759,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer
});
for(Entity entity : list) {
entity.teleport(this.entity.posX, this.entity.posY, this.entity.posZ,
this.entity.rotYaw, this.entity.rotPitch, this.entity.worldObj.dimension.getDimensionId());
this.entity.rotYaw, this.entity.rotPitch, this.entity.worldObj);
}
}
break;
@ -3065,11 +3067,11 @@ public class Player extends User implements ICrafting, Executor, IPlayer
}
public Position getLastTeleport() {
return this.teleportPos;
return this.teleportPos != null && this.teleportPos.isValid() ? this.teleportPos : null;
}
public Position getLastDeath() {
return this.deathPos;
return this.deathPos != null && this.deathPos.isValid() ? this.deathPos : null;
}
public String getEntityName() {

View file

@ -10,14 +10,12 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.zip.GZIPInputStream;
import java.util.zip.InflaterInputStream;
import common.biome.Biome;
import common.block.Block;
import common.block.artificial.BlockBed;
import common.block.artificial.BlockBed.EnumPartType;
@ -1837,9 +1835,6 @@ public abstract class Converter {
}
}
ntag.setList("Sections", sections);
byte[] biomes = new byte[256];
Arrays.fill(biomes, (byte)(Biome.DEF_BIOME.id & 255));
ntag.setByteArray("Biomes", biomes);
}
else {
ntag.setIntArray("HeightMap", tag.getIntArray("HeightMap"));

View file

@ -183,6 +183,32 @@ public final class WorldServer extends AWorldServer {
public static float clampGravity() {
return ExtMath.clampf(SVars.gravity, -10.0f, 10.0f);
}
public void sendPacket(Packet packet) {
for(Player conn : this.server.getPlayers()) {
if(conn.getEntity() != null && conn.getEntity().worldObj == this) {
conn.sendPacket(packet);
}
}
}
public void sendNear(double x, double y, double z, double radius, Packet packet) {
this.sendNearExcept(null, x, y, z, radius, packet);
}
public void sendNearExcept(EntityNPC except, double x, double y, double z, double radius, Packet packet) {
for(Player conn : this.server.getPlayers()) {
EntityNPC player = conn.getEntity();
if(player != null && player != except && player.worldObj == this) {
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);
}
}
}
}
private BiomeGenerator createBiomeGenerator(Random rand) {
return this.dimension.getBiomeSize() > 0 ? new BiomeGenLayered(rand.longv(), this.dimension.getDefaultBiome(), this.dimension.isSemiFixed(), this.dimension.getBiomeSize(), this.dimension.getRiverSize(),
@ -289,10 +315,10 @@ public final class WorldServer extends AWorldServer {
// this.time = time;
this.daytime = dtime;
this.updateViewRadius();
this.chunkDir = new File(new File("chunk"), dim.getDimensionName());
this.chunkDir = new File(new File("chunk"), UniverseRegistry.getName(dim));
this.chunkDir.mkdirs();
if(!SVars.seed.isEmpty())
this.rand.setSeed((long)SVars.seed.hashCode() ^ ~((long)dim.getDimensionName().hashCode()));
this.rand.setSeed((long)SVars.seed.hashCode() ^ ~((long)UniverseRegistry.getName(dim).hashCode()));
this.seed = this.rand.longv();
this.dimension.setSeed(this.seed);
TagObject tag = null;
@ -308,7 +334,7 @@ public final class WorldServer extends AWorldServer {
this.exterminated = tag.getBool("Exterminated");
this.time = tag.getLong("Time");
if(tag.hasObject("Generator")) {
this.dimension.fromTags(tag.getObject("Generator"));
this.dimension.readGenerator(tag.getObject("Generator"));
if(this.dimension.getType().weather && !this.exterminated)
this.weather = this.dimension.getWeather();
this.seed = this.dimension.getSeed();
@ -871,7 +897,7 @@ public final class WorldServer extends AWorldServer {
public static boolean needsLoading(Dimension dim) {
TagObject tag = null;
try {
File dat = new File(new File(new File("chunk"), dim.getDimensionName()), "loaders.cdt");
File dat = new File(new File(new File("chunk"), UniverseRegistry.getName(dim)), "loaders.cdt");
if(dat.exists() && dat.isFile())
tag = TagObject.readGZip(dat);
}
@ -884,7 +910,7 @@ public final class WorldServer extends AWorldServer {
public static void loadWarps(Dimension dim, Map<String, Position> warps) {
TagObject tag = null;
try {
File dat = new File(new File(new File("chunk"), dim.getDimensionName()), "warps.cdt");
File dat = new File(new File(new File("chunk"), UniverseRegistry.getName(dim)), "warps.cdt");
if(dat.exists() && dat.isFile())
tag = TagObject.readGZip(dat);
}
@ -897,7 +923,7 @@ public final class WorldServer extends AWorldServer {
for(int z = 0; z < list.size(); z++) {
TagObject pos = list.get(z);
warps.put(pos.getString("Name"), new Position(pos.getDouble("X"), pos.getDouble("Y"), pos.getDouble("Z"),
pos.getFloat("Yaw"), pos.getFloat("Pitch"), dim.getDimensionId()));
pos.getFloat("Yaw"), pos.getFloat("Pitch"), dim));
}
}
}
@ -905,11 +931,12 @@ public final class WorldServer extends AWorldServer {
public static void saveWarps(Map<String, Position> warps) {
Map<Integer, List<TagObject>> map = Maps.newHashMap();
for(Entry<String, Position> pos : warps.entrySet()) {
Dimension dim = UniverseRegistry.getDimension(pos.getValue().dim());
Dimension dim = pos.getValue().getDimension();
if(dim != null) {
List<TagObject> list = map.get(pos.getValue().dim());
int id = UniverseRegistry.getId(dim);
List<TagObject> list = map.get(id);
if(list == null)
map.put(pos.getValue().dim(), list = Lists.newArrayList());
map.put(id, list = Lists.newArrayList());
TagObject warp = new TagObject();
warp.setString("Name", pos.getKey());
warp.setDouble("X", pos.getValue().x());
@ -921,8 +948,8 @@ public final class WorldServer extends AWorldServer {
}
}
for(Dimension dim : UniverseRegistry.getDimensions()) {
List<TagObject> list = map.get(dim.getDimensionId());
File file = new File(new File(new File("chunk"), dim.getDimensionName()), "warps.cdt");
List<TagObject> list = map.get(UniverseRegistry.getId(dim));
File file = new File(new File(new File("chunk"), UniverseRegistry.getName(dim)), "warps.cdt");
if(list == null) {
file.delete();
}
@ -1000,7 +1027,7 @@ public final class WorldServer extends AWorldServer {
// this.dataModified = false;
TagObject data = new TagObject();
// data.setLong("Seed", this.seed);
data.setObject("Generator", this.dimension.toTags(true));
data.setObject("Generator", this.dimension.writeGenerator());
data.setLong("Time", this.time);
data.setBool("Exterminated", this.exterminated);
data.setString("Weather", this.weather.getName());
@ -1072,7 +1099,7 @@ public final class WorldServer extends AWorldServer {
public void strikeLightning(double x, double y, double z, int color, int damage, boolean fire, EntityLiving summoner) {
EntityLightning entity = new EntityLightning(this, x, y, z, color, damage, fire, summoner);
this.effects.add(entity);
this.server.sendNear(entity.posX, entity.posY, entity.posZ, 512.0D, this.dimension.getDimensionId(),
this.sendNear(entity.posX, entity.posY, entity.posZ, 512.0D,
new SPacketSpawnGlobalEntity(entity, 1, entity.color));
if(fire && SVars.fire) {
BlockPos pos = new BlockPos(entity);
@ -1130,8 +1157,8 @@ public final class WorldServer extends AWorldServer {
for(TickEvent blockeventdata : this.queue[i]) {
if(this.fireBlockEvent(blockeventdata)) {
this.server.sendNear((double)blockeventdata.position().getX(), (double)blockeventdata.position().getY(),
(double)blockeventdata.position().getZ(), 64.0D, this.dimension.getDimensionId(),
this.sendNear((double)blockeventdata.position().getX(), (double)blockeventdata.position().getY(),
(double)blockeventdata.position().getZ(), 64.0D,
new SPacketBlockAction(blockeventdata.position(), blockeventdata.block(), blockeventdata.id(),
blockeventdata.parameter()));
}
@ -1156,8 +1183,8 @@ public final class WorldServer extends AWorldServer {
public void setWeather(Weather weather) {
this.weather = weather;
// this.dataModified = true;
this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.SET_WEATHER,
weather.getID()), this.dimension.getDimensionId());
this.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.SET_WEATHER,
weather.getID()));
}
protected void updateWeather(boolean force) {
@ -1228,15 +1255,15 @@ public final class WorldServer extends AWorldServer {
}
if(prevRain != this.rain || force) {
this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.RAIN_STRENGTH, this.rain), this.dimension.getDimensionId());
this.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.RAIN_STRENGTH, this.rain));
}
if(prevDarkness != this.darkness || force) {
this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.DARKNESS, this.darkness), this.dimension.getDimensionId());
this.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.DARKNESS, this.darkness));
}
if(prevFog != this.fog || force) {
this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.FOG_STRENGTH, this.fog), this.dimension.getDimensionId());
this.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.FOG_STRENGTH, this.fog));
}
}
@ -1252,7 +1279,7 @@ public final class WorldServer extends AWorldServer {
}
if(prevTemp != this.temp || force) {
this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.TEMPERATURE, this.temp), this.dimension.getDimensionId());
this.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.TEMPERATURE, this.temp));
}
}
@ -1612,7 +1639,7 @@ public final class WorldServer extends AWorldServer {
this.loaderList.clear();
for(Iterator<Entry<String, Position>> iter = this.server.getWarps().entrySet().iterator(); iter.hasNext();) {
Entry<String, Position> pos = iter.next();
if(pos.getValue().dim() == this.dimension.getDimensionId())
if(pos.getValue().getDimension() == this.dimension)
iter.remove();
}
Region.finishWrite();
@ -1752,7 +1779,7 @@ public final class WorldServer extends AWorldServer {
public void playSound(SoundEvent sound, double x, double y, double z, float volume)
{
this.server.sendNear(x, y, z, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, this.dimension.getDimensionId(), new SPacketSoundEffect(sound, x, y, z, volume));
this.sendNear(x, y, z, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, new SPacketSoundEffect(sound, x, y, z, volume));
}
public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2)
@ -1765,7 +1792,7 @@ public final class WorldServer extends AWorldServer {
public void playAuxSFX(EntityNPC player, int sfxType, BlockPos blockPosIn, int data)
{
this.server.sendNearExcept(player, (double)blockPosIn.getX(), (double)blockPosIn.getY(), (double)blockPosIn.getZ(), 64.0D, this.dimension.getDimensionId(), new SPacketEffect(sfxType, blockPosIn, data));
this.sendNearExcept(player, (double)blockPosIn.getX(), (double)blockPosIn.getY(), (double)blockPosIn.getZ(), 64.0D, new SPacketEffect(sfxType, blockPosIn, data));
}
// public void broadcastSound(int soundID, BlockPos pos, int data)
@ -2684,7 +2711,7 @@ public final class WorldServer extends AWorldServer {
this.server.placeInDimension(entity, (WorldServer)oldWorld, (WorldServer)world, pos, portal);
}
public AWorldServer getOtherWorld(int dimension) {
public AWorldServer getOtherWorld(Dimension dimension) {
return this.server.getWorld(dimension);
}