This commit is contained in:
Eoghanmc22 2020-11-21 14:59:17 -05:00
commit 04fc38a14f
2 changed files with 13 additions and 8 deletions

View File

@ -693,7 +693,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);
@ -724,7 +729,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();
@ -734,7 +739,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 {
}
}
}
}