Fixed player spawn when a respawn point is not specified

This commit is contained in:
themode 2020-11-21 20:56:32 +01:00
parent ab98c11de3
commit 48b637cbc8
2 changed files with 13 additions and 8 deletions

View File

@ -698,7 +698,12 @@ public class Player extends LivingEntity implements CommandSender {
// true if the chunks need to be sent to the client, can be false if the instances share the same chunks (eg SharedInstance)
final boolean needWorldRefresh = !InstanceUtils.areLinked(this.instance, instance);
if (needWorldRefresh && !firstSpawn) {
// true if the player needs every chunk around its position
final boolean needChunkLoad = !firstSpawn || firstSpawn &&
ChunkUtils.getChunkCoordinate((int) getRespawnPoint().getX()) == 0 &&
ChunkUtils.getChunkCoordinate((int) getRespawnPoint().getZ()) == 0;
if (needWorldRefresh && needChunkLoad) {
// Remove all previous viewable chunks (from the previous instance)
for (Chunk viewableChunk : viewableChunks) {
viewableChunk.removeViewer(this);
@ -729,7 +734,7 @@ public class Player extends LivingEntity implements CommandSender {
final boolean isLast = counter.get() == length - 1;
if (isLast) {
// This is the last chunk to be loaded , spawn player
spawnPlayer(instance, false);
spawnPlayer(instance, firstSpawn);
} else {
// Increment the counter of current loaded chunks
counter.incrementAndGet();
@ -739,7 +744,7 @@ public class Player extends LivingEntity implements CommandSender {
// WARNING: if auto load is disabled and no chunks are loaded beforehand, player will be stuck.
instance.loadOptionalChunk(chunkX, chunkZ, callback);
}
} else if (firstSpawn) {
} else if (!needChunkLoad) {
// The player always believe that his position is 0;0 so this is a pretty hacky fix
instance.loadOptionalChunk(0, 0, chunk -> spawnPlayer(instance, true));
} else {

View File

@ -29,14 +29,14 @@ public class MainDemo {
// Add event listeners
ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
connectionManager.addPlayerInitialization(player -> {
// Set the spawning instance
// Set the spawning instance and spawn position
player.addEventCallback(PlayerLoginEvent.class, event -> {
event.setSpawningInstance(instanceContainer);
player.setRespawnPoint(new Position(0, 45, 0));
player.setRespawnPoint(new Position(0, 42, 0));
});
});
// Start the server
// Start the server on port 25565
minecraftServer.start("localhost", 25565);
}
@ -55,7 +55,7 @@ public class MainDemo {
@Override
public void fillBiomes(Biome[] biomes, int chunkX, int chunkZ) {
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
Arrays.fill(biomes, Biome.PLAINS);
}
@Override
@ -64,4 +64,4 @@ public class MainDemo {
}
}
}
}