mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-08 16:32:07 +01:00
Load a single chunk on instance spawn
This commit is contained in:
parent
bebdcf59d5
commit
fceafb0b1e
@ -541,11 +541,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
if (dimensionChange) {
|
if (dimensionChange) {
|
||||||
sendDimension(instanceDimensionType);
|
sendDimension(instanceDimensionType);
|
||||||
}
|
}
|
||||||
|
return instance.loadOptionalChunk(spawnPosition)
|
||||||
// Only load the spawning chunk to speed up login, remaining chunks are loaded in #spawnPlayer
|
|
||||||
final long[] visibleChunks = ChunkUtils.getChunksInRange(spawnPosition, 0);
|
|
||||||
|
|
||||||
return ChunkUtils.optionalLoadAll(instance, visibleChunks, null)
|
|
||||||
.thenRun(() -> spawnPlayer(instance, spawnPosition, firstSpawn, dimensionChange, true));
|
.thenRun(() -> spawnPlayer(instance, spawnPosition, firstSpawn, dimensionChange, true));
|
||||||
} else {
|
} else {
|
||||||
// The player already has the good version of all the chunks.
|
// The player already has the good version of all the chunks.
|
||||||
@ -1493,7 +1489,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
public void refreshVisibleEntities(@NotNull Chunk newChunk) {
|
public void refreshVisibleEntities(@NotNull Chunk newChunk) {
|
||||||
final int entityViewDistance = MinecraftServer.getEntityViewDistance();
|
final int entityViewDistance = MinecraftServer.getEntityViewDistance();
|
||||||
final float maximalDistance = entityViewDistance * Chunk.CHUNK_SECTION_SIZE;
|
final float maximalDistance = entityViewDistance * Chunk.CHUNK_SECTION_SIZE;
|
||||||
|
|
||||||
// Manage already viewable entities
|
// Manage already viewable entities
|
||||||
this.viewableEntities.stream()
|
this.viewableEntities.stream()
|
||||||
.filter(entity -> entity.getDistance(this) > maximalDistance)
|
.filter(entity -> entity.getDistance(this) > maximalDistance)
|
||||||
@ -1506,18 +1501,15 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
removeViewer((Player) entity);
|
removeViewer((Player) entity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Manage entities in unchecked chunks
|
// Manage entities in unchecked chunks
|
||||||
EntityUtils.forEachRange(instance, newChunk.toPosition(), entityViewDistance, entity -> {
|
EntityUtils.forEachRange(instance, newChunk.toPosition(), entityViewDistance, entity -> {
|
||||||
if (entity.isAutoViewable() && !entity.viewers.contains(this)) {
|
if (entity.isAutoViewable() && !entity.viewers.contains(this)) {
|
||||||
entity.addViewer(this);
|
entity.addViewer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof Player && isAutoViewable() && !viewers.contains(entity)) {
|
if (entity instanceof Player && isAutoViewable() && !viewers.contains(entity)) {
|
||||||
addViewer((Player) entity);
|
addViewer((Player) entity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user