2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
2022-06-07 18:00:00 +02:00
@@ -102,6 +102,11 @@
2022-02-28 16:00:00 +01:00
import org.apache.commons.lang3.mutable.MutableObject;
import org.slf4j.Logger;
2019-04-23 04:00:00 +02:00
2021-11-23 07:13:52 +01:00
+// CraftBukkit start
+import net.minecraft.world.level.levelgen.GeneratorSettings;
+import org.bukkit.entity.Player;
+// CraftBukkit end
2021-03-08 22:47:33 +01:00
+
2021-06-11 07:00:00 +02:00
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
private static final byte CHUNK_TYPE_REPLACEABLE = -1;
2022-06-07 18:00:00 +02:00
@@ -144,6 +149,27 @@
2021-06-11 07:00:00 +02:00
private final Queue<Runnable> unloadQueue;
int viewDistance;
2019-07-13 20:19:44 +02:00
+ // 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 {
+
2021-06-11 07:00:00 +02:00
+ private final java.util.Queue<Runnable> queue = new java.util.ArrayDeque<>();
2019-07-13 20:19:44 +02:00
+
+ @Override
+ public void execute(Runnable runnable) {
2021-06-11 07:00:00 +02:00
+ queue.add(runnable);
2019-07-13 20:19:44 +02:00
+ }
+
+ @Override
+ public void run() {
2021-06-11 07:00:00 +02:00
+ Runnable task;
+ while ((task = queue.poll()) != null) {
2019-07-13 20:19:44 +02:00
+ task.run();
+ }
+ }
+ };
+ // CraftBukkit end
+
2022-06-07 18:00:00 +02:00
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) {
2021-11-21 23:00:00 +01:00
super(convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
2021-06-11 07:00:00 +02:00
this.visibleChunkMap = this.updatingChunkMap.clone();
2022-06-07 18:00:00 +02:00
@@ -313,9 +339,12 @@
2021-11-26 22:00:00 +01:00
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();
2019-04-23 04:00:00 +02:00
- final int l1 = 0;
+ // CraftBukkit start - decompile error
+ int cnt = 0;
2021-11-26 22:00:00 +01:00
- for (Iterator iterator = list2.iterator(); iterator.hasNext(); ++l1) {
+ for (Iterator iterator = list2.iterator(); iterator.hasNext(); ++cnt) {
2019-04-23 04:00:00 +02:00
+ final int l1 = cnt;
2016-12-06 12:05:58 +01:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
final Either<IChunkAccess, PlayerChunk.Failure> either = (Either) iterator.next();
2022-02-28 16:00:00 +01:00
if (either == null) {
2022-06-07 18:00:00 +02:00
@@ -520,7 +549,7 @@
2019-04-23 04:00:00 +02:00
2021-11-21 23:00:00 +01:00
private void scheduleUnload(long i, PlayerChunk playerchunk) {
CompletableFuture<IChunkAccess> completablefuture = playerchunk.getChunkToSave();
2019-05-27 22:30:00 +02:00
- Consumer consumer = (ichunkaccess) -> {
+ Consumer<IChunkAccess> consumer = (ichunkaccess) -> { // CraftBukkit - decompile error
2021-11-21 23:00:00 +01:00
CompletableFuture<IChunkAccess> completablefuture1 = playerchunk.getChunkToSave();
2019-05-27 22:30:00 +02:00
if (completablefuture1 != completablefuture) {
2022-06-07 18:00:00 +02:00
@@ -609,9 +638,9 @@
ProtoChunk protochunk = ChunkRegionLoader.read(this.level, this.poiManager, chunkcoordintpair, (NBTTagCompound) optional.get());
this.markPosition(chunkcoordintpair, protochunk.getStatus().getChunkType());
- return Either.left(protochunk);
+ return Either.<IChunkAccess, PlayerChunk.Failure>left(protochunk); // CraftBukkit - decompile error
} else {
- return Either.left(this.createEmptyChunk(chunkcoordintpair));
+ return Either.<IChunkAccess, PlayerChunk.Failure>left(this.createEmptyChunk(chunkcoordintpair)); // CraftBukkit - decompile error
}
}, this.mainThreadExecutor).exceptionallyAsync((throwable) -> {
return this.handleChunkLoadFailure(throwable, chunkcoordintpair);
@@ -717,7 +746,21 @@
2021-06-11 07:00:00 +02:00
2021-11-21 23:00:00 +01:00
private static void postLoadProtoChunk(WorldServer worldserver, List<NBTTagCompound> list) {
2021-06-11 07:00:00 +02:00
if (!list.isEmpty()) {
2021-11-21 23:00:00 +01:00
- worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver));
2021-06-11 07:00:00 +02:00
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
2021-11-21 23:00:00 +01:00
+ worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver).filter((entity) -> {
2021-06-11 07:00:00 +02:00
+ boolean needsRemoval = false;
2021-06-11 13:33:49 +02:00
+ net.minecraft.server.dedicated.DedicatedServer server = worldserver.getCraftServer().getServer();
2021-11-21 23:00:00 +01:00
+ if (!server.areNpcsEnabled() && entity instanceof net.minecraft.world.entity.npc.NPC) {
+ entity.discard();
2021-06-11 07:00:00 +02:00
+ needsRemoval = true;
+ }
2021-11-21 23:00:00 +01:00
+ if (!server.isSpawningAnimals() && (entity instanceof net.minecraft.world.entity.animal.EntityAnimal || entity instanceof net.minecraft.world.entity.animal.EntityWaterAnimal)) {
+ entity.discard();
2021-06-11 07:00:00 +02:00
+ needsRemoval = true;
+ }
+ return !needsRemoval;
+ }));
+ // CraftBukkit end
}
}
2022-06-07 18:00:00 +02:00
@@ -816,7 +859,7 @@
2021-11-24 22:00:00 +01:00
if (!playerchunk.wasAccessibleSinceLastSave()) {
return false;
} else {
- IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkToSave().getNow((Object) null);
+ IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkToSave().getNow(null); // CraftBukkit - decompile error
2021-11-26 22:00:00 +01:00
if (!(ichunkaccess instanceof ProtoChunkExtension) && !(ichunkaccess instanceof Chunk)) {
return false;
2022-06-07 18:00:00 +02:00
@@ -978,7 +1021,8 @@
2019-07-20 01:00:00 +02:00
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
2021-11-21 23:00:00 +01:00
- csvwriter.writeRow(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getStatus).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) -> {
2020-02-02 01:18:17 +01:00
+ // CraftBukkit - decompile error
2021-11-21 23:00:00 +01:00
+ csvwriter.writeRow(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getStatus).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();
2022-06-07 18:00:00 +02:00
@@ -991,7 +1035,7 @@
2019-07-20 01:00:00 +02:00
2021-11-21 23:00:00 +01:00
private static String printFuture(CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture) {
2019-07-20 01:00:00 +02:00
try {
- Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow((Object) null);
2020-02-02 01:18:17 +01:00
+ Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error
2019-07-20 01:00:00 +02:00
return either != null ? (String) either.map((chunk) -> {
return "done";
2022-06-07 18:00:00 +02:00
@@ -1007,12 +1051,14 @@
2019-04-23 04:00:00 +02:00
2022-06-07 18:00:00 +02:00
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
2019-04-23 04:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
2022-06-07 18:00:00 +02:00
@@ -1433,7 +1479,7 @@
2021-06-11 07:00:00 +02:00
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
2019-04-23 04:00:00 +02:00
public EntityTracker(Entity entity, int i, int j, boolean flag) {
2021-06-11 07:00:00 +02:00
- 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;
2022-06-07 18:00:00 +02:00
this.lastSectionPos = SectionPosition.of((EntityAccess) entity);
@@ -1492,6 +1538,11 @@
2021-11-21 23:00:00 +01:00
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer);
2021-06-11 07:00:00 +02:00
+ // CraftBukkit start - respect vanish API
2021-11-28 23:18:52 +01:00
+ if (!entityplayer.getBukkitEntity().canSee(this.entity.getBukkitEntity())) {
+ flag = false;
2021-06-11 07:00:00 +02:00
+ }
+ // CraftBukkit end
if (flag) {
if (this.seenBy.add(entityplayer.connection)) {
2021-11-21 23:00:00 +01:00
this.serverEntity.addPairing(entityplayer);