More more work

This commit is contained in:
Nassim Jahnke 2021-11-23 12:47:17 +01:00 committed by MiniDigger | Martin
parent 456621b0d7
commit c8cb91bb99
4 changed files with 87 additions and 21 deletions

View File

@ -1311,7 +1311,7 @@ index 03bdc1622791e1206406c87065978688d602e39e..c4dcafac892169a7bfcc065701fffb43
public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message) { public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message) {
broadcastCommandMessage(source, message, true); broadcastCommandMessage(source, message, true);
diff --git a/src/main/java/org/bukkit/command/CommandSender.java b/src/main/java/org/bukkit/command/CommandSender.java diff --git a/src/main/java/org/bukkit/command/CommandSender.java b/src/main/java/org/bukkit/command/CommandSender.java
index 284be63a125624a8ae43d2c164aede810ce6bfe5..7c9a0c85c0e23d6a569c3583e87b005938923d95 100644 index 284be63a125624a8ae43d2c164aede810ce6bfe5..f98d46fa45bb7c842d791b09f082a0968ae537fb 100644
--- a/src/main/java/org/bukkit/command/CommandSender.java --- a/src/main/java/org/bukkit/command/CommandSender.java
+++ b/src/main/java/org/bukkit/command/CommandSender.java +++ b/src/main/java/org/bukkit/command/CommandSender.java
@@ -6,12 +6,13 @@ import org.bukkit.permissions.Permissible; @@ -6,12 +6,13 @@ import org.bukkit.permissions.Permissible;
@ -1404,7 +1404,7 @@ index 284be63a125624a8ae43d2c164aede810ce6bfe5..7c9a0c85c0e23d6a569c3583e87b0059
+ * + *
+ * @return Name of the sender + * @return Name of the sender
+ */ + */
+ public @NotNull Component name(); + public @NotNull net.kyori.adventure.text.Component name();
+ +
+ @Override + @Override
+ default void sendMessage(final @NotNull net.kyori.adventure.identity.Identity identity, final @NotNull net.kyori.adventure.text.Component message, final @NotNull net.kyori.adventure.audience.MessageType type) { + default void sendMessage(final @NotNull net.kyori.adventure.identity.Identity identity, final @NotNull net.kyori.adventure.text.Component message, final @NotNull net.kyori.adventure.audience.MessageType type) {

View File

@ -4481,10 +4481,10 @@ index 4ea6c2f0ac4703a5d67137073a5da0c39d77bdce..b964121f19e6a28df7675e65441c551a
} else { } else {
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..850caa39d4875620b05c9a3cc27c65ef2c877005 index 0000000000000000000000000000000000000000..ff4def7ec3dcfa30fdc0135bd1add8e47989fb36
--- /dev/null --- /dev/null
+++ b/src/main/java/net/minecraft/server/MCUtil.java +++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -0,0 +1,501 @@ @@ -0,0 +1,505 @@
+package net.minecraft.server; +package net.minecraft.server;
+ +
+import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.google.common.util.concurrent.ThreadFactoryBuilder;
@ -4985,6 +4985,10 @@ index 0000000000000000000000000000000000000000..850caa39d4875620b05c9a3cc27c65ef
+ return null; + return null;
+ } + }
+ } + }
+
+ public static int getTicketLevelFor(net.minecraft.world.level.chunk.ChunkStatus status) {
+ return net.minecraft.server.level.ChunkMap.MAX_VIEW_DISTANCE + net.minecraft.world.level.chunk.ChunkStatus.getDistance(status);
+ }
+} +}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index b06105d3920f68bcedb81359b0f62925421b338d..6fc450b66d381c6453498fa18d36570ef74b124d 100644 index b06105d3920f68bcedb81359b0f62925421b338d..6fc450b66d381c6453498fa18d36570ef74b124d 100644
@ -5038,7 +5042,7 @@ index b06105d3920f68bcedb81359b0f62925421b338d..6fc450b66d381c6453498fa18d36570e
} catch (Throwable throwable) { } catch (Throwable throwable) {
// Spigot Start // Spigot Start
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
index d2fbb6e28db27b3207879be3027bb74410a53900..258597ff1b8c83c1377fe21db60abf84abbf431c 100644 index d2fbb6e28db27b3207879be3027bb74410a53900..303125c4d0f8f235703975eab5eccb9aa045ccf8 100644
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java --- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java +++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
@@ -49,9 +49,9 @@ public class ChunkHolder { @@ -49,9 +49,9 @@ public class ChunkHolder {
@ -5076,7 +5080,29 @@ index d2fbb6e28db27b3207879be3027bb74410a53900..258597ff1b8c83c1377fe21db60abf84
if (!ChunkHolder.getFullChunkStatus(this.oldTicketLevel).isOrAfter(ChunkHolder.FullChunkStatus.BORDER)) return null; // note: using oldTicketLevel for isLoaded checks if (!ChunkHolder.getFullChunkStatus(this.oldTicketLevel).isOrAfter(ChunkHolder.FullChunkStatus.BORDER)) return null; // note: using oldTicketLevel for isLoaded checks
return this.getFullChunkUnchecked(); return this.getFullChunkUnchecked();
} }
@@ -115,20 +118,20 @@ public class ChunkHolder { @@ -105,6 +108,21 @@ public class ChunkHolder {
}
// CraftBukkit end
+ // Paper start
+ public ChunkAccess getAvailableChunkNow() {
+ // TODO can we just getStatusFuture(EMPTY)?
+ for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getParent(); curr != next; curr = next, next = next.getParent()) {
+ CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> future = this.getFutureIfPresentUnchecked(curr);
+ Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = future.getNow(null);
+ if (either == null || !either.left().isPresent()) {
+ continue;
+ }
+ return either.left().get();
+ }
+ return null;
+ }
+ // Paper end
+
public CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getFutureIfPresentUnchecked(ChunkStatus leastStatus) {
CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> completablefuture = (CompletableFuture) this.futures.get(leastStatus.getIndex());
@@ -115,20 +133,20 @@ public class ChunkHolder {
return ChunkHolder.getStatus(this.ticketLevel).isOrAfter(leastStatus) ? this.getFutureIfPresentUnchecked(leastStatus) : ChunkHolder.UNLOADED_CHUNK_FUTURE; return ChunkHolder.getStatus(this.ticketLevel).isOrAfter(leastStatus) ? this.getFutureIfPresentUnchecked(leastStatus) : ChunkHolder.UNLOADED_CHUNK_FUTURE;
} }
@ -5101,7 +5127,29 @@ index d2fbb6e28db27b3207879be3027bb74410a53900..258597ff1b8c83c1377fe21db60abf84
CompletableFuture<Either<LevelChunk, ChunkHolder.ChunkLoadingFailure>> completablefuture = this.getTickingChunkFuture(); CompletableFuture<Either<LevelChunk, ChunkHolder.ChunkLoadingFailure>> completablefuture = this.getTickingChunkFuture();
Either<LevelChunk, ChunkHolder.ChunkLoadingFailure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error Either<LevelChunk, ChunkHolder.ChunkLoadingFailure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error
@@ -167,7 +170,7 @@ public class ChunkHolder { @@ -149,6 +167,21 @@ public class ChunkHolder {
return null;
}
+ // Paper start
+ public ChunkStatus getChunkHolderStatus() {
+ for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getParent(); curr != next; curr = next, next = next.getParent()) {
+ CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> future = this.getFutureIfPresentUnchecked(curr);
+ Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = future.getNow(null);
+ if (either == null || !either.left().isPresent()) {
+ continue;
+ }
+ return curr;
+ }
+
+ return null;
+ }
+ // Paper end
+
@Nullable
public ChunkAccess getLastAvailable() {
for (int i = ChunkHolder.CHUNK_STATUSES.size() - 1; i >= 0; --i) {
@@ -167,7 +200,7 @@ public class ChunkHolder {
return null; return null;
} }
@ -5110,7 +5158,7 @@ index d2fbb6e28db27b3207879be3027bb74410a53900..258597ff1b8c83c1377fe21db60abf84
return this.chunkToSave; return this.chunkToSave;
} }
@@ -325,11 +328,11 @@ public class ChunkHolder { @@ -325,11 +358,11 @@ public class ChunkHolder {
return ChunkHolder.getFullChunkStatus(this.ticketLevel); return ChunkHolder.getFullChunkStatus(this.ticketLevel);
} }
@ -5124,7 +5172,7 @@ index d2fbb6e28db27b3207879be3027bb74410a53900..258597ff1b8c83c1377fe21db60abf84
return this.ticketLevel; return this.ticketLevel;
} }
@@ -418,14 +421,27 @@ public class ChunkHolder { @@ -418,14 +451,27 @@ public class ChunkHolder {
this.wasAccessibleSinceLastSave |= flag3; this.wasAccessibleSinceLastSave |= flag3;
if (!flag2 && flag3) { if (!flag2 && flag3) {
@ -5152,7 +5200,7 @@ index d2fbb6e28db27b3207879be3027bb74410a53900..258597ff1b8c83c1377fe21db60abf84
} }
boolean flag4 = playerchunk_state.isOrAfter(ChunkHolder.FullChunkStatus.TICKING); boolean flag4 = playerchunk_state.isOrAfter(ChunkHolder.FullChunkStatus.TICKING);
@@ -434,12 +450,29 @@ public class ChunkHolder { @@ -434,12 +480,29 @@ public class ChunkHolder {
if (!flag4 && flag5) { if (!flag4 && flag5) {
this.tickingChunkFuture = chunkStorage.prepareTickingChunk(this); this.tickingChunkFuture = chunkStorage.prepareTickingChunk(this);
this.scheduleFullChunkPromotion(chunkStorage, this.tickingChunkFuture, executor, ChunkHolder.FullChunkStatus.TICKING); this.scheduleFullChunkPromotion(chunkStorage, this.tickingChunkFuture, executor, ChunkHolder.FullChunkStatus.TICKING);
@ -5183,7 +5231,7 @@ index d2fbb6e28db27b3207879be3027bb74410a53900..258597ff1b8c83c1377fe21db60abf84
} }
boolean flag6 = playerchunk_state.isOrAfter(ChunkHolder.FullChunkStatus.ENTITY_TICKING); boolean flag6 = playerchunk_state.isOrAfter(ChunkHolder.FullChunkStatus.ENTITY_TICKING);
@@ -452,12 +485,28 @@ public class ChunkHolder { @@ -452,12 +515,28 @@ public class ChunkHolder {
this.entityTickingChunkFuture = chunkStorage.prepareEntityTickingChunk(this.pos); this.entityTickingChunkFuture = chunkStorage.prepareEntityTickingChunk(this.pos);
this.scheduleFullChunkPromotion(chunkStorage, this.entityTickingChunkFuture, executor, ChunkHolder.FullChunkStatus.ENTITY_TICKING); this.scheduleFullChunkPromotion(chunkStorage, this.entityTickingChunkFuture, executor, ChunkHolder.FullChunkStatus.ENTITY_TICKING);
@ -5374,7 +5422,7 @@ index 01b59a9c18d6f07889c3df2975cbf5594a167633..3f938d953daee7a5551a62df25f2e0fb
@Override @Override
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index a551683bc73db23d82bd2ca1e2c7c83e31e3c834..fc3565c1dd1c7f09bc885f1b0c9cf71477d64543 100644 index a551683bc73db23d82bd2ca1e2c7c83e31e3c834..2616debed901b2dd0bd5ad3ea26ffce2d92dc6c1 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -46,8 +46,11 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureMana @@ -46,8 +46,11 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureMana
@ -5389,7 +5437,7 @@ index a551683bc73db23d82bd2ca1e2c7c83e31e3c834..fc3565c1dd1c7f09bc885f1b0c9cf714
public static final List<ChunkStatus> CHUNK_STATUSES = ChunkStatus.getStatusList(); public static final List<ChunkStatus> CHUNK_STATUSES = ChunkStatus.getStatusList();
private final DistanceManager distanceManager; private final DistanceManager distanceManager;
@@ -67,6 +70,316 @@ public class ServerChunkCache extends ChunkSource { @@ -67,6 +70,334 @@ public class ServerChunkCache extends ChunkSource {
@Nullable @Nullable
@VisibleForDebug @VisibleForDebug
private NaturalSpawner.SpawnState lastSpawnState; private NaturalSpawner.SpawnState lastSpawnState;
@ -5545,6 +5593,16 @@ index a551683bc73db23d82bd2ca1e2c7c83e31e3c834..fc3565c1dd1c7f09bc885f1b0c9cf714
+ // Paper end + // Paper end
+ +
+ // Paper start + // Paper start
+ @Nullable
+ public ChunkAccess getChunkAtImmediately(int x, int z) {
+ ChunkHolder holder = this.chunkMap.getVisibleChunkIfPresent(ChunkPos.asLong(x, z));
+ if (holder == null) {
+ return null;
+ }
+
+ return holder.getLastAvailable();
+ }
+
+ // this will try to avoid chunk neighbours for lighting + // this will try to avoid chunk neighbours for lighting
+ public final ChunkAccess getFullStatusChunkAt(int chunkX, int chunkZ) { + public final ChunkAccess getFullStatusChunkAt(int chunkX, int chunkZ) {
+ LevelChunk ifLoaded = this.getChunkAtIfLoadedImmediately(chunkX, chunkZ); + LevelChunk ifLoaded = this.getChunkAtIfLoadedImmediately(chunkX, chunkZ);
@ -5634,6 +5692,14 @@ index a551683bc73db23d82bd2ca1e2c7c83e31e3c834..fc3565c1dd1c7f09bc885f1b0c9cf714
+ }, this.mainThreadProcessor); + }, this.mainThreadProcessor);
+ } + }
+ +
+ public <T> void addTicketAtLevel(TicketType<T> ticketType, ChunkPos chunkPos, int ticketLevel, T identifier) {
+ this.distanceManager.addTicketAtLevel(ticketType, chunkPos, ticketLevel, identifier);
+ }
+
+ public <T> void removeTicketAtLevel(TicketType<T> ticketType, ChunkPos chunkPos, int ticketLevel, T identifier) {
+ this.distanceManager.removeTicketAtLevel(ticketType, chunkPos, ticketLevel, identifier);
+ }
+
+ void chunkLoadAccept(int chunkX, int chunkZ, ChunkAccess chunk, java.util.function.Consumer<ChunkAccess> consumer) { + void chunkLoadAccept(int chunkX, int chunkZ, ChunkAccess chunk, java.util.function.Consumer<ChunkAccess> consumer) {
+ try { + try {
+ consumer.accept(chunk); + consumer.accept(chunk);
@ -5706,7 +5772,7 @@ index a551683bc73db23d82bd2ca1e2c7c83e31e3c834..fc3565c1dd1c7f09bc885f1b0c9cf714
public ServerChunkCache(ServerLevel world, LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, StructureManager structureManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int viewDistance, int simulationDistance, boolean dsync, ChunkProgressListener worldGenerationProgressListener, ChunkStatusUpdateListener chunkStatusChangeListener, Supplier<DimensionDataStorage> persistentStateManagerFactory) { public ServerChunkCache(ServerLevel world, LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, StructureManager structureManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int viewDistance, int simulationDistance, boolean dsync, ChunkProgressListener worldGenerationProgressListener, ChunkStatusUpdateListener chunkStatusChangeListener, Supplier<DimensionDataStorage> persistentStateManagerFactory) {
this.level = world; this.level = world;
@@ -127,6 +440,49 @@ public class ServerChunkCache extends ChunkSource { @@ -127,6 +458,49 @@ public class ServerChunkCache extends ChunkSource {
this.lastChunk[0] = chunk; this.lastChunk[0] = chunk;
} }
@ -5756,7 +5822,7 @@ index a551683bc73db23d82bd2ca1e2c7c83e31e3c834..fc3565c1dd1c7f09bc885f1b0c9cf714
@Nullable @Nullable
@Override @Override
public ChunkAccess getChunk(int x, int z, ChunkStatus leastStatus, boolean create) { public ChunkAccess getChunk(int x, int z, ChunkStatus leastStatus, boolean create) {
@@ -441,7 +797,7 @@ public class ServerChunkCache extends ChunkSource { @@ -441,7 +815,7 @@ public class ServerChunkCache extends ChunkSource {
gameprofilerfiller.popPush("spawnAndTick"); gameprofilerfiller.popPush("spawnAndTick");
boolean flag2 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit boolean flag2 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit

View File

@ -1125,10 +1125,10 @@ index 3f938d953daee7a5551a62df25f2e0fb487733ec..cab03a81a97d851db61e517cfe3a43fa
} }
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index fc3565c1dd1c7f09bc885f1b0c9cf71477d64543..28761de0a4a460f74fbf6aca3f5d5ec87684b529 100644 index 2616debed901b2dd0bd5ad3ea26ffce2d92dc6c1..c79521ab00a1c258bbeae56a687636e34932ac6f 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -508,13 +508,15 @@ public class ServerChunkCache extends ChunkSource { @@ -526,13 +526,15 @@ public class ServerChunkCache extends ChunkSource {
} }
gameprofilerfiller.incrementCounter("getChunkCacheMiss"); gameprofilerfiller.incrementCounter("getChunkCacheMiss");
@ -1146,7 +1146,7 @@ index fc3565c1dd1c7f09bc885f1b0c9cf71477d64543..28761de0a4a460f74fbf6aca3f5d5ec8
ichunkaccess = (ChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> { ichunkaccess = (ChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> {
return ichunkaccess1; return ichunkaccess1;
}, (playerchunk_failure) -> { }, (playerchunk_failure) -> {
@@ -712,7 +714,9 @@ public class ServerChunkCache extends ChunkSource { @@ -730,7 +732,9 @@ public class ServerChunkCache extends ChunkSource {
public void save(boolean flush) { public void save(boolean flush) {
this.runDistanceManagerUpdates(); this.runDistanceManagerUpdates();
@ -1156,7 +1156,7 @@ index fc3565c1dd1c7f09bc885f1b0c9cf71477d64543..28761de0a4a460f74fbf6aca3f5d5ec8
} }
@Override @Override
@@ -750,7 +754,9 @@ public class ServerChunkCache extends ChunkSource { @@ -768,7 +772,9 @@ public class ServerChunkCache extends ChunkSource {
this.runDistanceManagerUpdates(); this.runDistanceManagerUpdates();
this.level.timings.doChunkMap.stopTiming(); // Spigot this.level.timings.doChunkMap.stopTiming(); // Spigot
this.level.getProfiler().popPush("chunks"); this.level.getProfiler().popPush("chunks");
@ -1166,7 +1166,7 @@ index fc3565c1dd1c7f09bc885f1b0c9cf71477d64543..28761de0a4a460f74fbf6aca3f5d5ec8
this.level.timings.doChunkUnload.startTiming(); // Spigot this.level.timings.doChunkUnload.startTiming(); // Spigot
this.level.getProfiler().popPush("unload"); this.level.getProfiler().popPush("unload");
this.chunkMap.tick(booleansupplier); this.chunkMap.tick(booleansupplier);
@@ -777,13 +783,16 @@ public class ServerChunkCache extends ChunkSource { @@ -795,13 +801,16 @@ public class ServerChunkCache extends ChunkSource {
boolean flag1 = level.ticksPerAnimalSpawns != 0L && worlddata.getGameTime() % level.ticksPerAnimalSpawns == 0L; // CraftBukkit boolean flag1 = level.ticksPerAnimalSpawns != 0L && worlddata.getGameTime() % level.ticksPerAnimalSpawns == 0L; // CraftBukkit
gameprofilerfiller.push("naturalSpawnCount"); gameprofilerfiller.push("naturalSpawnCount");
@ -1183,7 +1183,7 @@ index fc3565c1dd1c7f09bc885f1b0c9cf71477d64543..28761de0a4a460f74fbf6aca3f5d5ec8
while (iterator.hasNext()) { while (iterator.hasNext()) {
ChunkHolder playerchunk = (ChunkHolder) iterator.next(); ChunkHolder playerchunk = (ChunkHolder) iterator.next();
@@ -812,27 +821,27 @@ public class ServerChunkCache extends ChunkSource { @@ -830,27 +839,27 @@ public class ServerChunkCache extends ChunkSource {
} }
if (this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) { if (this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) {