Skip to content

Instantly share code, notes, and snippets.

@aikar
Created March 30, 2020 04:33
Show Gist options
  • Save aikar/dd676e5dfb2e6968980adb1a55e2a0ca to your computer and use it in GitHub Desktop.
Save aikar/dd676e5dfb2e6968980adb1a55e2a0ca to your computer and use it in GitHub Desktop.
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
index b6239e5fa6..d5339cea9a 100644
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -46,14 +46,31 @@ public class PlayerChunk {
// Paper start
int chunkPriority = -1;
int lastChunkPriority = -1;
+ boolean isUrgent = false;
+ java.util.List<PlayerChunk> urgentNeighbors = new java.util.ArrayList<>();
+ public void onNeighborRequest(PlayerChunk neighbor, ChunkStatus status) {
+ if (isUrgent) {
+ neighbor.markChunkUrgent();
+ this.urgentNeighbors.add(neighbor);
+ }
+ }
+
public void markChunkUrgent() {
- this.chunkPriority = 0;
this.lastChunkPriority = this.chunkPriority;
+ this.chunkPriority = this.ticketLevel - 20;
+ this.chunkMap.world.asyncChunkTaskManager.raisePriority(location.x, location.z, com.destroystokyo.paper.io.PrioritizedTaskQueue.HIGHEST_PRIORITY);
+ System.out.println("marking " + this + " as urgent: " + this.chunkPriority);
}
+
public void clearChunkUrgent() {
- if (this.chunkPriority == 0) {
+ if (this.isUrgent) {
this.chunkPriority = this.lastChunkPriority;
this.lastChunkPriority = -1;
+ this.isUrgent = false;
+ for (PlayerChunk urgentNeighbor : this.urgentNeighbors) {
+ urgentNeighbor.clearChunkUrgent();
+ }
+ this.urgentNeighbors.clear();
}
}
// Paper end
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index d9d56edbd3..d6266d7f4c 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -245,6 +245,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
List<CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> list = Lists.newArrayList();
int j = chunkcoordintpair.x;
int k = chunkcoordintpair.z;
+ PlayerChunk requestingNeighbor = this.requestingNeighbor; // Paper
for (int l = -i; l <= i; ++l) {
for (int i1 = -i; i1 <= i; ++i1) {
@@ -262,6 +263,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
}
ChunkStatus chunkstatus = (ChunkStatus) intfunction.apply(j1);
+ if (requestingNeighbor != null) requestingNeighbor.onNeighborRequest(playerchunk, chunkstatus); // Paper
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = playerchunk.a(chunkstatus, this);
list.add(completablefuture);
@@ -618,7 +620,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
ChunkCoordIntPair chunkcoordintpair = playerchunk.i();
if (chunkstatus == ChunkStatus.EMPTY) {
- return this.f(chunkcoordintpair);
+ return this.f(chunkcoordintpair, playerchunk); // Paper
} else {
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = playerchunk.a(chunkstatus.e(), this);
@@ -661,7 +663,8 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
}
// Paper end
- private CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> f(ChunkCoordIntPair chunkcoordintpair) {
+ private CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> f(ChunkCoordIntPair chunkcoordintpair) { return f(chunkcoordintpair, getUpdatingChunk(chunkcoordintpair.pair())); } // Paper
+ private CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> f(ChunkCoordIntPair chunkcoordintpair, PlayerChunk playerChunk) { // Paper
// Paper start - Async chunk io
final java.util.function.BiFunction<ChunkRegionLoader.InProgressChunkHolder, Throwable, Either<IChunkAccess, PlayerChunk.Failure>> syncLoadComplete = (chunkHolder, ioThrowable) -> {
try (Timing ignored = this.world.timings.syncChunkLoadTimer.startTimingIfSync()) { // Paper
@@ -705,23 +708,27 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
};
CompletableFuture<NBTTagCompound> chunkSaveFuture = this.world.asyncChunkTaskManager.getChunkSaveFuture(chunkcoordintpair.x, chunkcoordintpair.z);
- boolean isBlockingMain = MCUtil.isMainThread() && ChunkProviderServer.IS_CHUNK_LOAD_BLOCKING_MAIN;
+ boolean isBlockingMain = playerChunk != null && playerChunk.isUrgent;
int priority = isBlockingMain ? com.destroystokyo.paper.io.PrioritizedTaskQueue.HIGHEST_PRIORITY : com.destroystokyo.paper.io.PrioritizedTaskQueue.HIGH_PRIORITY;
if (chunkSaveFuture != null) {
this.world.asyncChunkTaskManager.scheduleChunkLoad(chunkcoordintpair.x, chunkcoordintpair.z, priority, chunkHolderConsumer, isBlockingMain, chunkSaveFuture);
- this.world.asyncChunkTaskManager.raisePriority(chunkcoordintpair.x, chunkcoordintpair.z, priority);
} else {
this.world.asyncChunkTaskManager.scheduleChunkLoad(chunkcoordintpair.x, chunkcoordintpair.z, priority, chunkHolderConsumer, isBlockingMain);
}
+ this.world.asyncChunkTaskManager.raisePriority(chunkcoordintpair.x, chunkcoordintpair.z, priority);
return ret;
// Paper end
}
+ private PlayerChunk requestingNeighbor; // Paper
private CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> b(PlayerChunk playerchunk, ChunkStatus chunkstatus) {
ChunkCoordIntPair chunkcoordintpair = playerchunk.i();
+ PlayerChunk prevNeighbor = requestingNeighbor; // Paper
+ this.requestingNeighbor = playerchunk; // Paper
CompletableFuture<Either<List<IChunkAccess>, PlayerChunk.Failure>> completablefuture = this.a(chunkcoordintpair, chunkstatus.f(), (i) -> {
return this.a(chunkstatus, i);
});
+ this.requestingNeighbor = prevNeighbor; // Paper
this.world.getMethodProfiler().c(() -> {
return "chunkGenerate " + chunkstatus.d();
@@ -882,9 +889,12 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
public CompletableFuture<Either<Chunk, PlayerChunk.Failure>> a(PlayerChunk playerchunk) {
ChunkCoordIntPair chunkcoordintpair = playerchunk.i();
+ PlayerChunk prevNeighbor = this.requestingNeighbor; // Paper
+ this.requestingNeighbor = playerchunk; // Paper
CompletableFuture<Either<List<IChunkAccess>, PlayerChunk.Failure>> completablefuture = this.a(chunkcoordintpair, 1, (i) -> {
return ChunkStatus.FULL;
});
+ this.requestingNeighbor = prevNeighbor; // Paper
CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture1 = completablefuture.thenApplyAsync((either) -> {
return either.flatMap((list) -> {
Chunk chunk = (Chunk) list.get(list.size() / 2);
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 20a2a2a8fb..f2dabbf1ab 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -10,6 +10,7 @@ import net.minecraft.server.Entity;
import net.minecraft.server.EntityAmbient;
import net.minecraft.server.EntityAnimal;
import net.minecraft.server.EntityArrow;
+import net.minecraft.server.EntityBee;
import net.minecraft.server.EntityComplexPart;
import net.minecraft.server.EntityCreature;
import net.minecraft.server.EntityCreeper;
@@ -231,6 +232,12 @@ public class ActivationRange
return 20; // Paper
}
// Paper start
+ if (entity instanceof EntityBee) {
+ EntityBee bee = (EntityBee)entity;
+ if (bee.getAnger() > 0 || (bee.hivePos != null && bee.hivePos.equals(bee.getMovingTarget()))) {
+ return 20;
+ }
+ }
if ( entity instanceof EntityVillager && ( (EntityVillager) entity ).canBreed() )
{
BehaviorController<EntityVillager> behaviorController = ((EntityVillager) entity).getBehaviorController();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment