geforkt von Mirrors/Paper
7d10cdea03
This PR contains all of Tuinity's patches. Very notable ones are: - Highly optimised collisions - Optimised entity lookups by bounding box (Mojang made regressions in 1.17, this brings it back to 1.16) - Starlight https://github.com/PaperMC/Starlight - Rewritten dataconverter system https://github.com/PaperMC/DataConverter - Random block ticking optimisation (wrongly dropped from Paper 1.17) - Chunk ticking optimisations - Anything else I've forgotten in the 60 or so patches If you are a previous Tuinity user, your config will not migrate. You must do it yourself. The config options have simply been moved into paper.yml, so it will be an easy migration. However, please note that the chunk loading options in tuinity.yml are NOT compatible with the options in paper.yml. * Port tuinity, initial patchset * Update gradle to 7.2 jmp said it fixes rebuildpatches not working for me. it fucking better * Completely clean apply * Remove tuinity config, add per player api patch * Remove paper reobf mappings patch * Properly update gradlew * Force clean rebuild * Mark fixups Comments and ATs still need to be done * grep -r "Tuinity" * Fixup * Ensure gameprofile lastaccess is written only under the state lock * update URL for dataconverter * Only clean rebuild tuinity patches might fix merge conflicts * Use UTF-8 for gradlew * Clean rb patches again * Convert block ids used as item ids Neither the converters of pre 1.13 nor DFU handled these cases, as by the time they were written the game at the time didn't consider these ids valid - they would be air. Because of this, some worlds have logspam since only DataConverter (not DFU or legacy converters) will warn when an invalid id has been seen. While quite a few do need to now be considered as air, quite a lot do not. So it makes sense to add conversion for these items, instead of simply suppressing or ignoring the logs. I've now added id -> string conversion for all block ids that could be used as items that existed in the game before 1.7.10 (I have no interest in tracking down the exact version block ids stopped working) that were on https://minecraft-ids.grahamedgecombe.com/ Items that did not directly convert to new items will be instead converted to air: stems, wheat crops, piston head, tripwire wire block * Fix LightPopulated parsing in V1466 The DFU code was checking if the number existed, not if it didn't exist. I misread the original code. * Always parse protochunk light sources unless it is marked as non-lit Chunks not marked as lit will always go through the light engine, so they should always have their block sources parsed. * Update custom names to JSON for players Missed this fix from CB, as it was inside the DataFixers class. I decided to double check all of the CB changes again: DataFixers.java was the only area I missed, as I had inspected all datafixer diffs and implemented them all into DataConverter. I also checked Bootstrap.java again, and re-evaluated their changes. I had previously done this, but determined that they were all bad. The changes to make standing_sign block map to oak_sign block in V1450 is bad, because that's not the item id V1450 accepts. Only in 1.14 did oak_sign even exist, and as expected there is a converter to rename all existing sign items/blocks. The fix to register the portal block under id 1440 is useless, as the flattenning logic will default to the lowest registered id - which is the exact blockstate that CB registers into 1440. So it just doesn't do anything. The extra item ids in the id -> string converter are already added, but I found this from EMC originally. The change for the spawn egg id 23 -> Arrow is just wrong, that id DOES correspond to TippedArrow, NOT Arrow. As expected, the spawn egg already has a dedicated mapping for Arrow, which is id 10 - which was Arrow's entity id. I also ported a fix for the cooked_fished id update. This doesn't really matter since there is already a dataconverter to fix this, but the game didn't accept cooked_fished at the time. So I see no harm. * Review all converters and walkers - Refactor V99 to have helper methods for defining entity/tile entity types - Automatically namespace all ids that should be namespaced. While vanilla never saved non-namespaced data for things that are namespaced, plugins/users might have. - Synchronised the identity ensure map in HelperBlockFlatteningV1450 - Code style consistency - Add missing log warning in V102 for ITEM_NAME type conversion - Use getBoolean instead of getByte - Use ConverterAbstractEntityRename for V143 TippedArrow -> Arrow rename, as it will affect ENTITY_NAME type - Always set isVillager to false in V502 for Zombie - Register V808's converter under subversion 1 like DFU - Register a breakpoint for V1.17.1. In the future, all final versions of major releases will have a breakpoint so that the work required to determine if a converter needs a breakpoint is minimal - Validate that a dataconverter is only registered for a version that is registered - ConverterFlattenTileEntity is actually ConverterFlattenEntity It even registered the converters under TILE_ENTITY, instead of ENTITY. - Fix id comparison in V1492 STRUCTURE_FEATURE renamer - Use ConverterAbstractStatsRename for V1510 stats renamer At the time I had written that class, the abstract renamer didn't exist. - Ensure OwnerUUID is at least set to empty string in V1904 if the ocelot is converted to a cat (this is likely so that it retains a collar) - Use generic read/write for Records in V1946 Records is actually a list, not a map. So reading map was invalid. * Always set light to zero when propagating decrease This fixes an almost infinite loop where light values would be spam queued on a very small subset on blocks. This also likely fixes the memory issues people were seeing. * re-organize patches * Apply and fix conflicts * Revert some patches getChunkAt retains chunks so that plugins don't spam loads revert mc-4 fix will remain unless issues pop up * Shuffle iterated chunks if per player is not enabled Can help with some mob spawning stacking up at locations * Make per player default, migrate all configs * Adjust comments in fixups * Rework config for player chunk loader Old config is not compatible. Move all configs to be under `settings` in paper.yml The player chunk loader has been modified to less aggressively load chunks, but to send chunks at higher rates compared to tuinity. There are new config entries to tune this behavior. * Add back old constructor to CompressionEncoder/Decoder (fixes Tuinity #358) * Raise chunk loading default limits * Reduce worldgen thread workers for lower core count cpus * Raise limits for chunk loading config Also place it under `chunk-loading` * Disable max chunk send rate by default * Fix conflicts and rebuild patches * Drop default send rate again Appears to be still causing problems for no known reason * Raise chunk send limits to 100 per player While a low limit fixes ping issues for some people, most people do not suffer from this issue and thus should not suffer from an extremely slow load-in rate. * Rebase part 1 Autosquash the fixups * Move not implemented up * Fixup mc-dev fixes Missed this one * Rebase per player viewdistance api into the original api patch * Remove old light engine patch part 1 The prioritisation must be kept from it, so that part has been rebased into the priority patch. Part 2 will deal with rebasing all of the patches _after_ * Rebase remaining patches for old light patch removal * Remove other mid tick patch * Remove Optimize-PlayerChunkMap-memory-use-for-visibleChunks.patch Replaced by `Do not copy visible chunks` * Revert AT for Vec3i setX/Y/Z The class is immutable. set should not be exposed * Remove old IntegerUtil class * Replace old CraftChunk#getEntities patch * Remove import for SWMRNibbleArray in ChunkAccess * Finished merge checklist * Remove ensureTickThread impl in urgency patch Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com> Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
718 Zeilen
42 KiB
Diff
718 Zeilen
42 KiB
Diff
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
|
|
index ee53453440177537fc653ea156785d7591498614..cfe293881f68c8db337c3a48948362bb7b3e3522 100644
|
|
--- a/src/main/java/co/aikar/timings/TimingsExport.java
|
|
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
|
|
@@ -152,7 +152,8 @@ public class TimingsExport extends Thread {
|
|
pair("gamerules", toObjectMapper(world.getWorld().getGameRules(), rule -> {
|
|
return pair(rule, world.getWorld().getGameRuleValue(rule));
|
|
})),
|
|
- pair("ticking-distance", world.getChunkSource().chunkMap.getEffectiveViewDistance())
|
|
+ pair("ticking-distance", world.getChunkSource().chunkMap.getEffectiveViewDistance()),
|
|
+ pair("notick-viewdistance", world.getChunkSource().chunkMap.getEffectiveNoTickViewDistance())
|
|
));
|
|
}));
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
index 9e16c9e6b6e84d84028821f2ade103dbced66470..fd1064b08e61c0547cad092e009635ab708b8962 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
@@ -487,6 +487,11 @@ public class PaperWorldConfig {
|
|
lightQueueSize = getInt("light-queue-size", lightQueueSize);
|
|
}
|
|
|
|
+ public int noTickViewDistance;
|
|
+ private void viewDistance() {
|
|
+ this.noTickViewDistance = this.getInt("viewdistances.no-tick-view-distance", -1);
|
|
+ }
|
|
+
|
|
public boolean antiXray;
|
|
public EngineMode engineMode;
|
|
public int maxBlockHeight;
|
|
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
|
index 5c1421620e02b7d4ab4171ebff41076c7ee8cd55..4bc418f45c6f16a9a1c78b6688625268870a96ad 100644
|
|
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
|
@@ -636,7 +636,8 @@ public final class MCUtil {
|
|
});
|
|
|
|
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
|
|
index 1ea32090783ac5b885b95ae2009dd61de3063ae0..8d3cdd288eacc91f7c9a624f601284e5cd2a36cc 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
|
@@ -75,6 +75,17 @@ public class ChunkHolder {
|
|
|
|
boolean isUpdateQueued = false; // Paper
|
|
private final ChunkMap chunkMap; // Paper
|
|
+ // 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
|
|
|
|
public ChunkHolder(ChunkPos pos, int level, LevelHeightAccessor world, LevelLightEngine lightingProvider, ChunkHolder.LevelChangeListener levelUpdateListener, ChunkHolder.PlayerProvider playersWatchingChunkProvider) {
|
|
this.futures = new AtomicReferenceArray(ChunkHolder.CHUNK_STATUSES.size());
|
|
@@ -204,7 +215,7 @@ public class ChunkHolder {
|
|
}
|
|
|
|
public void blockChanged(BlockPos pos) {
|
|
- LevelChunk chunk = this.getTickingChunk();
|
|
+ LevelChunk chunk = this.getSendingChunk(); // Paper - no-tick view distance
|
|
|
|
if (chunk != null) {
|
|
int i = this.levelHeightAccessor.getSectionIndex(pos.getY());
|
|
@@ -220,7 +231,7 @@ public class ChunkHolder {
|
|
}
|
|
|
|
public void sectionLightChanged(LightLayer lightType, int y) {
|
|
- LevelChunk chunk = this.getTickingChunk();
|
|
+ LevelChunk chunk = this.getSendingChunk(); // Paper - no-tick view distance
|
|
|
|
if (chunk != null) {
|
|
chunk.setUnsaved(true);
|
|
@@ -310,9 +321,48 @@ public class ChunkHolder {
|
|
}
|
|
|
|
public void broadcast(Packet<?> packet, boolean onlyOnWatchDistanceEdge) {
|
|
- 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);
|
|
+
|
|
+ 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);
|
|
+
|
|
+ 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 292fb6d71ca8bd63ad04d87d04f13b7f4f6f98fc..d2080cfe58f7e241c9612ad0e500240dcb341878 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -127,7 +127,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
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
|
|
// Paper start
|
|
final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> mailboxLight;
|
|
public void addLightTask(ChunkHolder playerchunk, Runnable run) {
|
|
@@ -169,21 +169,68 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
|
|
// Paper start - distance maps
|
|
private final com.destroystokyo.paper.util.misc.PooledLinkedHashSets<ServerPlayer> pooledLinkedPlayerHashSets = new com.destroystokyo.paper.util.misc.PooledLinkedHashSets<>();
|
|
+ // 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());
|
|
int chunkZ = MCUtil.getChunkCoordinate(player.getZ());
|
|
// Note: players need to be explicitly added to distance maps before they can be updated
|
|
+ // Paper start - no-tick view distance
|
|
+ int effectiveTickViewDistance = this.getEffectiveViewDistance();
|
|
+ int effectiveNoTickViewDistance = Math.max(this.getEffectiveNoTickViewDistance(), effectiveTickViewDistance);
|
|
+
|
|
+ if (!this.skipPlayer(player)) {
|
|
+ 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) {
|
|
|
|
+ // 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) {
|
|
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
|
|
+ // Paper start - no-tick view distance
|
|
+ int effectiveTickViewDistance = this.getEffectiveViewDistance();
|
|
+ int effectiveNoTickViewDistance = Math.max(this.getEffectiveNoTickViewDistance(), effectiveTickViewDistance);
|
|
+
|
|
+ if (!this.skipPlayer(player)) {
|
|
+ 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
|
|
// Paper start
|
|
@@ -257,6 +304,45 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
this.dataRegionManager = new io.papermc.paper.chunk.SingleThreadChunkRegionManager(this.level, 2, (1.0 / 3.0), 1, 6, "Data", DataRegionData::new, DataRegionSectionData::new);
|
|
this.regionManagers.add(this.dataRegionManager);
|
|
// Paper end
|
|
+ // 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
|
|
}
|
|
|
|
private static double euclideanDistanceSquared(ChunkPos pos, Entity entity) {
|
|
@@ -954,14 +1040,10 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
completablefuture1.thenAcceptAsync((either) -> {
|
|
either.ifLeft((chunk) -> {
|
|
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;
|
|
}
|
|
@@ -1054,27 +1136,34 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
}
|
|
|
|
public void setViewDistance(int watchDistance) {
|
|
- 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) -> {
|
|
- int l = ChunkMap.checkerboardDistance(chunkcoordintpair, entityplayer, true);
|
|
- 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) {
|
|
+ net.minecraft.server.network.ServerGamePacketListenerImpl connection = player.connection;
|
|
+ if (connection != null) {
|
|
+ // moved in from PlayerList
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundSetChunkCacheRadiusPacket(loadViewDistance));
|
|
+ }
|
|
+ this.updateMaps(player);
|
|
+ // Paper end - no-tick view distance
|
|
}
|
|
}
|
|
|
|
@@ -1086,7 +1175,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
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);
|
|
@@ -1182,7 +1271,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
// 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) {
|
|
@@ -1293,13 +1382,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
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)
|
|
|
|
}
|
|
|
|
@@ -1307,7 +1390,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
SectionPos sectionposition = SectionPos.of((Entity) player);
|
|
|
|
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
|
|
return sectionposition;
|
|
}
|
|
|
|
@@ -1362,6 +1445,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
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;
|
|
@@ -1400,6 +1484,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
}
|
|
}
|
|
}
|
|
+ */ // Paper end - replaced by distance map
|
|
|
|
this.updateMaps(player); // Paper - distance maps
|
|
|
|
@@ -1407,11 +1492,46 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
|
|
@Override
|
|
public Stream<ServerPlayer> getPlayers(ChunkPos chunkPos, boolean onlyOnWatchDistanceEdge) {
|
|
- return this.playerMap.getPlayers(chunkPos.toLong()).filter((entityplayer) -> {
|
|
- int i = ChunkMap.checkerboardDistance(chunkPos, entityplayer, true);
|
|
-
|
|
- return i > this.viewDistance ? false : !onlyOnWatchDistanceEdge || i == this.viewDistance;
|
|
- });
|
|
+ // 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);
|
|
+
|
|
+ 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
|
|
}
|
|
|
|
public void addEntity(Entity entity) {
|
|
@@ -1532,6 +1652,47 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
+ private static int getLightMask(final LevelChunk chunk) {
|
|
+ final net.minecraft.world.level.chunk.LevelChunkSection[] chunkSections = chunk.getSections();
|
|
+ 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.
|
|
+
|
|
+ */
|
|
+ mask |= (net.minecraft.world.level.chunk.LevelChunkSection.isEmpty(chunkSections[i]) ? 0 : 7) << i;
|
|
+ }
|
|
+
|
|
+ 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
|
|
+
|
|
public void playerLoadedChunk(ServerPlayer player, Packet<?>[] packets, LevelChunk chunk) {
|
|
if (packets[0] == null) {
|
|
packets[0] = new ClientboundLevelChunkPacket(chunk, chunk.level.chunkPacketBlockController.shouldModify(player, chunk)); // Paper - Ani-Xray - Bypass
|
|
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
|
|
index 45c7ebe67019cdbe88b6617a95d5c40d3a68286c..38eebda226e007c8910e04f502ce218cdfe1d456 100644
|
|
--- a/src/main/java/net/minecraft/server/level/DistanceManager.java
|
|
+++ b/src/main/java/net/minecraft/server/level/DistanceManager.java
|
|
@@ -275,8 +275,8 @@ public abstract class DistanceManager {
|
|
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() {
|
|
@@ -503,7 +503,7 @@ public abstract class DistanceManager {
|
|
|
|
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
|
|
index 2a7b0d5de81665a5b899ab85cd1fa30be29f9b3e..7efaf53b4df9d4e7e88020ce4ca41c9222fa8064 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -242,6 +242,7 @@ public class ServerPlayer extends Player {
|
|
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
|
|
|
|
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
|
|
+ boolean needsChunkCenterUpdate; // Paper - no-tick view distance
|
|
|
|
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
|
|
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 4ba978af436cb114aa5274df5cd8bd25ff7be2c9..10eb562d2089dc20c9ec33956c3e2f98084de748 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -244,7 +244,7 @@ public abstract class PlayerList {
|
|
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()));
|
|
@@ -797,7 +797,7 @@ public abstract class PlayerList {
|
|
// 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);
|
|
entityplayer1.unsetRemoved();
|
|
entityplayer1.connection.teleport(new Location(worldserver1.getWorld(), entityplayer1.getX(), entityplayer1.getY(), entityplayer1.getZ(), entityplayer1.getYRot(), entityplayer1.getXRot()));
|
|
@@ -1282,7 +1282,7 @@ public abstract class PlayerList {
|
|
|
|
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
|
|
index d050d60900a6829a9409ef944d7e4fceb5248dc1..a49fdaa7b7a0ed82e4a1ebab0a4fb086e86b8e36 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -528,8 +528,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
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
|
|
index 515e28eea8cbab261320352ee0db9b877807f3ed..83ed84f89a036d3768b22a36bc8a0bfc2bc29ec7 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
|
@@ -33,7 +33,10 @@ import net.minecraft.core.Registry;
|
|
import net.minecraft.core.SectionPos;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.network.FriendlyByteBuf;
|
|
+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;
|
|
import net.minecraft.util.profiling.ProfilerFiller;
|
|
@@ -227,7 +230,51 @@ public class LevelChunk implements ChunkAccess {
|
|
}
|
|
|
|
protected void onNeighbourChange(final long bitsetBefore, final long bitsetAfter) {
|
|
+ // Paper start - no-tick view distance
|
|
+ ServerChunkCache chunkProviderServer = ((ServerLevel)this.level).getChunkSource();
|
|
+ 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) {
|
|
+ chunkProviderServer.addTicketAtLevel(net.minecraft.server.level.TicketType.PLAYER, LevelChunk.this.chunkPos, 31, LevelChunk.this.chunkPos); // 31 -> entity ticking, TODO check on update
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+ }
|
|
|
|
+ // 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;
|
|
+ }
|
|
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<net.minecraft.server.level.ServerPlayer> inRange = chunkMap.playerViewDistanceBroadcastMap.getObjectsInRange(LevelChunk.this.coordinateKey);
|
|
+ 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];
|
|
+ if (!(temp instanceof net.minecraft.server.level.ServerPlayer)) {
|
|
+ continue;
|
|
+ }
|
|
+ net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer)temp;
|
|
+ chunkMap.playerLoadedChunk(player, chunkPackets, LevelChunk.this);
|
|
+ }
|
|
+ })));
|
|
+ }
|
|
+ }
|
|
+ // Paper end - no-tick view distance
|
|
}
|
|
|
|
public final boolean isAnyNeighborsLoaded() {
|
|
@@ -1011,7 +1058,7 @@ public class LevelChunk implements ChunkAccess {
|
|
BlockState iblockdata = this.getBlockState(blockposition);
|
|
BlockState iblockdata1 = Block.updateFromNeighbourShapes(iblockdata, (LevelAccessor) this.level, blockposition);
|
|
|
|
- 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
|
|
}
|
|
|
|
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 2a5d4e4efe9ea9fcac4c6079c28a020b4c2df118..d347f8f3bfe7ed0492dd0cd593837ee2246527aa 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -1895,10 +1895,39 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
// 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]");
|
|
+ }
|
|
+ net.minecraft.server.level.ChunkMap chunkMap = getHandle().getChunkSource().chunkMap;
|
|
+ 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]");
|
|
+ }
|
|
+ net.minecraft.server.level.ChunkMap chunkMap = getHandle().getChunkSource().chunkMap;
|
|
+ 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
|
|
index 2574ccd92c43f56e8be71f1bf6857c761a72a510..951e8ba1e05436aa0afcd0a72358550422afa791 100644
|
|
--- a/src/main/java/org/spigotmc/ActivationRange.java
|
|
+++ b/src/main/java/org/spigotmc/ActivationRange.java
|
|
@@ -188,7 +188,7 @@ public class ActivationRange
|
|
maxRange = Math.max( maxRange, waterActivationRange );
|
|
maxRange = Math.max( maxRange, villagerActivationRange );
|
|
// Paper end
|
|
- maxRange = Math.min( ( world.spigotConfig.viewDistance << 4 ) - 8, maxRange );
|
|
+ maxRange = Math.min( ( ((net.minecraft.server.level.ServerLevel)world).getChunkSource().chunkMap.getEffectiveViewDistance() << 4 ) - 8, maxRange ); // Paper - no-tick view distance
|
|
|
|
for ( Player player : world.players() )
|
|
{
|