Make it compile

This commit is contained in:
Nassim Jahnke
2024-06-14 18:02:15 +02:00
parent 492de57f77
commit 201427a880
4 changed files with 101 additions and 20 deletions

View File

@@ -2671,11 +2671,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor;
+import com.destroystokyo.paper.util.SneakyThrow;
+import com.mojang.datafixers.util.Either;
+import com.mojang.logging.LogUtils;
+import io.papermc.paper.util.CoordinateUtils;
+import net.minecraft.server.level.ChunkHolder;
+import net.minecraft.server.level.ChunkMap;
+import net.minecraft.server.level.ChunkResult;
+import net.minecraft.server.level.FullChunkStatus;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
@@ -2683,8 +2683,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.level.ChunkPos;
+import net.minecraft.world.level.chunk.ChunkAccess;
+import net.minecraft.world.level.chunk.status.ChunkPyramid;
+import net.minecraft.world.level.chunk.status.ChunkStatus;
+import net.minecraft.world.level.chunk.LevelChunk;
+import net.minecraft.world.level.chunk.status.ChunkStep;
+import org.bukkit.Bukkit;
+import org.slf4j.Logger;
+import java.util.ArrayList;
@@ -2695,6 +2697,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+public final class ChunkSystem {
+
+ private static final Logger LOGGER = LogUtils.getLogger();
+ private static final ChunkStep FULL_CHUNK_STEP = ChunkPyramid.GENERATION_PYRAMID.getStepTo(ChunkStatus.FULL);
+
+ public static int getDistance(final ChunkStatus status) {
+ return FULL_CHUNK_STEP.getAccumulatedRadiusOf(status);
+ }
+
+ public static void scheduleChunkTask(final ServerLevel level, final int chunkX, final int chunkZ, final Runnable run) {
+ scheduleChunkTask(level, chunkX, chunkZ, run, PrioritisedExecutor.Priority.NORMAL);
@@ -2715,7 +2722,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ if (chunk == null) {
+ onComplete.accept(null);
+ } else {
+ if (chunk.getStatus().isOrAfter(toStatus)) {
+ if (chunk.getPersistedStatus().isOrAfter(toStatus)) {
+ scheduleChunkLoad(level, chunkX, chunkZ, toStatus, addTicket, priority, onComplete);
+ } else {
+ onComplete.accept(null);
@@ -2736,7 +2743,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return;
+ }
+
+ final int minLevel = 33 + ChunkStatus.getDistance(toStatus);
+ final int minLevel = 33 + ChunkSystem.getDistance(toStatus);
+ final Long chunkReference = addTicket ? Long.valueOf(++chunkLoadCounter) : null;
+ final ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ);
+
@@ -2770,19 +2777,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return;
+ }
+
+ final CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> loadFuture = holder.getOrScheduleFuture(toStatus, level.chunkSource.chunkMap);
+ final CompletableFuture<ChunkResult<ChunkAccess>> loadFuture = holder.scheduleChunkGenerationTask(toStatus, level.chunkSource.chunkMap);
+
+ if (loadFuture.isDone()) {
+ loadCallback.accept(loadFuture.join().left().orElse(null));
+ loadCallback.accept(loadFuture.join().orElse(null));
+ return;
+ }
+
+ loadFuture.whenCompleteAsync((final Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either, final Throwable thr) -> {
+ loadFuture.whenCompleteAsync((final ChunkResult<ChunkAccess> result, final Throwable thr) -> {
+ if (thr != null) {
+ loadCallback.accept(null);
+ return;
+ }
+ loadCallback.accept(either.left().orElse(null));
+ loadCallback.accept(result.orElse(null));
+ }, (final Runnable r) -> {
+ scheduleChunkTask(level, chunkX, chunkZ, r, PrioritisedExecutor.Priority.HIGHEST);
+ });
@@ -2838,7 +2845,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return;
+ }
+
+ final CompletableFuture<Either<LevelChunk, ChunkHolder.ChunkLoadingFailure>> tickingState;
+ final CompletableFuture<ChunkResult<LevelChunk>> tickingState;
+ switch (toStatus) {
+ case FULL: {
+ tickingState = holder.getFullChunkFuture();
@@ -2858,16 +2865,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ if (tickingState.isDone()) {
+ loadCallback.accept(tickingState.join().left().orElse(null));
+ loadCallback.accept(tickingState.join().orElse(null));
+ return;
+ }
+
+ tickingState.whenCompleteAsync((final Either<LevelChunk, ChunkHolder.ChunkLoadingFailure> either, final Throwable thr) -> {
+ tickingState.whenCompleteAsync((final ChunkResult<LevelChunk> result, final Throwable thr) -> {
+ if (thr != null) {
+ loadCallback.accept(null);
+ return;
+ }
+ loadCallback.accept(either.left().orElse(null));
+ loadCallback.accept(result.orElse(null));
+ }, (final Runnable r) -> {
+ scheduleChunkTask(level, chunkX, chunkZ, r, PrioritisedExecutor.Priority.HIGHEST);
+ });
@@ -4014,7 +4021,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ public static int getTicketLevelFor(net.minecraft.world.level.chunk.status.ChunkStatus status) {
+ return net.minecraft.server.level.ChunkMap.MAX_VIEW_DISTANCE + net.minecraft.world.level.chunk.status.ChunkStatus.getDistance(status);
+ return net.minecraft.server.level.ChunkMap.MAX_VIEW_DISTANCE + io.papermc.paper.chunk.system.ChunkSystem.getDistance(status);
+ }
+
+ @NotNull
@@ -6171,12 +6178,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public @Nullable ChunkAccess getAvailableChunkNow() {
+ // TODO can we just getStatusFuture(EMPTY)?
+ for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getParent(); curr != next; curr = next, next = next.getParent()) {
+ CompletableFuture<ChunkResult<ChunkAccess>> future = this.getFutureIfPresentUnchecked(curr);
+ ChunkResult<ChunkAccess> either = future.getNow(null);
+ if (either == null || either.isSuccess()) {
+ ChunkAccess chunkAccess = this.getChunkIfPresentUnchecked(curr);
+ if (chunkAccess == null) {
+ continue;
+ }
+ return either.orElseThrow(IllegalStateException::new);
+ return chunkAccess;
+ }
+ return null;
+ }
@@ -6216,9 +6222,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start
+ public @Nullable ChunkStatus getChunkHolderStatus() {
+ for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getParent(); curr != next; curr = next, next = next.getParent()) {
+ CompletableFuture<ChunkResult<ChunkAccess>> future = this.getFutureIfPresentUnchecked(curr);
+ ChunkResult<ChunkAccess> either = future.getNow(null);
+ if (either == null || !either.isSuccess()) {
+ ChunkAccess chunkAccess = this.getChunkIfPresentUnchecked(curr);
+ if (chunkAccess == null) {
+ continue;
+ }
+ return curr;
@@ -6745,7 +6750,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return null;
+ }
+
+ return holder.getLastAvailable();
+ return holder.getLatestChunk();
+ }
+
+ public <T> void addTicketAtLevel(TicketType<T> ticketType, ChunkPos chunkPos, int ticketLevel, T identifier) {