Skip to content

Commit b630564

Browse files
committed
More patches
1 parent 348c855 commit b630564

6 files changed

+82
-252
lines changed

patches/unapplied/server/1030-Incremental-chunk-and-player-saving.patch renamed to patches/server/1049-Incremental-chunk-and-player-saving.patch

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Subject: [PATCH] Incremental chunk and player saving
55

66

77
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
8-
index b64c3e29e2b8e890073fee0b45c8b8dfc2b642fd..aa38e3b297209cc121e7dc7a6ac9588c18bf9357 100644
8+
index de80ac827c8ac3630d68b73cb425d4b56f7d2cd7..f422cbcb69d6fda2b4e229cbdbf10abd0d36d6f9 100644
99
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
1010
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
11-
@@ -992,7 +992,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
11+
@@ -1009,7 +1009,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
1212

1313
try {
1414
this.isSaving = true;
@@ -17,49 +17,43 @@ index b64c3e29e2b8e890073fee0b45c8b8dfc2b642fd..aa38e3b297209cc121e7dc7a6ac9588c
1717
flag3 = this.saveAllChunks(suppressLogs, flush, force);
1818
} finally {
1919
this.isSaving = false;
20-
@@ -1595,16 +1595,28 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
20+
@@ -1676,9 +1676,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2121
}
2222

2323
--this.ticksUntilAutosave;
24-
- // CraftBukkit start
25-
- if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) {
26-
- this.ticksUntilAutosave = this.autosavePeriod;
27-
- // CraftBukkit end
28-
- MinecraftServer.LOGGER.debug("Autosave started");
29-
- this.profiler.push("save");
30-
- this.saveEverything(true, false, false);
31-
- this.profiler.pop();
32-
- MinecraftServer.LOGGER.debug("Autosave finished");
24+
- if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) { // CraftBukkit
25+
- this.autoSave();
3326
+ // Paper start - Incremental chunk and player saving
27+
+ final ProfilerFiller profiler = Profiler.get();
3428
+ int playerSaveInterval = io.papermc.paper.configuration.GlobalConfiguration.get().playerAutoSave.rate;
3529
+ if (playerSaveInterval < 0) {
3630
+ playerSaveInterval = autosavePeriod;
3731
+ }
38-
+ this.profiler.push("save");
32+
+ profiler.push("save");
3933
+ final boolean fullSave = autosavePeriod > 0 && this.tickCount % autosavePeriod == 0;
4034
+ try {
4135
+ this.isSaving = true;
4236
+ if (playerSaveInterval > 0) {
4337
+ this.playerList.saveAll(playerSaveInterval);
4438
+ }
45-
+ for (ServerLevel level : this.getAllLevels()) {
39+
+ for (final ServerLevel level : this.getAllLevels()) {
4640
+ if (level.paperConfig().chunks.autoSaveInterval.value() > 0) {
4741
+ level.saveIncrementally(fullSave);
4842
+ }
4943
+ }
5044
+ } finally {
5145
+ this.isSaving = false;
5246
}
53-
+ this.profiler.pop();
47+
+ profiler.pop();
5448
+ // Paper end - Incremental chunk and player saving
55-
// Paper start - move executeAll() into full server tick timing
56-
try (co.aikar.timings.Timing ignored = MinecraftTimings.processTasksTimer.startTiming()) {
57-
this.runAllTasks();
49+
50+
ProfilerFiller gameprofilerfiller = Profiler.get();
51+
5852
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
59-
index 202975cf97ae143622a0c19826b0d63ad2afa0ce..f9abf63e12ea930275121b470e4e4906cff0fc12 100644
53+
index a7420e4522e0dff72ce7f8a791b9cd4bfa270106..fd07824ff6a928ca6e2f56477a63bac7aaeb8c15 100644
6054
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
6155
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
62-
@@ -1315,6 +1315,35 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
56+
@@ -1371,6 +1371,35 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
6357
return !this.server.isUnderSpawnProtection(this, pos, player) && this.getWorldBorder().isWithinBounds(pos);
6458
}
6559

@@ -96,10 +90,10 @@ index 202975cf97ae143622a0c19826b0d63ad2afa0ce..f9abf63e12ea930275121b470e4e4906
9690
// Paper start - add close param
9791
this.save(progressListener, flush, savingDisabled, false);
9892
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
99-
index 8dc3ba983fd4c61e463867be8d224aa90424215a..6c280abdef5f80b668d6090f9d35283a33e21e0c 100644
93+
index 8ceeebb561046933cba0725e15732fa074226884..8c9148426f23cbbdfaf7ae66657d1a620f8bd853 100644
10094
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
10195
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
102-
@@ -203,6 +203,7 @@ import org.bukkit.inventory.MainHand;
96+
@@ -221,6 +221,7 @@ import org.bukkit.inventory.MainHand;
10397
public class ServerPlayer extends net.minecraft.world.entity.player.Player implements ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer { // Paper - rewrite chunk system
10498

10599
private static final Logger LOGGER = LogUtils.getLogger();
@@ -108,18 +102,18 @@ index 8dc3ba983fd4c61e463867be8d224aa90424215a..6c280abdef5f80b668d6090f9d35283a
108102
private static final int NEUTRAL_MOB_DEATH_NOTIFICATION_RADII_Y = 10;
109103
private static final int FLY_STAT_RECORDING_SPEED = 25;
110104
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
111-
index 30b6f5d4af1dc799d5ffee6a345bcf92528df7cd..5e2c4969e77c669acbb4a13c07033cb267c3d586 100644
105+
index 3642444d45038fd1a07768ff96bfbd8678b02e04..f8f8e8f602f416fe97fc23ef6efeee7af2749292 100644
112106
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
113107
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
114-
@@ -569,6 +569,7 @@ public abstract class PlayerList {
108+
@@ -519,6 +519,7 @@ public abstract class PlayerList {
115109

116110
protected void save(ServerPlayer player) {
117111
if (!player.getBukkitEntity().isPersistent()) return; // CraftBukkit
118112
+ player.lastSave = MinecraftServer.currentTick; // Paper - Incremental chunk and player saving
119113
this.playerIo.save(player);
120114
ServerStatsCounter serverstatisticmanager = (ServerStatsCounter) player.getStats(); // CraftBukkit
121115

122-
@@ -1193,10 +1194,22 @@ public abstract class PlayerList {
116+
@@ -1153,10 +1154,22 @@ public abstract class PlayerList {
123117
}
124118

125119
public void saveAll() {

patches/unapplied/server/1011-Optimise-general-POI-access.patch renamed to patches/server/1050-Optimise-general-POI-access.patch

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -886,10 +886,10 @@ index d5a549f08b98c80a5cf0eef02cb8a389c32dfecb..92731b6b593289e9f583c9b705b219e8
886886
BlockPos blockPos = path.getTarget();
887887
Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
888888
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
889-
index d7a6eab60bf26916f78f858e224573560e581fef..a908bf1dc5e821dcf6981a8c21076fb0bdc6516d 100644
889+
index 5930a430983061afddf20e3208ff2462ca1b78cd..63a94b6068fdaef8bb26675c2927cb729ced1dac 100644
890890
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
891891
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
892-
@@ -268,36 +268,45 @@ public class PoiManager extends SectionStorage<PoiSection> implements ca.spotted
892+
@@ -254,36 +254,45 @@ public class PoiManager extends SectionStorage<PoiSection, PoiSection.Packed> im
893893
public Optional<BlockPos> find(
894894
Predicate<Holder<PoiType>> typePredicate, Predicate<BlockPos> posPredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus
895895
) {
@@ -903,10 +903,10 @@ index d7a6eab60bf26916f78f858e224573560e581fef..a908bf1dc5e821dcf6981a8c21076fb0
903903
public Optional<BlockPos> findClosest(Predicate<Holder<PoiType>> typePredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus) {
904904
- return this.getInRange(typePredicate, pos, radius, occupationStatus)
905905
- .map(PoiRecord::getPos)
906-
- .min(Comparator.comparingDouble(blockPos2 -> blockPos2.distSqr(pos)));
906+
- .min(Comparator.comparingDouble(poiPos -> poiPos.distSqr(pos)));
907907
+ // Paper start - re-route to faster logic
908-
+ BlockPos ret = io.papermc.paper.util.PoiAccess.findClosestPoiDataPosition(this, typePredicate, null, pos, radius, radius * radius, occupationStatus, false);
909-
+ return Optional.ofNullable(ret);
908+
+ BlockPos closestPos = io.papermc.paper.util.PoiAccess.findClosestPoiDataPosition(this, typePredicate, null, pos, radius, radius * radius, occupationStatus, false);
909+
+ return Optional.ofNullable(closestPos);
910910
+ // Paper end - re-route to faster logic
911911
}
912912

@@ -929,27 +929,27 @@ index d7a6eab60bf26916f78f858e224573560e581fef..a908bf1dc5e821dcf6981a8c21076fb0
929929
- return this.getInRange(typePredicate, pos, radius, occupationStatus)
930930
- .map(PoiRecord::getPos)
931931
- .filter(posPredicate)
932-
- .min(Comparator.comparingDouble(blockPos2 -> blockPos2.distSqr(pos)));
932+
- .min(Comparator.comparingDouble(poiPos -> poiPos.distSqr(pos)));
933933
+ // Paper start - re-route to faster logic
934-
+ BlockPos ret = io.papermc.paper.util.PoiAccess.findClosestPoiDataPosition(this, typePredicate, posPredicate, pos, radius, radius * radius, occupationStatus, false);
935-
+ return Optional.ofNullable(ret);
934+
+ BlockPos closestPos = io.papermc.paper.util.PoiAccess.findClosestPoiDataPosition(this, typePredicate, posPredicate, pos, radius, radius * radius, occupationStatus, false);
935+
+ return Optional.ofNullable(closestPos);
936936
+ // Paper end - re-route to faster logic
937937
}
938938

939-
public Optional<BlockPos> take(Predicate<Holder<PoiType>> typePredicate, BiPredicate<Holder<PoiType>, BlockPos> biPredicate, BlockPos pos, int radius) {
939+
public Optional<BlockPos> take(Predicate<Holder<PoiType>> typePredicate, BiPredicate<Holder<PoiType>, BlockPos> posPredicate, BlockPos pos, int radius) {
940940
- return this.getInRange(typePredicate, pos, radius, PoiManager.Occupancy.HAS_SPACE)
941-
- .filter(poi -> biPredicate.test(poi.getPoiType(), poi.getPos()))
941+
- .filter(poi -> posPredicate.test(poi.getPoiType(), poi.getPos()))
942942
- .findFirst()
943943
+ // Paper start - re-route to faster logic
944944
+ final @javax.annotation.Nullable PoiRecord closest = io.papermc.paper.util.PoiAccess.findClosestPoiDataRecord(
945-
+ this, typePredicate, biPredicate, pos, radius, radius * radius, Occupancy.HAS_SPACE, false
945+
+ this, typePredicate, posPredicate, pos, radius, radius * radius, Occupancy.HAS_SPACE, false
946946
+ );
947947
+ return Optional.ofNullable(closest)
948948
+ // Paper end - re-route to faster logic
949949
.map(poi -> {
950950
poi.acquireTicket();
951951
return poi.getPos();
952-
@@ -312,8 +321,21 @@ public class PoiManager extends SectionStorage<PoiSection> implements ca.spotted
952+
@@ -298,8 +307,21 @@ public class PoiManager extends SectionStorage<PoiSection, PoiSection.Packed> im
953953
int radius,
954954
RandomSource random
955955
) {
@@ -974,7 +974,7 @@ index d7a6eab60bf26916f78f858e224573560e581fef..a908bf1dc5e821dcf6981a8c21076fb0
974974

975975
public boolean release(BlockPos pos) {
976976
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
977-
index a6c0e89cb645693034f8e90ac2de8f2da457453c..11e895d837794d79a76303b912092096bd7d07a8 100644
977+
index 712cbfc100e8aaf612d1d651dae64f57f892a768..827991ee61406bcda3f4794dcc735c0e2e0e09af 100644
978978
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
979979
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
980980
@@ -26,7 +26,7 @@ import org.slf4j.Logger;
@@ -987,10 +987,10 @@ index a6c0e89cb645693034f8e90ac2de8f2da457453c..11e895d837794d79a76303b912092096
987987
private boolean isValid;
988988

989989
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java
990-
index c7ed3eb80f6e8b918434153093644776866aa220..21de1b95f2a5d136149447472e871f675760ba1a 100644
990+
index c3beb7fcad46a917d2b61bd0a0e98e5106056728..9b97fb2d125df4df715599aab27e074707731466 100644
991991
--- a/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java
992992
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java
993-
@@ -81,11 +81,11 @@ public abstract class SectionStorage<R> implements AutoCloseable, ca.spottedleaf
993+
@@ -131,11 +131,11 @@ public class SectionStorage<R, P> implements AutoCloseable, ca.spottedleaf.moonr
994994
}
995995

996996
@Nullable
@@ -1005,7 +1005,7 @@ index c7ed3eb80f6e8b918434153093644776866aa220..21de1b95f2a5d136149447472e871f67
10051005
return Optional.empty();
10061006
} else {
10071007
diff --git a/src/main/java/net/minecraft/world/level/portal/PortalForcer.java b/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
1008-
index fd04a50183ccb1f21fc6efa70256e1bb4db2d6d4..49f7ba292b82bac1643cc07aa576f3c37b8e8ab3 100644
1008+
index 83d294f6f48b867d09ea0d339c779011bf4138a5..9204bb0538297f233442a86733a33e6d0eea8114 100644
10091009
--- a/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
10101010
+++ b/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
10111011
@@ -53,17 +53,39 @@ public class PortalForcer {

patches/unapplied/server/1025-Fix-entity-tracker-desync-when-new-players-are-added.patch renamed to patches/server/1051-Fix-entity-tracker-desync-when-new-players-are-added.patch

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ client will not tick the entity and thus not lerp the entity
2929
from its old position to its new position.
3030

3131
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundAddEntityPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundAddEntityPacket.java
32-
index 854baa554da2215a656f976ae2973341c3b2d61c..792b9a72a610cc512a8920d61013b6ba02f71e47 100644
32+
index f6e1deb2f849d8b01b15cfa69e2f6cd5f2b1512b..f66e40326c510aa3267542b1a24ed75d1ed6d3f1 100644
3333
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundAddEntityPacket.java
3434
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundAddEntityPacket.java
3535
@@ -42,9 +42,11 @@ public class ClientboundAddEntityPacket implements Packet<ClientGamePacketListen
@@ -48,10 +48,10 @@ index 854baa554da2215a656f976ae2973341c3b2d61c..792b9a72a610cc512a8920d61013b6ba
4848
entityTrackerEntry.getLastSentYRot(),
4949
entity.getType(),
5050
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
51-
index 21370ed6c7d98d3f3546f0365ac50e5c26ba3bde..af8cb316ac169aa8d98a88765b85bb013b9ba961 100644
51+
index d692af061ded8cd5bcf1d268e6bd521d84f99c39..bf43bdb43c5301c0e0954729bc531fb6a5045075 100644
5252
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
5353
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
54-
@@ -1269,6 +1269,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
54+
@@ -1277,6 +1277,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
5555
this.serverEntity.addPairing(player);
5656
}
5757
// Paper end - entity tracking events
@@ -60,10 +60,10 @@ index 21370ed6c7d98d3f3546f0365ac50e5c26ba3bde..af8cb316ac169aa8d98a88765b85bb01
6060
} else if (this.seenBy.remove(player.connection)) {
6161
this.serverEntity.removePairing(player);
6262
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
63-
index 12d86f27d04bffed8c3844e36b42fbc2f84dacff..8ea2f24695f5dad55e21f238b69442513e7a90c6 100644
63+
index 5bbc7ceaafc163f12344e5d5d355ad2ff30ddca2..90eb4927fa51ce3df86aa7b6c71f49150a03e337 100644
6464
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
6565
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
66-
@@ -96,6 +96,13 @@ public class ServerEntity {
66+
@@ -100,6 +100,13 @@ public class ServerEntity {
6767
this.trackedDataValues = entity.getEntityData().getNonDefaultValues();
6868
}
6969

@@ -77,25 +77,25 @@ index 12d86f27d04bffed8c3844e36b42fbc2f84dacff..8ea2f24695f5dad55e21f238b6944251
7777
public void sendChanges() {
7878
// Paper start - optimise collisions
7979
if (((ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity)this.entity).moonrise$isHardColliding()) {
80-
@@ -145,7 +152,7 @@ public class ServerEntity {
80+
@@ -149,7 +156,7 @@ public class ServerEntity {
8181
}
8282
}
8383

8484
- if (this.tickCount % this.updateInterval == 0 || this.entity.hasImpulse || this.entity.getEntityData().isDirty()) {
8585
+ if (this.forceStateResync || this.tickCount % this.updateInterval == 0 || this.entity.hasImpulse || this.entity.getEntityData().isDirty()) { // Paper - fix desync when a player is added to the tracker
86-
int i;
87-
int j;
86+
byte b0 = Mth.packDegrees(this.entity.getYRot());
87+
byte b1 = Mth.packDegrees(this.entity.getXRot());
88+
boolean flag = Math.abs(b0 - this.lastSentYRot) >= 1 || Math.abs(b1 - this.lastSentXRot) >= 1;
89+
@@ -199,7 +206,7 @@ public class ServerEntity {
90+
long k = this.positionCodec.encodeZ(vec3d);
91+
boolean flag5 = i < -32768L || i > 32767L || j < -32768L || j > 32767L || k < -32768L || k > 32767L;
8892

89-
@@ -185,7 +192,7 @@ public class ServerEntity {
90-
long i1 = this.positionCodec.encodeZ(vec3d);
91-
boolean flag6 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i1 < -32768L || i1 > 32767L;
92-
93-
- if (!flag6 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.onGround()) {
94-
+ if (!this.forceStateResync && !flag6 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.onGround()) { // Paper - fix desync when a player is added to the tracker
95-
if ((!flag2 || !flag3) && !(this.entity instanceof AbstractArrow)) {
96-
if (flag2) {
97-
packet1 = new ClientboundMoveEntityPacket.Pos(this.entity.getId(), (short) ((int) k), (short) ((int) l), (short) ((int) i1), this.entity.onGround());
98-
@@ -249,6 +256,7 @@ public class ServerEntity {
93+
- if (!flag5 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.onGround()) {
94+
+ if (!this.forceStateResync && !flag5 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.onGround()) { // Paper - fix desync when a player is added to the tracker
95+
if ((!flag2 || !flag) && !(this.entity instanceof AbstractArrow)) {
96+
if (flag2) {
97+
packet1 = new ClientboundMoveEntityPacket.Pos(this.entity.getId(), (short) ((int) i), (short) ((int) j), (short) ((int) k), this.entity.onGround());
98+
@@ -265,6 +272,7 @@ public class ServerEntity {
9999
}
100100

101101
this.entity.hasImpulse = false;

0 commit comments

Comments
 (0)