mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
eed041d629
By: md_5 <git@md-5.net>
123 lines
8 KiB
Diff
123 lines
8 KiB
Diff
--- a/net/minecraft/server/level/PlayerChunkMap.java
|
|
+++ b/net/minecraft/server/level/PlayerChunkMap.java
|
|
@@ -102,6 +102,10 @@
|
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
|
import org.slf4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.craftbukkit.generator.CustomChunkGenerator;
|
|
+// CraftBukkit end
|
|
+
|
|
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, GeneratingChunkMap {
|
|
|
|
private static final ChunkResult<List<IChunkAccess>> UNLOADED_CHUNK_LIST_RESULT = ChunkResult.error("Unloaded chunks found in range");
|
|
@@ -145,6 +149,27 @@
|
|
public int serverViewDistance;
|
|
private final WorldGenContext worldGenContext;
|
|
|
|
+ // 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 {
|
|
+
|
|
+ private final java.util.Queue<Runnable> queue = new java.util.ArrayDeque<>();
|
|
+
|
|
+ @Override
|
|
+ public void execute(Runnable runnable) {
|
|
+ queue.add(runnable);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ Runnable task;
|
|
+ while ((task = queue.poll()) != null) {
|
|
+ task.run();
|
|
+ }
|
|
+ }
|
|
+ };
|
|
+ // 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(new RegionStorageInfo(convertable_conversionsession.getLevelId(), worldserver.dimension(), "chunk"), convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
|
|
this.visibleChunkMap = this.updatingChunkMap.clone();
|
|
@@ -164,7 +189,13 @@
|
|
IRegistryCustom iregistrycustom = worldserver.registryAccess();
|
|
long j = worldserver.getSeed();
|
|
|
|
- if (chunkgenerator instanceof ChunkGeneratorAbstract chunkgeneratorabstract) {
|
|
+ // CraftBukkit start - SPIGOT-7051: It's a rigged game! Use delegate for random state creation, otherwise it is not so random.
|
|
+ ChunkGenerator randomGenerator = chunkgenerator;
|
|
+ if (randomGenerator instanceof CustomChunkGenerator customChunkGenerator) {
|
|
+ randomGenerator = customChunkGenerator.getDelegate();
|
|
+ }
|
|
+ if (randomGenerator instanceof ChunkGeneratorAbstract chunkgeneratorabstract) {
|
|
+ // CraftBukkit end
|
|
this.randomState = RandomState.create((GeneratorSettingBase) chunkgeneratorabstract.generatorSettings().value(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
|
|
} else {
|
|
this.randomState = RandomState.create(GeneratorSettingBase.dummy(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
|
|
@@ -318,7 +349,7 @@
|
|
throw this.debugFuturesAndCreateReportedException(new IllegalStateException("At least one of the chunk futures were null"), "n/a");
|
|
}
|
|
|
|
- IChunkAccess ichunkaccess = (IChunkAccess) chunkresult.orElse((Object) null);
|
|
+ IChunkAccess ichunkaccess = (IChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error
|
|
|
|
if (ichunkaccess == null) {
|
|
return PlayerChunkMap.UNLOADED_CHUNK_LIST_RESULT;
|
|
@@ -937,7 +968,8 @@
|
|
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
|
|
});
|
|
|
|
- csvwriter.writeRow(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getPersistedStatus).orElse((Object) null), optional1.map(Chunk::getFullStatus).orElse((Object) null), printFuture(playerchunk.getFullChunkFuture()), printFuture(playerchunk.getTickingChunkFuture()), printFuture(playerchunk.getEntityTickingChunkFuture()), this.distanceManager.getTicketDebugString(i), this.anyPlayerCloseEnoughForSpawning(chunkcoordintpair), optional1.map((chunk) -> {
|
|
+ // CraftBukkit - decompile error
|
|
+ csvwriter.writeRow(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getPersistedStatus).orElse(null), optional1.map(Chunk::getFullStatus).orElse(null), printFuture(playerchunk.getFullChunkFuture()), printFuture(playerchunk.getTickingChunkFuture()), printFuture(playerchunk.getEntityTickingChunkFuture()), this.distanceManager.getTicketDebugString(i), this.anyPlayerCloseEnoughForSpawning(chunkcoordintpair), optional1.map((chunk) -> {
|
|
return chunk.getBlockEntities().size();
|
|
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
|
|
return chunk.getBlockTicks().count();
|
|
@@ -950,7 +982,7 @@
|
|
|
|
private static String printFuture(CompletableFuture<ChunkResult<Chunk>> completablefuture) {
|
|
try {
|
|
- ChunkResult<Chunk> chunkresult = (ChunkResult) completablefuture.getNow((Object) null);
|
|
+ ChunkResult<Chunk> chunkresult = (ChunkResult) completablefuture.getNow(null); // CraftBukkit - decompile error
|
|
|
|
return chunkresult != null ? (chunkresult.isSuccess() ? "done" : "unloaded") : "not completed";
|
|
} catch (CompletionException completionexception) {
|
|
@@ -962,12 +994,14 @@
|
|
|
|
private CompletableFuture<Optional<NBTTagCompound>> readChunk(ChunkCoordIntPair chunkcoordintpair) {
|
|
return this.read(chunkcoordintpair).thenApplyAsync((optional) -> {
|
|
- return optional.map(this::upgradeChunkTag);
|
|
+ return optional.map((nbttagcompound) -> upgradeChunkTag(nbttagcompound, chunkcoordintpair)); // CraftBukkit
|
|
}, SystemUtils.backgroundExecutor());
|
|
}
|
|
|
|
- private NBTTagCompound upgradeChunkTag(NBTTagCompound nbttagcompound) {
|
|
- return this.upgradeChunkTag(this.level.dimension(), this.overworldDataStorage, nbttagcompound, this.generator().getTypeNameForDataFixer());
|
|
+ // CraftBukkit start
|
|
+ private NBTTagCompound upgradeChunkTag(NBTTagCompound nbttagcompound, ChunkCoordIntPair chunkcoordintpair) {
|
|
+ return this.upgradeChunkTag(this.level.getTypeKey(), this.overworldDataStorage, nbttagcompound, this.generator().getTypeNameForDataFixer(), chunkcoordintpair, level);
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
|
|
@@ -1370,7 +1404,7 @@
|
|
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
|
|
|
|
public EntityTracker(final Entity entity, final int i, final int j, final boolean flag) {
|
|
- this.serverEntity = new EntityTrackerEntry(PlayerChunkMap.this.level, entity, j, flag, this::broadcast);
|
|
+ this.serverEntity = new EntityTrackerEntry(PlayerChunkMap.this.level, entity, j, flag, this::broadcast, seenBy); // CraftBukkit
|
|
this.entity = entity;
|
|
this.range = i;
|
|
this.lastSectionPos = SectionPosition.of((EntityAccess) entity);
|
|
@@ -1430,6 +1464,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);
|
|
|
|
+ // CraftBukkit start - respect vanish API
|
|
+ if (!entityplayer.getBukkitEntity().canSee(this.entity.getBukkitEntity())) {
|
|
+ flag = false;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (flag) {
|
|
if (this.seenBy.add(entityplayer.connection)) {
|
|
this.serverEntity.addPairing(entityplayer);
|