papermc/patches/server/0369-No-Tick-view-distance-implementation.patch

718 lines
42 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 5 May 2020 21:23:34 -0700
Subject: [PATCH] No-Tick view distance implementation
Implements world view distance getters/setters
Per-Player is absent due to difficulty of maintaining
the diff required to make it happen.
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
2021-06-13 19:29:58 +00:00
index f27fadc15cb7f5c782e45885ec6a5a69963beade..2ff4d4921e2076abf415bd3c8f5173ecd6222168 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/co/aikar/timings/TimingsExport.java
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
2021-06-13 19:29:58 +00:00
@@ -152,7 +152,8 @@ public class TimingsExport extends Thread {
2021-06-11 12:02:28 +00:00
pair("gamerules", toObjectMapper(world.getWorld().getGameRules(), rule -> {
return pair(rule, world.getWorld().getGameRuleValue(rule));
})),
2021-06-13 19:29:58 +00:00
- pair("ticking-distance", world.getChunkSource().chunkMap.getEffectiveViewDistance())
+ pair("ticking-distance", world.getChunkSource().chunkMap.getEffectiveViewDistance()),
+ pair("notick-viewdistance", world.getChunkSource().chunkMap.getEffectiveNoTickViewDistance())
2021-06-11 12:02:28 +00:00
));
}));
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2021-06-16 13:14:19 +00:00
index b8ca1f73b2451307c3711076eaa43e2adb34d92e..45e30c0d78b7625a6a55e6d7d60a823b674b75db 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2021-06-16 06:25:38 +00:00
@@ -487,6 +487,11 @@ public class PaperWorldConfig {
2021-06-13 19:29:58 +00:00
lightQueueSize = getInt("light-queue-size", lightQueueSize);
2021-06-11 12:02:28 +00:00
}
2021-06-15 13:20:52 +00:00
2021-06-11 12:02:28 +00:00
+ public int noTickViewDistance;
+ private void viewDistance() {
+ this.noTickViewDistance = this.getInt("viewdistances.no-tick-view-distance", -1);
+ }
2021-06-15 13:20:52 +00:00
+
public boolean antiXray;
public EngineMode engineMode;
2021-06-16 13:14:19 +00:00
public int maxBlockHeight;
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
2021-06-13 19:29:58 +00:00
index bb0a07a280c7d4885165e9d6488e7741aaa7b47c..9c88426ab1275ee5fb6e28be8b213533dc4ab859 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java
2021-06-13 19:29:58 +00:00
@@ -636,7 +636,8 @@ public final class MCUtil {
2021-06-11 12:02:28 +00:00
});
worldData.addProperty("name", world.getWorld().getName());
- worldData.addProperty("view-distance", world.spigotConfig.viewDistance);
+ worldData.addProperty("view-distance", world.getChunkSource().chunkMap.getEffectiveViewDistance());
+ worldData.addProperty("no-view-distance", world.getChunkSource().chunkMap.getRawNoTickViewDistance());
worldData.addProperty("keep-spawn-loaded", world.keepSpawnInMemory);
worldData.addProperty("keep-spawn-loaded-range", world.paperConfig.keepLoadedRange);
worldData.addProperty("visible-chunk-count", visibleChunks.size());
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
2021-06-15 22:24:12 +00:00
index 2aa86f35b8960273ad91b21e260bcf91cf861e08..8fff5580a88fd1643845967eb7bdab2630777e91 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
2021-06-13 19:29:58 +00:00
@@ -75,6 +75,17 @@ public class ChunkHolder {
2021-06-11 12:02:28 +00:00
2021-06-13 19:29:58 +00:00
boolean isUpdateQueued = false; // Paper
private final ChunkMap chunkMap; // Paper
2021-06-11 12:02:28 +00:00
+ // Paper start - no-tick view distance
+ public final LevelChunk getSendingChunk() {
+ // it's important that we use getChunkAtIfLoadedImmediately to mirror the chunk sending logic used
+ // in Chunk's neighbour callback
+ LevelChunk ret = this.chunkMap.level.getChunkSource().getChunkAtIfLoadedImmediately(this.pos.x, this.pos.z);
+ if (ret != null && ret.areNeighboursLoaded(1)) {
+ return ret;
+ }
+ return null;
+ }
+ // Paper end - no-tick view distance
2021-06-13 19:29:58 +00:00
public ChunkHolder(ChunkPos pos, int level, LevelHeightAccessor world, LevelLightEngine lightingProvider, ChunkHolder.LevelChangeListener levelUpdateListener, ChunkHolder.PlayerProvider playersWatchingChunkProvider) {
2021-06-11 12:02:28 +00:00
this.futures = new AtomicReferenceArray(ChunkHolder.CHUNK_STATUSES.size());
2021-06-13 19:29:58 +00:00
@@ -207,7 +218,7 @@ public class ChunkHolder {
2021-06-11 12:02:28 +00:00
}
2021-06-13 19:29:58 +00:00
public void blockChanged(BlockPos pos) {
2021-06-11 12:02:28 +00:00
- LevelChunk chunk = this.getTickingChunk();
+ LevelChunk chunk = this.getSendingChunk(); // Paper - no-tick view distance
if (chunk != null) {
2021-06-13 19:29:58 +00:00
int i = this.levelHeightAccessor.getSectionIndex(pos.getY());
@@ -223,7 +234,7 @@ public class ChunkHolder {
2021-06-11 12:02:28 +00:00
}
2021-06-13 19:29:58 +00:00
public void sectionLightChanged(LightLayer lightType, int y) {
2021-06-11 12:02:28 +00:00
- LevelChunk chunk = this.getTickingChunk();
+ LevelChunk chunk = this.getSendingChunk(); // Paper - no-tick view distance
if (chunk != null) {
chunk.setUnsaved(true);
2021-06-13 19:29:58 +00:00
@@ -313,9 +324,48 @@ public class ChunkHolder {
2021-06-11 12:02:28 +00:00
}
2021-06-15 22:24:12 +00:00
public void broadcast(Packet<?> packet, boolean onlyOnWatchDistanceEdge) {
2021-06-11 12:02:28 +00:00
- this.playerProvider.getPlayers(this.pos, onlyOnWatchDistanceEdge).forEach((entityplayer) -> {
- entityplayer.connection.send(packet);
- });
+ // Paper start - per player view distance
+ // there can be potential desync with player's last mapped section and the view distance map, so use the
+ // view distance map here.
+ com.destroystokyo.paper.util.misc.PlayerAreaMap viewDistanceMap = this.chunkMap.playerViewDistanceBroadcastMap;
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> players = viewDistanceMap.getObjectsInRange(this.pos);
+ if (players == null) {
+ return;
+ }
+
+ if (onlyOnWatchDistanceEdge) { // flag -> border only
+ Object[] backingSet = players.getBackingSet();
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
+ Object temp = backingSet[i];
+ if (!(temp instanceof ServerPlayer)) {
+ continue;
+ }
+ ServerPlayer player = (ServerPlayer)temp;
+
+ int viewDistance = viewDistanceMap.getLastViewDistance(player);
+ long lastPosition = viewDistanceMap.getLastCoordinate(player);
+
2021-06-13 19:29:58 +00:00
+ int distX = Math.abs(net.minecraft.server.MCUtil.getCoordinateX(lastPosition) - this.pos.x);
+ int distZ = Math.abs(net.minecraft.server.MCUtil.getCoordinateZ(lastPosition) - this.pos.z);
2021-06-11 12:02:28 +00:00
+
+ if (Math.max(distX, distZ) == viewDistance) {
+ player.connection.send(packet);
+ }
+ }
+ } else {
+ Object[] backingSet = players.getBackingSet();
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
+ Object temp = backingSet[i];
+ if (!(temp instanceof ServerPlayer)) {
+ continue;
+ }
+ ServerPlayer player = (ServerPlayer)temp;
+ player.connection.send(packet);
+ }
+ }
+
+ return;
+ // Paper end - per player view distance
}
public CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getOrScheduleFuture(ChunkStatus targetStatus, ChunkMap chunkStorage) {
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 4123f529e0bbd97a6a25a08e6e8d129c5e322eb7..4af8caff4231fbb8e1997dfa5479cf8fa932f0f4 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
2021-06-16 06:25:38 +00:00
@@ -127,7 +127,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
private boolean modified;
private final ChunkTaskPriorityQueueSorter queueSorter;
private final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> worldgenMailbox;
- private final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> mainThreadMailbox;
+ public final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> mainThreadMailbox; // Paper - private -> public
2021-06-13 19:29:58 +00:00
// Paper start
final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> mailboxLight;
public void addLightTask(ChunkHolder playerchunk, Runnable run) {
2021-06-16 06:25:38 +00:00
@@ -169,21 +169,68 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-13 19:29:58 +00:00
// Paper start - distance maps
private final com.destroystokyo.paper.util.misc.PooledLinkedHashSets<ServerPlayer> pooledLinkedPlayerHashSets = new com.destroystokyo.paper.util.misc.PooledLinkedHashSets<>();
2021-06-11 12:02:28 +00:00
+ // Paper start - no-tick view distance
+ int noTickViewDistance;
+ public final int getRawNoTickViewDistance() {
+ return this.noTickViewDistance;
+ }
+ public final int getEffectiveNoTickViewDistance() {
+ return this.noTickViewDistance == -1 ? this.getEffectiveViewDistance() : this.noTickViewDistance;
+ }
+ public final int getLoadViewDistance() {
+ return Math.max(this.getEffectiveViewDistance(), this.getEffectiveNoTickViewDistance());
+ }
+
+ public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerViewDistanceBroadcastMap;
+ public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerViewDistanceTickMap;
+ public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerViewDistanceNoTickMap;
+ // Paper end - no-tick view distance
void addPlayerToDistanceMaps(ServerPlayer player) {
int chunkX = MCUtil.getChunkCoordinate(player.getX());
2021-06-13 19:29:58 +00:00
int chunkZ = MCUtil.getChunkCoordinate(player.getZ());
// Note: players need to be explicitly added to distance maps before they can be updated
2021-06-11 12:02:28 +00:00
+ // Paper start - no-tick view distance
+ int effectiveTickViewDistance = this.getEffectiveViewDistance();
+ int effectiveNoTickViewDistance = Math.max(this.getEffectiveNoTickViewDistance(), effectiveTickViewDistance);
+
2021-06-13 19:29:58 +00:00
+ if (!this.skipPlayer(player)) {
2021-06-11 12:02:28 +00:00
+ this.playerViewDistanceTickMap.add(player, chunkX, chunkZ, effectiveTickViewDistance);
+ this.playerViewDistanceNoTickMap.add(player, chunkX, chunkZ, effectiveNoTickViewDistance + 2); // clients need chunk 1 neighbour, and we need another 1 for sending those extra neighbours (as we require neighbours to send)
+ }
+
+ player.needsChunkCenterUpdate = true;
+ this.playerViewDistanceBroadcastMap.add(player, chunkX, chunkZ, effectiveNoTickViewDistance + 1); // clients need an extra neighbour to render the full view distance configured
+ player.needsChunkCenterUpdate = false;
+ // Paper end - no-tick view distance
}
void removePlayerFromDistanceMaps(ServerPlayer player) {
2021-06-13 19:29:58 +00:00
2021-06-11 12:02:28 +00:00
+ // Paper start - no-tick view distance
+ this.playerViewDistanceBroadcastMap.remove(player);
+ this.playerViewDistanceTickMap.remove(player);
+ this.playerViewDistanceNoTickMap.remove(player);
+ // Paper end - no-tick view distance
}
void updateMaps(ServerPlayer player) {
2021-06-13 19:29:58 +00:00
int chunkX = MCUtil.getChunkCoordinate(player.getX());
int chunkZ = MCUtil.getChunkCoordinate(player.getZ());
// Note: players need to be explicitly added to distance maps before they can be updated
2021-06-11 12:02:28 +00:00
+ // Paper start - no-tick view distance
+ int effectiveTickViewDistance = this.getEffectiveViewDistance();
+ int effectiveNoTickViewDistance = Math.max(this.getEffectiveNoTickViewDistance(), effectiveTickViewDistance);
+
2021-06-13 19:29:58 +00:00
+ if (!this.skipPlayer(player)) {
2021-06-11 12:02:28 +00:00
+ this.playerViewDistanceTickMap.update(player, chunkX, chunkZ, effectiveTickViewDistance);
+ this.playerViewDistanceNoTickMap.update(player, chunkX, chunkZ, effectiveNoTickViewDistance + 2); // clients need chunk 1 neighbour, and we need another 1 for sending those extra neighbours (as we require neighbours to send)
+ }
+
+ player.needsChunkCenterUpdate = true;
+ this.playerViewDistanceBroadcastMap.update(player, chunkX, chunkZ, effectiveNoTickViewDistance + 1); // clients need an extra neighbour to render the full view distance configured
+ player.needsChunkCenterUpdate = false;
+ // Paper end - no-tick view distance
}
// Paper end
2021-06-16 06:25:38 +00:00
@@ -221,6 +268,45 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-13 19:29:58 +00:00
this.overworldDataStorage = persistentStateManagerFactory;
this.poiManager = new PoiManager(new File(this.storageFolder, "poi"), dataFixer, dsync, world);
this.setViewDistance(viewDistance);
2021-06-11 12:02:28 +00:00
+ // Paper start - no-tick view distance
+ this.setNoTickViewDistance(this.level.paperConfig.noTickViewDistance);
+ this.playerViewDistanceTickMap = new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets,
+ (ServerPlayer player, int rangeX, int rangeZ, int currPosX, int currPosZ, int prevPosX, int prevPosZ,
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> newState) -> {
+ if (newState.size() != 1) {
+ return;
+ }
+ LevelChunk chunk = ChunkMap.this.level.getChunkSource().getChunkAtIfLoadedMainThreadNoCache(rangeX, rangeZ);
+ if (chunk == null || !chunk.areNeighboursLoaded(2)) {
+ return;
+ }
+
+ ChunkPos chunkPos = new ChunkPos(rangeX, rangeZ);
+ ChunkMap.this.level.getChunkSource().addTicketAtLevel(TicketType.PLAYER, chunkPos, 31, chunkPos); // entity ticking level, TODO check on update
+ },
+ (ServerPlayer player, int rangeX, int rangeZ, int currPosX, int currPosZ, int prevPosX, int prevPosZ,
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> newState) -> {
+ if (newState != null) {
+ return;
+ }
+ ChunkPos chunkPos = new ChunkPos(rangeX, rangeZ);
+ ChunkMap.this.level.getChunkSource().removeTicketAtLevel(TicketType.PLAYER, chunkPos, 31, chunkPos); // entity ticking level, TODO check on update
+ });
+ this.playerViewDistanceNoTickMap = new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets);
+ this.playerViewDistanceBroadcastMap = new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets,
+ (ServerPlayer player, int rangeX, int rangeZ, int currPosX, int currPosZ, int prevPosX, int prevPosZ,
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> newState) -> {
+ if (player.needsChunkCenterUpdate) {
+ player.needsChunkCenterUpdate = false;
+ player.connection.send(new ClientboundSetChunkCacheCenterPacket(currPosX, currPosZ));
+ }
+ ChunkMap.this.updateChunkTracking(player, new ChunkPos(rangeX, rangeZ), new Packet[2], false, true); // unloaded, loaded
+ },
+ (ServerPlayer player, int rangeX, int rangeZ, int currPosX, int currPosZ, int prevPosX, int prevPosZ,
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> newState) -> {
+ ChunkMap.this.updateChunkTracking(player, new ChunkPos(rangeX, rangeZ), null, true, false); // unloaded, loaded
+ });
+ // Paper end - no-tick view distance
}
2021-06-13 19:29:58 +00:00
private static double euclideanDistanceSquared(ChunkPos pos, Entity entity) {
2021-06-16 06:25:38 +00:00
@@ -906,14 +992,10 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
completablefuture1.thenAcceptAsync((either) -> {
2021-06-13 19:29:58 +00:00
either.ifLeft((chunk) -> {
2021-06-11 12:02:28 +00:00
this.tickingGenerated.getAndIncrement();
- Packet<?>[] apacket = new Packet[2];
-
- this.getPlayers(chunkcoordintpair, false).forEach((entityplayer) -> {
- this.playerLoadedChunk(entityplayer, apacket, chunk);
- });
+ // Paper - no-tick view distance - moved to Chunk neighbour update
});
}, (runnable) -> {
- this.mainThreadMailbox.tell(ChunkTaskPriorityQueueSorter.message(holder, runnable));
+ this.mainThreadMailbox.tell(ChunkTaskPriorityQueueSorter.message(holder, runnable)); // Paper - diff on change, this is the scheduling method copied in Chunk used to schedule chunk broadcasts (on change it needs to be copied again)
});
return completablefuture1;
}
2021-06-16 06:25:38 +00:00
@@ -1006,27 +1088,34 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
}
2021-06-15 22:24:12 +00:00
public void setViewDistance(int watchDistance) {
2021-06-11 12:02:28 +00:00
- int j = Mth.clamp(watchDistance + 1, 3, 33);
+ int j = Mth.clamp(watchDistance + 1, 3, 33); // Paper - diff on change, these make the lower view distance limit 2 and the upper 32
if (j != this.viewDistance) {
int k = this.viewDistance;
this.viewDistance = j;
- this.distanceManager.updatePlayerTickets(this.viewDistance);
- ObjectIterator objectiterator = this.updatingChunkMap.values().iterator();
+ this.setNoTickViewDistance(this.getRawNoTickViewDistance()); //Paper - no-tick view distance - propagate changes to no-tick, which does the actual chunk loading/sending
+ }
- while (objectiterator.hasNext()) {
- ChunkHolder playerchunk = (ChunkHolder) objectiterator.next();
- ChunkPos chunkcoordintpair = playerchunk.getPos();
- Packet<?>[] apacket = new Packet[2];
+ }
- this.getPlayers(chunkcoordintpair, false).forEach((entityplayer) -> {
2021-06-13 19:29:58 +00:00
- int l = ChunkMap.checkerboardDistance(chunkcoordintpair, entityplayer, true);
2021-06-11 12:02:28 +00:00
- boolean flag = l <= k;
- boolean flag1 = l <= this.viewDistance;
+ // Paper start - no-tick view distance
+ public final void setNoTickViewDistance(int viewDistance) {
+ viewDistance = viewDistance == -1 ? -1 : Mth.clamp(viewDistance, 2, 32);
- this.updateChunkTracking(entityplayer, chunkcoordintpair, apacket, flag, flag1);
- });
+ this.noTickViewDistance = viewDistance;
+ int loadViewDistance = this.getLoadViewDistance();
+ this.distanceManager.setNoTickViewDistance(loadViewDistance + 2 + 2); // add 2 to account for the change to 31 -> 33 tickets // see notes in the distance map updating for the other + 2
+
+ if (this.level != null && this.level.players != null) { // this can be called from constructor, where these aren't set
+ for (ServerPlayer player : this.level.players) {
2021-06-13 19:29:58 +00:00
+ net.minecraft.server.network.ServerGamePacketListenerImpl connection = player.connection;
2021-06-11 12:02:28 +00:00
+ if (connection != null) {
+ // moved in from PlayerList
2021-06-13 19:29:58 +00:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundSetChunkCacheRadiusPacket(loadViewDistance));
2021-06-11 12:02:28 +00:00
+ }
+ this.updateMaps(player);
2021-06-13 19:29:58 +00:00
+ // Paper end - no-tick view distance
2021-06-11 12:02:28 +00:00
}
}
2021-06-16 06:25:38 +00:00
@@ -1038,7 +1127,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
ChunkHolder playerchunk = this.getVisibleChunkIfPresent(pos.toLong());
if (playerchunk != null) {
- LevelChunk chunk = playerchunk.getTickingChunk();
+ LevelChunk chunk = playerchunk.getSendingChunk(); // Paper - no-tick view distance
if (chunk != null) {
this.playerLoadedChunk(player, packets, chunk);
2021-06-16 06:25:38 +00:00
@@ -1134,7 +1223,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-15 22:24:12 +00:00
// Paper end
@Nullable
- public CompoundTag readChunk(ChunkPos pos) throws IOException { // Paper - private -> public
+ public CompoundTag readChunk(ChunkPos pos) throws IOException {
CompoundTag nbttagcompound = this.read(pos);
// Paper start - Cache chunk status on disk
if (nbttagcompound == null) {
2021-06-16 06:25:38 +00:00
@@ -1245,13 +1334,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
this.removePlayerFromDistanceMaps(player); // Paper - distance maps
}
- for (int k = i - this.viewDistance; k <= i + this.viewDistance; ++k) {
- for (int l = j - this.viewDistance; l <= j + this.viewDistance; ++l) {
- ChunkPos chunkcoordintpair = new ChunkPos(k, l);
-
- this.updateChunkTracking(player, chunkcoordintpair, new Packet[2], !added, added);
- }
- }
+ // Paper - broadcast view distance map handles this (see remove/add calls above)
}
2021-06-16 06:25:38 +00:00
@@ -1259,7 +1342,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-13 19:29:58 +00:00
SectionPos sectionposition = SectionPos.of((Entity) player);
2021-06-11 12:02:28 +00:00
2021-06-13 19:29:58 +00:00
player.setLastSectionPos(sectionposition);
- player.connection.send(new ClientboundSetChunkCacheCenterPacket(sectionposition.x(), sectionposition.z()));
+ // player.connection.send(new ClientboundSetChunkCacheCenterPacket(sectionposition.x(), sectionposition.z())); // Paper - distance map handles this now
2021-06-11 12:02:28 +00:00
return sectionposition;
}
2021-06-16 06:25:38 +00:00
@@ -1314,6 +1397,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
int k1;
int l1;
+ /* // Paper start - replaced by distance map
if (Math.abs(i1 - i) <= this.viewDistance * 2 && Math.abs(j1 - j) <= this.viewDistance * 2) {
k1 = Math.min(i, i1) - this.viewDistance;
l1 = Math.min(j, j1) - this.viewDistance;
2021-06-16 06:25:38 +00:00
@@ -1352,6 +1436,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
}
}
2021-06-13 19:29:58 +00:00
}
+ */ // Paper end - replaced by distance map
2021-06-11 12:02:28 +00:00
this.updateMaps(player); // Paper - distance maps
2021-06-16 06:25:38 +00:00
@@ -1359,11 +1444,46 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
@Override
public Stream<ServerPlayer> getPlayers(ChunkPos chunkPos, boolean onlyOnWatchDistanceEdge) {
2021-06-13 19:29:58 +00:00
- return this.playerMap.getPlayers(chunkPos.toLong()).filter((entityplayer) -> {
- int i = ChunkMap.checkerboardDistance(chunkPos, entityplayer, true);
2021-06-16 06:25:38 +00:00
-
- return i > this.viewDistance ? false : !onlyOnWatchDistanceEdge || i == this.viewDistance;
- });
2021-06-11 12:02:28 +00:00
+ // Paper start - per player view distance
+ // there can be potential desync with player's last mapped section and the view distance map, so use the
+ // view distance map here.
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> inRange = this.playerViewDistanceBroadcastMap.getObjectsInRange(chunkPos);
2021-06-16 06:25:38 +00:00
+
2021-06-11 12:02:28 +00:00
+ if (inRange == null) {
+ return Stream.empty();
+ }
+ // all current cases are inlined so we wont hit this code, it's just in case plugins or future updates use it
+ List<ServerPlayer> players = new java.util.ArrayList<>();
+ Object[] backingSet = inRange.getBackingSet();
+
+ if (onlyOnWatchDistanceEdge) { // flag -> border only
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
+ Object temp = backingSet[i];
+ if (!(temp instanceof ServerPlayer)) {
+ continue;
+ }
+ ServerPlayer player = (ServerPlayer)temp;
+ int viewDistance = this.playerViewDistanceBroadcastMap.getLastViewDistance(player);
+ long lastPosition = this.playerViewDistanceBroadcastMap.getLastCoordinate(player);
+
+ int distX = Math.abs(MCUtil.getCoordinateX(lastPosition) - chunkPos.x);
+ int distZ = Math.abs(MCUtil.getCoordinateZ(lastPosition) - chunkPos.z);
+ if (Math.max(distX, distZ) == viewDistance) {
+ players.add(player);
+ }
+ }
+ } else {
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
+ Object temp = backingSet[i];
+ if (!(temp instanceof ServerPlayer)) {
+ continue;
+ }
+ ServerPlayer player = (ServerPlayer)temp;
+ players.add(player);
+ }
+ }
+ return players.stream();
+ // Paper end - per player view distance
}
2021-06-15 22:24:12 +00:00
public void addEntity(Entity entity) {
2021-06-16 06:25:38 +00:00
@@ -1485,6 +1605,47 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
}
+ // Paper start
+ private static int getLightMask(final LevelChunk chunk) {
2021-06-13 19:29:58 +00:00
+ final net.minecraft.world.level.chunk.LevelChunkSection[] chunkSections = chunk.getSections();
2021-06-11 12:02:28 +00:00
+ int mask = 0;
+
+ for (int i = 0; i < chunkSections.length; ++i) {
+ /*
+
+
+Lightmasks have 18 bits, from the -1 (void) section until the 17th (air) section.
+Sections go from 0..16. Now whenever a section is not empty, it can potentially change lighting for the section itself, the section below and the section above, hence the bitmask 111b, which is 7d.
+
+ */
2021-06-13 19:29:58 +00:00
+ mask |= (net.minecraft.world.level.chunk.LevelChunkSection.isEmpty(chunkSections[i]) ? 0 : 7) << i;
2021-06-11 12:02:28 +00:00
+ }
+
+ return mask;
+ }
+
+ private static int getCeilingLightMask(final LevelChunk chunk) {
+ int mask = getLightMask(chunk);
+
+ /*
+ It is similar to get highest bit, it would turn an 001010 into an 001111 so basically the highest bit and all below.
+ We then invert this, so we'd have 110000 and compare that to the "main" chunk.
+ This is because the bug only appears when the current chunks lightmaps are higher than those of the neighbors, thus we can omit sending neighbors which are lower than the current chunks lights.
+
+ so TLDR is that getCeilingLightMask returns a light mask with all bits set below the highest affected section. We could also count the number of leading zeros and invert them, somehow.
+ @TODO: Implement Leafs suggestion
+ either use Integer#numberOfLeadingZeros or document what this bithack is supposed to be doing then
+ */
+ mask |= mask >> 1;
+ mask |= mask >> 2;
+ mask |= mask >> 4;
+ mask |= mask >> 8;
+ mask |= mask >> 16;
+
+ return mask;
+ }
+ // Paper end
+
2021-06-15 22:24:12 +00:00
public void playerLoadedChunk(ServerPlayer player, Packet<?>[] packets, LevelChunk chunk) {
2021-06-11 12:02:28 +00:00
if (packets[0] == null) {
2021-06-15 13:20:52 +00:00
packets[0] = new ClientboundLevelChunkPacket(chunk, chunk.level.chunkPacketBlockController.shouldModify(player, chunk)); // Paper - Ani-Xray - Bypass
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
2021-06-13 19:29:58 +00:00
index 45c7ebe67019cdbe88b6617a95d5c40d3a68286c..38eebda226e007c8910e04f502ce218cdfe1d456 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/level/DistanceManager.java
+++ b/src/main/java/net/minecraft/server/level/DistanceManager.java
2021-06-13 19:29:58 +00:00
@@ -275,8 +275,8 @@ public abstract class DistanceManager {
2021-06-11 12:02:28 +00:00
return s;
}
- protected void updatePlayerTickets(int viewDistance) {
- this.playerTicketManager.updateViewDistance(viewDistance);
+ protected void setNoTickViewDistance(int i) { // Paper - force abi breakage on usage change
+ this.playerTicketManager.updateViewDistance(i);
}
public int getNaturalSpawnChunkCount() {
2021-06-13 19:29:58 +00:00
@@ -503,7 +503,7 @@ public abstract class DistanceManager {
2021-06-11 12:02:28 +00:00
private void onLevelChange(long pos, int distance, boolean oldWithinViewDistance, boolean withinViewDistance) {
if (oldWithinViewDistance != withinViewDistance) {
- Ticket<?> ticket = new Ticket<>(TicketType.PLAYER, DistanceManager.PLAYER_TICKET_LEVEL, new ChunkPos(pos));
+ Ticket<?> ticket = new Ticket<>(TicketType.PLAYER, 33, new ChunkPos(pos)); // Paper - no-tick view distance
if (withinViewDistance) {
DistanceManager.this.ticketThrottlerInput.tell(ChunkTaskPriorityQueueSorter.message(() -> {
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2021-06-15 22:24:12 +00:00
index 54cc0391f77d90a206e9fb2422ea31d5b9ee22af..648e7b258eef32213c512781faffa840eedebec6 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2021-06-13 19:29:58 +00:00
@@ -241,6 +241,7 @@ public class ServerPlayer extends Player {
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
2021-06-11 12:02:28 +00:00
2021-06-13 19:29:58 +00:00
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
2021-06-11 12:02:28 +00:00
+ boolean needsChunkCenterUpdate; // Paper - no-tick view distance
2021-06-13 19:29:58 +00:00
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2021-06-13 19:29:58 +00:00
index bcc946d2747443c34ee8ac2485a5ab41773c93af..2730923bd0bf3b0f928765b9e09e2299fa9a393d 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2021-06-13 19:29:58 +00:00
@@ -241,7 +241,7 @@ public abstract class PlayerList {
2021-06-11 12:02:28 +00:00
boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO);
// Spigot - view distance
- playerconnection.send(new ClientboundLoginPacket(player.getId(), player.gameMode.getGameModeForPlayer(), player.gameMode.getPreviousGameModeForPlayer(), BiomeManager.obfuscateSeed(worldserver1.getSeed()), worlddata.isHardcore(), this.server.levelKeys(), this.registryHolder, worldserver1.dimensionType(), worldserver1.dimension(), this.getMaxPlayers(), worldserver1.spigotConfig.viewDistance, flag1, !flag, worldserver1.isDebug(), worldserver1.isFlat()));
+ playerconnection.send(new ClientboundLoginPacket(player.getId(), player.gameMode.getGameModeForPlayer(), player.gameMode.getPreviousGameModeForPlayer(), BiomeManager.obfuscateSeed(worldserver1.getSeed()), worlddata.isHardcore(), this.server.levelKeys(), this.registryHolder, worldserver1.dimensionType(), worldserver1.dimension(), this.getMaxPlayers(), worldserver1.getChunkSource().chunkMap.getLoadViewDistance(), flag1, !flag, worldserver1.isDebug(), worldserver1.isFlat())); // Paper - no-tick view distance
player.getBukkitEntity().sendSupportedChannels(); // CraftBukkit
playerconnection.send(new ClientboundCustomPayloadPacket(ClientboundCustomPayloadPacket.BRAND, (new FriendlyByteBuf(Unpooled.buffer())).writeUtf(this.getServer().getServerModName())));
playerconnection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
2021-06-13 19:29:58 +00:00
@@ -789,7 +789,7 @@ public abstract class PlayerList {
2021-06-11 12:02:28 +00:00
// CraftBukkit start
LevelData worlddata = worldserver1.getLevelData();
entityplayer1.connection.send(new ClientboundRespawnPacket(worldserver1.dimensionType(), worldserver1.dimension(), BiomeManager.obfuscateSeed(worldserver1.getSeed()), entityplayer1.gameMode.getGameModeForPlayer(), entityplayer1.gameMode.getPreviousGameModeForPlayer(), worldserver1.isDebug(), worldserver1.isFlat(), flag));
- entityplayer1.connection.send(new ClientboundSetChunkCacheRadiusPacket(worldserver1.spigotConfig.viewDistance)); // Spigot
+ entityplayer1.connection.send(new ClientboundSetChunkCacheRadiusPacket(worldserver1.getChunkSource().chunkMap.getLoadViewDistance())); // Spigot // Paper - no-tick view distance
entityplayer1.setLevel(worldserver1);
2021-06-13 19:29:58 +00:00
entityplayer1.unsetRemoved();
entityplayer1.connection.teleport(new Location(worldserver1.getWorld(), entityplayer1.getX(), entityplayer1.getY(), entityplayer1.getZ(), entityplayer1.getYRot(), entityplayer1.getXRot()));
@@ -1273,7 +1273,7 @@ public abstract class PlayerList {
2021-06-11 12:02:28 +00:00
public void setViewDistance(int viewDistance) {
this.viewDistance = viewDistance;
- this.broadcastAll(new ClientboundSetChunkCacheRadiusPacket(viewDistance));
+ //this.sendAll(new PacketPlayOutViewDistance(i)); // Paper - move into setViewDistance
Iterator iterator = this.server.getAllLevels().iterator();
while (iterator.hasNext()) {
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2021-06-16 04:53:50 +00:00
index 603db501fe8491539edb2564a312fe69f9e07a63..4569aa6df0ef596f185235bfedb1ce058d1da62b 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2021-06-15 13:20:52 +00:00
@@ -527,8 +527,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 12:02:28 +00:00
this.setBlocksDirty(blockposition, iblockdata1, iblockdata2);
}
- if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(ChunkHolder.FullChunkStatus.TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement
+ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(ChunkHolder.FullChunkStatus.TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement // Paper - diff on change, see below
this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i);
+ // Paper start - per player view distance - allow block updates for non-ticking chunks in player view distance
+ // if copied from above
+ } else if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || ((ServerLevel)this).getChunkSource().chunkMap.playerViewDistanceBroadcastMap.getObjectsInRange(MCUtil.getCoordinateKey(blockposition)) != null)) {
+ ((ServerLevel)this).getChunkSource().blockChanged(blockposition);
+ // Paper end - per player view distance
}
if ((i & 1) != 0) {
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
2021-06-15 22:24:12 +00:00
index 164df6e9a91d9fbdbf6e4b835ea1946d81f3be55..a088cb005525fda2c9d5521ab3bac43cfa38a393 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
2021-06-13 19:29:58 +00:00
@@ -33,7 +33,10 @@ import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
2021-06-11 12:02:28 +00:00
import net.minecraft.nbt.CompoundTag;
2021-06-13 19:29:58 +00:00
import net.minecraft.network.FriendlyByteBuf;
2021-06-11 12:02:28 +00:00
+import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.ChunkHolder;
+import net.minecraft.server.level.ChunkMap;
+import net.minecraft.server.level.ChunkTaskPriorityQueueSorter;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
2021-06-13 19:29:58 +00:00
import net.minecraft.util.profiling.ProfilerFiller;
@@ -227,7 +230,51 @@ public class LevelChunk implements ChunkAccess {
2021-06-11 12:02:28 +00:00
}
protected void onNeighbourChange(final long bitsetBefore, final long bitsetAfter) {
+ // Paper start - no-tick view distance
2021-06-13 19:29:58 +00:00
+ ServerChunkCache chunkProviderServer = ((ServerLevel)this.level).getChunkSource();
2021-06-11 12:02:28 +00:00
+ ChunkMap chunkMap = chunkProviderServer.chunkMap;
+ // this code handles the addition of ticking tickets - the distance map handles the removal
+ if (!areNeighboursLoaded(bitsetBefore, 2) && areNeighboursLoaded(bitsetAfter, 2)) {
+ if (chunkMap.playerViewDistanceTickMap.getObjectsInRange(this.coordinateKey) != null) {
+ // now we're ready for entity ticking
+ chunkProviderServer.mainThreadProcessor.execute(() -> {
+ // double check that this condition still holds.
+ if (LevelChunk.this.areNeighboursLoaded(2) && chunkMap.playerViewDistanceTickMap.getObjectsInRange(LevelChunk.this.coordinateKey) != null) {
2021-06-13 19:29:58 +00:00
+ chunkProviderServer.addTicketAtLevel(net.minecraft.server.level.TicketType.PLAYER, LevelChunk.this.chunkPos, 31, LevelChunk.this.chunkPos); // 31 -> entity ticking, TODO check on update
2021-06-11 12:02:28 +00:00
+ }
+ });
+ }
+ }
+ // this code handles the chunk sending
+ if (!areNeighboursLoaded(bitsetBefore, 1) && areNeighboursLoaded(bitsetAfter, 1)) {
+ if (chunkMap.playerViewDistanceBroadcastMap.getObjectsInRange(this.coordinateKey) != null) {
+ // now we're ready to send
+ chunkMap.mainThreadMailbox.tell(ChunkTaskPriorityQueueSorter.message(chunkMap.getUpdatingChunkIfPresent(this.coordinateKey), (() -> { // Copied frm PlayerChunkMap
+ // double check that this condition still holds.
+ if (!LevelChunk.this.areNeighboursLoaded(1)) {
+ return;
+ }
2021-06-13 19:29:58 +00:00
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<net.minecraft.server.level.ServerPlayer> inRange = chunkMap.playerViewDistanceBroadcastMap.getObjectsInRange(LevelChunk.this.coordinateKey);
2021-06-11 12:02:28 +00:00
+ if (inRange == null) {
+ return;
+ }
+
+ // broadcast
+ Object[] backingSet = inRange.getBackingSet();
+ Packet[] chunkPackets = new Packet[2];
+ for (int index = 0, len = backingSet.length; index < len; ++index) {
+ Object temp = backingSet[index];
2021-06-13 19:29:58 +00:00
+ if (!(temp instanceof net.minecraft.server.level.ServerPlayer)) {
2021-06-11 12:02:28 +00:00
+ continue;
+ }
2021-06-13 19:29:58 +00:00
+ net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer)temp;
+ chunkMap.playerLoadedChunk(player, chunkPackets, LevelChunk.this);
2021-06-11 12:02:28 +00:00
+ }
+ })));
+ }
+ }
+ // Paper end - no-tick view distance
}
public final boolean isAnyNeighborsLoaded() {
2021-06-13 19:29:58 +00:00
@@ -1005,7 +1052,7 @@ public class LevelChunk implements ChunkAccess {
2021-06-11 12:02:28 +00:00
BlockState iblockdata = this.getBlockState(blockposition);
2021-06-13 19:29:58 +00:00
BlockState iblockdata1 = Block.updateFromNeighbourShapes(iblockdata, (LevelAccessor) this.level, blockposition);
2021-06-11 12:02:28 +00:00
2021-06-13 19:29:58 +00:00
- this.level.setBlock(blockposition, iblockdata1, 20);
+ this.level.setBlock(blockposition, iblockdata1, 20 | 2); // Paper - We send chunks before they're ticking ready, so we need to notify here
2021-06-11 12:02:28 +00:00
}
this.postProcessing[i].clear();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 053878ce00b77367b403a8c52f0d81f485022c59..b6134895d1b04d3ea7340e77f70efa23cff8b568 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2541,10 +2541,39 @@ public class CraftWorld implements World {
2021-06-11 12:02:28 +00:00
// Spigot start
@Override
public int getViewDistance() {
- return world.spigotConfig.viewDistance;
+ return getHandle().getChunkSource().chunkMap.getEffectiveViewDistance(); // Paper - no-tick view distance
}
// Spigot end
+ // Paper start - per player view distance
+ @Override
+ public void setViewDistance(int viewDistance) {
+ if (viewDistance < 2 || viewDistance > 32) {
+ throw new IllegalArgumentException("View distance " + viewDistance + " is out of range of [2, 32]");
+ }
2021-06-13 19:29:58 +00:00
+ net.minecraft.server.level.ChunkMap chunkMap = getHandle().getChunkSource().chunkMap;
2021-06-11 12:02:28 +00:00
+ if (viewDistance != chunkMap.getEffectiveViewDistance()) {
+ chunkMap.setViewDistance(viewDistance);
+ }
+ }
+
+ @Override
+ public int getNoTickViewDistance() {
+ return getHandle().getChunkSource().chunkMap.getEffectiveNoTickViewDistance();
+ }
+
+ @Override
+ public void setNoTickViewDistance(int viewDistance) {
+ if ((viewDistance < 2 || viewDistance > 32) && viewDistance != -1) {
+ throw new IllegalArgumentException("View distance " + viewDistance + " is out of range of [2, 32]");
+ }
2021-06-13 19:29:58 +00:00
+ net.minecraft.server.level.ChunkMap chunkMap = getHandle().getChunkSource().chunkMap;
2021-06-11 12:02:28 +00:00
+ if (viewDistance != chunkMap.getRawNoTickViewDistance()) {
+ chunkMap.setNoTickViewDistance(viewDistance);
+ }
+ }
+ // Paper end - per player view distance
+
// Spigot start
private final org.bukkit.World.Spigot spigot = new org.bukkit.World.Spigot()
{
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
2021-06-13 19:29:58 +00:00
index 2ab585a018290996e7fa9ca6f3ad7d734cd7beaa..a08583863f9fa08016bdfc7949a273eaa4429927 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
2021-06-13 19:29:58 +00:00
@@ -188,7 +188,7 @@ public class ActivationRange
2021-06-11 12:02:28 +00:00
maxRange = Math.max( maxRange, waterActivationRange );
maxRange = Math.max( maxRange, villagerActivationRange );
// Paper end
- maxRange = Math.min( ( world.spigotConfig.viewDistance << 4 ) - 8, maxRange );
2021-06-13 19:29:58 +00:00
+ maxRange = Math.min( ( ((net.minecraft.server.level.ServerLevel)world).getChunkSource().chunkMap.getEffectiveViewDistance() << 4 ) - 8, maxRange ); // Paper - no-tick view distance
2021-06-11 12:02:28 +00:00
for ( Player player : world.players() )
{