Re-add legacy getChunkAtAsynchronously to ChunkProviderServer
Apparently some plugins use it
This commit is contained in:
parent
e8c2c3bfda
commit
09904fd780
19 changed files with 159 additions and 157 deletions
|
@ -5914,7 +5914,7 @@ index 6c98676827ceb6999f340fa2b06a0b3e1cb4cae2..f08089b8672454acf8c2309e850466b3
|
|||
|
||||
while (objectiterator.hasNext()) {
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
index ce88976db29b9e9524dbe45b16721ef90afb692b..96323a83d917516edf4b6951d1e881d2f5513bd0 100644
|
||||
index ce88976db29b9e9524dbe45b16721ef90afb692b..1a8c5ce3ecce9cbbc8496ea3882b18c297964e33 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -50,6 +50,7 @@ import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
|
@ -5925,7 +5925,7 @@ index ce88976db29b9e9524dbe45b16721ef90afb692b..96323a83d917516edf4b6951d1e881d2
|
|||
public static final List<ChunkStatus> CHUNK_STATUSES = ChunkStatus.getStatusList();
|
||||
private final DistanceManager distanceManager;
|
||||
final ServerLevel level;
|
||||
@@ -68,6 +69,151 @@ public class ServerChunkCache extends ChunkSource {
|
||||
@@ -68,6 +69,231 @@ public class ServerChunkCache extends ChunkSource {
|
||||
@Nullable
|
||||
@VisibleForDebug
|
||||
private NaturalSpawner.SpawnState lastSpawnState;
|
||||
|
@ -6022,6 +6022,86 @@ index ce88976db29b9e9524dbe45b16721ef90afb692b..96323a83d917516edf4b6951d1e881d2
|
|||
+ ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.NORMAL, onLoad
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ void chunkLoadAccept(int chunkX, int chunkZ, ChunkAccess chunk, java.util.function.Consumer<ChunkAccess> consumer) {
|
||||
+ try {
|
||||
+ consumer.accept(chunk);
|
||||
+ } catch (Throwable throwable) {
|
||||
+ if (throwable instanceof ThreadDeath) {
|
||||
+ throw (ThreadDeath)throwable;
|
||||
+ }
|
||||
+ LOGGER.error("Load callback for chunk " + chunkX + "," + chunkZ + " in world '" + this.level.getWorld().getName() + "' threw an exception", throwable);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ void getChunkAtAsynchronously(int chunkX, int chunkZ, int ticketLevel,
|
||||
+ java.util.function.Consumer<ChunkAccess> consumer) {
|
||||
+ if (ticketLevel <= 33) {
|
||||
+ this.getFullChunkAsync(chunkX, chunkZ, (java.util.function.Consumer)consumer);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ net.minecraft.server.ChunkSystem.scheduleChunkLoad(
|
||||
+ this.level, chunkX, chunkZ, ChunkHolder.getStatus(ticketLevel), true,
|
||||
+ ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.NORMAL, consumer
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ public final void getChunkAtAsynchronously(int chunkX, int chunkZ, ChunkStatus status, boolean gen, boolean allowSubTicketLevel, java.util.function.Consumer<ChunkAccess> onLoad) {
|
||||
+ // try to fire sync
|
||||
+ int chunkStatusTicketLevel = 33 + ChunkStatus.getDistance(status);
|
||||
+ ChunkHolder playerChunk = this.chunkMap.getUpdatingChunkIfPresent(io.papermc.paper.util.CoordinateUtils.getChunkKey(chunkX, chunkZ));
|
||||
+ if (playerChunk != null) {
|
||||
+ ChunkStatus holderStatus = playerChunk.getChunkHolderStatus();
|
||||
+ ChunkAccess immediate = playerChunk.getAvailableChunkNow();
|
||||
+ if (immediate != null) {
|
||||
+ if (allowSubTicketLevel ? immediate.getStatus().isOrAfter(status) : (playerChunk.getTicketLevel() <= chunkStatusTicketLevel && holderStatus != null && holderStatus.isOrAfter(status))) {
|
||||
+ this.chunkLoadAccept(chunkX, chunkZ, immediate, onLoad);
|
||||
+ return;
|
||||
+ } else {
|
||||
+ if (gen || (!allowSubTicketLevel && immediate.getStatus().isOrAfter(status))) {
|
||||
+ this.getChunkAtAsynchronously(chunkX, chunkZ, chunkStatusTicketLevel, onLoad);
|
||||
+ return;
|
||||
+ } else {
|
||||
+ this.chunkLoadAccept(chunkX, chunkZ, null, onLoad);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // need to fire async
|
||||
+
|
||||
+ if (gen && !allowSubTicketLevel) {
|
||||
+ this.getChunkAtAsynchronously(chunkX, chunkZ, chunkStatusTicketLevel, onLoad);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ this.getChunkAtAsynchronously(chunkX, chunkZ, net.minecraft.server.MCUtil.getTicketLevelFor(ChunkStatus.EMPTY), (ChunkAccess chunk) -> {
|
||||
+ if (chunk == null) {
|
||||
+ throw new IllegalStateException("Chunk cannot be null");
|
||||
+ }
|
||||
+
|
||||
+ if (!chunk.getStatus().isOrAfter(status)) {
|
||||
+ if (gen) {
|
||||
+ this.getChunkAtAsynchronously(chunkX, chunkZ, chunkStatusTicketLevel, onLoad);
|
||||
+ return;
|
||||
+ } else {
|
||||
+ ServerChunkCache.this.chunkLoadAccept(chunkX, chunkZ, null, onLoad);
|
||||
+ return;
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (allowSubTicketLevel) {
|
||||
+ ServerChunkCache.this.chunkLoadAccept(chunkX, chunkZ, chunk, onLoad);
|
||||
+ return;
|
||||
+ } else {
|
||||
+ this.getChunkAtAsynchronously(chunkX, chunkZ, chunkStatusTicketLevel, onLoad);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ });
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
+ // Paper start
|
||||
|
@ -6077,7 +6157,7 @@ index ce88976db29b9e9524dbe45b16721ef90afb692b..96323a83d917516edf4b6951d1e881d2
|
|||
|
||||
public ServerChunkCache(ServerLevel world, LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, StructureTemplateManager structureTemplateManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int viewDistance, int simulationDistance, boolean dsync, ChunkProgressListener worldGenerationProgressListener, ChunkStatusUpdateListener chunkStatusChangeListener, Supplier<DimensionDataStorage> persistentStateManagerFactory) {
|
||||
this.level = world;
|
||||
@@ -120,6 +266,49 @@ public class ServerChunkCache extends ChunkSource {
|
||||
@@ -120,6 +346,49 @@ public class ServerChunkCache extends ChunkSource {
|
||||
this.lastChunk[0] = chunk;
|
||||
}
|
||||
|
||||
|
@ -6127,7 +6207,7 @@ index ce88976db29b9e9524dbe45b16721ef90afb692b..96323a83d917516edf4b6951d1e881d2
|
|||
@Nullable
|
||||
@Override
|
||||
public ChunkAccess getChunk(int x, int z, ChunkStatus leastStatus, boolean create) {
|
||||
@@ -327,6 +516,12 @@ public class ServerChunkCache extends ChunkSource {
|
||||
@@ -327,6 +596,12 @@ public class ServerChunkCache extends ChunkSource {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue