char origins

This commit is contained in:
Sen 2025-03-28 14:30:37 +01:00
parent 3316c42ed8
commit e9ede99d84
14 changed files with 516 additions and 373 deletions

View file

@ -354,16 +354,16 @@ public final class Server implements Runnable, IThreadListener {
}
}
private void preload(Entity entity) {
public void preload(WorldServer world, int bx, int bz) {
int done = 0;
int total = Config.distance * 2 + 1;
total *= total;
this.setMessage("Landschaft wird generiert");
this.startProgress(false, total);
WorldServer world = this.getWorld(Config.spawnDim);
world = world == null ? this.space : world;
int bx = (int)entity.posX >> 4;
int bz = (int)entity.posZ >> 4;
// WorldServer world = this.getWorld(Config.spawnDim);
// world = world == null ? this.space : world;
bx = bx >> 4;
bz = bz >> 4;
long last = System.currentTimeMillis();
for(int x = -Config.distance; x <= Config.distance && this.running; x++) {
for(int z = -Config.distance; z <= Config.distance && this.running; z++) {
@ -381,6 +381,14 @@ public final class Server implements Runnable, IThreadListener {
}
this.setProgress(-1);
}
// public void resetProgress() {
// this.setProgress(-1);
// }
//
// public void setDone() {
// this.setProgress(-2);
// }
private void tick() {
// boolean pause = this.paused;
@ -614,26 +622,26 @@ public final class Server implements Runnable, IThreadListener {
return Thread.currentThread() == this.serverThread;
}
private void movePlayerToSpawn(EntityNPC player) {
BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ);
int radius = Config.spawnRadius;
if(radius > 0) {
pos = ((WorldServer)player.worldObj).getTopSolidOrLiquidBlock(pos.add(
ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0,
ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1)));
}
player.moveToBlockPosAndAngles(pos, radius > 0 ? (-180.0f + player.worldObj.rand.floatv() * 360.0f) : Config.spawnYaw,
radius > 0 ? 0.0f : Config.spawnPitch);
while(radius >= 0 && !player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox()).isEmpty()
&& player.posY < 511.0D) {
player.setPosition(player.posX, player.posY + 1.0D, player.posZ);
}
}
// private void movePlayerToSpawn(EntityNPC player) {
// BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ);
// int radius = Config.spawnRadius;
// if(radius > 0) {
// pos = ((WorldServer)player.worldObj).getTopSolidOrLiquidBlock(pos.add(
// ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0,
// ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1)));
// }
// player.moveToBlockPosAndAngles(pos, radius > 0 ? (-180.0f + player.worldObj.rand.floatv() * 360.0f) : Config.spawnYaw,
// radius > 0 ? 0.0f : Config.spawnPitch);
// while(radius >= 0 && !player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox()).isEmpty()
// && player.posY < 511.0D) {
// player.setPosition(player.posX, player.posY + 1.0D, player.posZ);
// }
// }
public Position getRandomSpawnPosition() {
WorldServer world = this.getWorld(Config.spawnDim);
public Position getRandomSpawnPosition(WorldPos origin) {
WorldServer world = this.getWorld(origin.getDimension());
world = world == null ? this.space : world;
BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ);
BlockPos pos = origin;
int radius = Config.spawnRadius;
if(radius > 0) {
pos = world.getTopSolidOrLiquidBlock(pos.add(
@ -703,8 +711,8 @@ public final class Server implements Runnable, IThreadListener {
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": "
+ String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? " (Charakter-Editor)" : "'" + player.getCommandName() + "'") + ")");
if(Config.preloadAll || (Config.preloadLocal && conn.isLocal()))
this.preload(player);
if(Config.preloadLocal && conn.isLocal() && this.players.size() == 1)
this.preload(world, (int)player.posX, (int)player.posZ);
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
@ -807,6 +815,7 @@ public final class Server implements Runnable, IThreadListener {
old.getServerWorld().removePlayer(old);
old.getServerWorld().removePlayerEntityDangerously(old);
WorldPos bed = old.getSpawnPoint();
WorldPos origin = old.getOrigin();
BlockPos spawn = null;
String message = null;
WorldServer world = bed == null ? this.space : this.getWorld(bed.getDimension());
@ -824,19 +833,22 @@ public final class Server implements Runnable, IThreadListener {
}
}
if(bed == null) {
world = this.getWorld(Config.spawnDim);
world = this.getWorld(origin.getDimension());
world = world == null ? this.space : world;
}
EntityNPC nplayer = conn.createPlayer(world, EntityRegistry.getEntityString(old));
conn.clonePlayer(old);
nplayer.setId(old.getId());
nplayer.setOrigin(origin);
if(bed != null) {
nplayer.setLocationAndAngles((double)((float)spawn.getX() + 0.5F), (double)((float)spawn.getY() + 0.1F),
(double)((float)spawn.getZ() + 0.5F), 0.0F, 0.0F);
nplayer.setSpawnPoint(bed);
}
else {
this.movePlayerToSpawn(nplayer);
Position rpos = this.getRandomSpawnPosition(origin);
nplayer.setLocationAndAngles(rpos.x, rpos.y, rpos.z, rpos.yaw, rpos.pitch);
// this.movePlayerToSpawn(nplayer);
}
world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
if(bed != null ? Config.checkBed : Config.spawnRadius >= 0) {
@ -1027,7 +1039,7 @@ public final class Server implements Runnable, IThreadListener {
if(this.endpoint != null)
this.unsetLanEndpoint();
// throw new IllegalStateException("Eingangspunkt bereits gesetzt");
Log.JNI.info("Öffne Port " + port + " auf 0.0.0.0");
Log.JNI.info("Öffne Port %d auf 0.0.0.0 (Timeout %ds)", port, Config.timeout);
this.endpoint = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(NioServerSocketChannel.class)).childHandler(new ChannelInitializer<Channel>() {
protected void initChannel(Channel channel) throws Exception {
try {
@ -1035,7 +1047,7 @@ public final class Server implements Runnable, IThreadListener {
}
catch(ChannelException e) {
}
channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30)))
channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(Config.timeout)))
.addLast((String)"splitter", (ChannelHandler)(new PacketSplitter()))
.addLast((String)"decoder", (ChannelHandler)(new PacketDecoder(true)))
.addLast((String)"prepender", (ChannelHandler)(new PacketPrepender()))