Port CB changes from Moonrise patch
This commit is contained in:
@@ -83,6 +83,12 @@ public class CraftChunk implements Chunk {
|
||||
}
|
||||
|
||||
public ChunkAccess getHandle(ChunkStatus chunkStatus) {
|
||||
// Paper start - chunk system
|
||||
net.minecraft.world.level.chunk.LevelChunk full = this.worldServer.getChunkIfLoaded(this.x, this.z);
|
||||
if (full != null) {
|
||||
return full;
|
||||
}
|
||||
// Paper end - chunk system
|
||||
ChunkAccess chunkAccess = this.worldServer.getChunk(this.x, this.z, chunkStatus);
|
||||
|
||||
// SPIGOT-7332: Get unwrapped extension
|
||||
@@ -117,60 +123,12 @@ public class CraftChunk implements Chunk {
|
||||
|
||||
@Override
|
||||
public boolean isEntitiesLoaded() {
|
||||
return this.getCraftWorld().getHandle().entityManager.areEntitiesLoaded(ChunkPos.asLong(this.x, this.z));
|
||||
return this.getCraftWorld().getHandle().areEntitiesLoaded(ChunkPos.asLong(this.x, this.z)); // Paper - chunk system
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity[] getEntities() {
|
||||
if (!this.isLoaded()) {
|
||||
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
|
||||
}
|
||||
|
||||
PersistentEntitySectionManager<net.minecraft.world.entity.Entity> entityManager = this.getCraftWorld().getHandle().entityManager;
|
||||
long pair = ChunkPos.asLong(this.x, this.z);
|
||||
|
||||
if (entityManager.areEntitiesLoaded(pair)) {
|
||||
return entityManager.getEntities(new ChunkPos(this.x, this.z)).stream()
|
||||
.map(net.minecraft.world.entity.Entity::getBukkitEntity)
|
||||
.filter(Objects::nonNull).toArray(Entity[]::new);
|
||||
}
|
||||
|
||||
entityManager.ensureChunkQueuedForLoad(pair); // Start entity loading
|
||||
|
||||
// SPIGOT-6772: Use entity mailbox and re-schedule entities if they get unloaded
|
||||
ConsecutiveExecutor mailbox = ((EntityStorage) entityManager.permanentStorage).entityDeserializerQueue;
|
||||
BooleanSupplier supplier = () -> {
|
||||
// only execute inbox if our entities are not present
|
||||
if (entityManager.areEntitiesLoaded(pair)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!entityManager.isPending(pair)) {
|
||||
// Our entities got unloaded, this should normally not happen.
|
||||
entityManager.ensureChunkQueuedForLoad(pair); // Re-start entity loading
|
||||
}
|
||||
|
||||
// tick loading inbox, which loads the created entities to the world
|
||||
// (if present)
|
||||
entityManager.tick();
|
||||
// check if our entities are loaded
|
||||
return entityManager.areEntitiesLoaded(pair);
|
||||
};
|
||||
|
||||
// now we wait until the entities are loaded,
|
||||
// the converting from NBT to entity object is done on the main Thread which is why we wait
|
||||
while (!supplier.getAsBoolean()) {
|
||||
if (mailbox.size() != 0) {
|
||||
mailbox.run();
|
||||
} else {
|
||||
Thread.yield();
|
||||
LockSupport.parkNanos("waiting for entity loading", 100000L);
|
||||
}
|
||||
}
|
||||
|
||||
return entityManager.getEntities(new ChunkPos(this.x, this.z)).stream()
|
||||
.map(net.minecraft.world.entity.Entity::getBukkitEntity)
|
||||
.filter(Objects::nonNull).toArray(Entity[]::new);
|
||||
return FeatureHooks.getChunkEntities(this.worldServer, this.x, this.z); // Paper - chunk system
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user