Implement APIs for per world view and simulation distances

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2023-12-23 14:32:49 +11:00
parent 6a6ddbcb6d
commit a9fb0c70f8
3 changed files with 38 additions and 19 deletions

View file

@ -1,5 +1,14 @@
--- a/net/minecraft/server/level/ChunkMapDistance.java
+++ b/net/minecraft/server/level/ChunkMapDistance.java
@@ -55,7 +55,7 @@
final LongSet ticketsToRelease = new LongOpenHashSet();
final Executor mainThreadExecutor;
private long ticketTickCounter;
- private int simulationDistance = 10;
+ public int simulationDistance = 10;
protected ChunkMapDistance(Executor executor, Executor executor1) {
Objects.requireNonNull(executor1);
@@ -122,10 +122,25 @@
}

View file

@ -1,22 +1,23 @@
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
@@ -101,6 +101,12 @@
@@ -101,6 +101,10 @@
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.levelgen.GeneratorSettings;
+import org.bukkit.craftbukkit.generator.CustomChunkGenerator;
+import org.bukkit.entity.Player;
+// CraftBukkit end
+
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
private static final byte CHUNK_TYPE_REPLACEABLE = -1;
@@ -143,6 +149,27 @@
@@ -141,7 +145,28 @@
private final Long2ByteMap chunkTypeCache;
private final Long2LongMap chunkSaveCooldowns;
private final Queue<Runnable> unloadQueue;
private int serverViewDistance;
- private int serverViewDistance;
+ public int serverViewDistance;
+
+ // CraftBukkit start - recursion-safe executor for Chunk loadCallback() and unloadCallback()
+ public final CallbackExecutor callbackExecutor = new CallbackExecutor();
+ public static final class CallbackExecutor implements java.util.concurrent.Executor, Runnable {
@ -37,11 +38,10 @@
+ }
+ };
+ // CraftBukkit end
+
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, StructureTemplateManager structuretemplatemanager, Executor executor, IAsyncTaskHandler<Runnable> iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
super(convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
this.visibleChunkMap = this.updatingChunkMap.clone();
@@ -161,6 +188,11 @@
@@ -161,6 +186,11 @@
this.storageName = path.getFileName().toString();
this.level = worldserver;
this.generator = chunkgenerator;
@ -53,7 +53,7 @@
IRegistryCustom iregistrycustom = worldserver.registryAccess();
long j = worldserver.getSeed();
@@ -332,9 +364,12 @@
@@ -332,9 +362,12 @@
CompletableFuture<List<Either<IChunkAccess, PlayerChunk.Failure>>> completablefuture1 = SystemUtils.sequence(list);
CompletableFuture<Either<List<IChunkAccess>, PlayerChunk.Failure>> completablefuture2 = completablefuture1.thenApply((list2) -> {
List<IChunkAccess> list3 = Lists.newArrayList();
@ -68,7 +68,7 @@
final Either<IChunkAccess, PlayerChunk.Failure> either = (Either) iterator.next();
if (either == null) {
@@ -540,7 +575,7 @@
@@ -540,7 +573,7 @@
private void scheduleUnload(long i, PlayerChunk playerchunk) {
CompletableFuture<IChunkAccess> completablefuture = playerchunk.getChunkToSave();
@ -77,7 +77,7 @@
CompletableFuture<IChunkAccess> completablefuture1 = playerchunk.getChunkToSave();
if (completablefuture1 != completablefuture) {
@@ -631,9 +666,9 @@
@@ -631,9 +664,9 @@
ProtoChunk protochunk = ChunkRegionLoader.read(this.level, this.poiManager, chunkcoordintpair, (NBTTagCompound) optional.get());
this.markPosition(chunkcoordintpair, protochunk.getStatus().getChunkType());
@ -89,7 +89,7 @@
}
}, this.mainThreadExecutor).exceptionallyAsync((throwable) -> {
return this.handleChunkLoadFailure(throwable, chunkcoordintpair);
@@ -748,7 +783,21 @@
@@ -748,7 +781,21 @@
private static void postLoadProtoChunk(WorldServer worldserver, List<NBTTagCompound> list) {
if (!list.isEmpty()) {
@ -112,7 +112,7 @@
}
}
@@ -860,7 +909,7 @@
@@ -860,7 +907,7 @@
if (!playerchunk.wasAccessibleSinceLastSave()) {
return false;
} else {
@ -121,7 +121,7 @@
if (!(ichunkaccess instanceof ProtoChunkExtension) && !(ichunkaccess instanceof Chunk)) {
return false;
@@ -1017,7 +1066,8 @@
@@ -1017,7 +1064,8 @@
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
@ -131,7 +131,7 @@
return chunk.getBlockEntities().size();
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
return chunk.getBlockTicks().count();
@@ -1030,7 +1080,7 @@
@@ -1030,7 +1078,7 @@
private static String printFuture(CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture) {
try {
@ -140,7 +140,7 @@
return either != null ? (String) either.map((chunk) -> {
return "done";
@@ -1046,12 +1096,14 @@
@@ -1046,12 +1094,14 @@
private CompletableFuture<Optional<NBTTagCompound>> readChunk(ChunkCoordIntPair chunkcoordintpair) {
return this.read(chunkcoordintpair).thenApplyAsync((optional) -> {
@ -158,7 +158,7 @@
}
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
@@ -1460,7 +1512,7 @@
@@ -1460,7 +1510,7 @@
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
public EntityTracker(Entity entity, int i, int j, boolean flag) {
@ -167,7 +167,7 @@
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.of((EntityAccess) entity);
@@ -1520,6 +1572,11 @@
@@ -1520,6 +1570,11 @@
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer) && PlayerChunkMap.this.isChunkTracked(entityplayer, this.entity.chunkPosition().x, this.entity.chunkPosition().z);

View file

@ -1032,6 +1032,16 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return Difficulty.getByValue(this.getHandle().getDifficulty().ordinal());
}
@Override
public int getViewDistance() {
return world.getChunkSource().chunkMap.serverViewDistance;
}
@Override
public int getSimulationDistance() {
return world.getChunkSource().chunkMap.getDistanceManager().simulationDistance;
}
public BlockMetadataStore getBlockMetadata() {
return blockMetadata;
}