Fixed chunk being asked two times

This commit is contained in:
themode 2020-11-21 08:06:04 +01:00
parent 234ac6daf4
commit 500fc2e903
2 changed files with 9 additions and 4 deletions

View File

@ -698,7 +698,7 @@ 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) {
if (needWorldRefresh && !firstSpawn) {
// Remove all previous viewable chunks (from the previous instance)
for (Chunk viewableChunk : viewableChunks) {
viewableChunk.removeViewer(this);
@ -729,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, firstSpawn);
spawnPlayer(instance, false);
} else {
// Increment the counter of current loaded chunks
counter.incrementAndGet();
@ -739,8 +739,13 @@ 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) {
// 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 {
spawnPlayer(instance, firstSpawn);
// The player already has the good version of all the chunks.
// We just need to refresh his entity viewing list and add him to the instance
spawnPlayer(instance, false);
}
}

View File

@ -72,7 +72,7 @@ public class TemporaryCache<T> {
}
/**
* Gets the time an object will be kept without being retrieved
* Gets the time an object will be kept without being retrieved.
*
* @return the keep time in milliseconds
*/