Skip to content

Commit dfb8d58

Browse files
committed
More
1 parent 803400f commit dfb8d58

File tree

3 files changed

+56
-108
lines changed

3 files changed

+56
-108
lines changed

paper-server/patches/rejected/net/minecraft/world/level/chunk/storage/SerializableChunkData.java.patch paper-server/patches/sources/net/minecraft/world/level/chunk/storage/SerializableChunkData.java.patch

+39-75
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
From 3aeeaf31b7a7f888f54e47826e8ec0ddbe65c4bf Mon Sep 17 00:00:00 2001
2-
From: File <[email protected]>
3-
Date: Sun, 20 Apr 1997 14:37:42 +0100
4-
Subject: [PATCH] paper File Patches
5-
6-
7-
diff --git a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
8-
index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d4cee1984 100644
91
--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
102
+++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
11-
@@ -91,6 +91,7 @@ public record SerializableChunkData(
3+
@@ -91,6 +_,7 @@
124
List<CompoundTag> entities,
135
List<CompoundTag> blockEntities,
146
CompoundTag structureData
157
+ , @Nullable net.minecraft.nbt.Tag persistentDataContainer // CraftBukkit - persistentDataContainer
168
) {
179
public static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codecRW(
1810
Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState()
19-
@@ -107,12 +108,39 @@ public record SerializableChunkData(
11+
@@ -109,12 +_,39 @@
2012
public static final String BLOCK_LIGHT_TAG = "BlockLight";
2113
public static final String SKY_LIGHT_TAG = "SkyLight";
2214

@@ -25,10 +17,10 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
2517
+ public static ChunkPos getChunkCoordinate(final CompoundTag chunkData) {
2618
+ final int dataVersion = ChunkStorage.getVersion(chunkData);
2719
+ if (dataVersion < 2842) { // Level tag is removed after this version
28-
+ final CompoundTag levelData = chunkData.getCompound("Level");
29-
+ return new ChunkPos(levelData.getInt("xPos"), levelData.getInt("zPos"));
20+
+ final CompoundTag levelData = chunkData.getCompound("Level").orElse(null);
21+
+ return new ChunkPos(levelData.getIntOr("xPos", 0), levelData.getIntOr("zPos", 0));
3022
+ } else {
31-
+ return new ChunkPos(chunkData.getInt("xPos"), chunkData.getInt("zPos"));
23+
+ return new ChunkPos(chunkData.getIntOr("xPos", 0), chunkData.getIntOr("zPos", 0));
3224
+ }
3325
+ }
3426
+ // Paper end - guard against serializing mismatching coordinates
@@ -40,50 +32,50 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
4032
+
4133
@Nullable
4234
public static SerializableChunkData parse(LevelHeightAccessor levelHeightAccessor, RegistryAccess registries, CompoundTag tag) {
43-
if (!tag.contains("Status", 8)) {
35+
if (tag.getString("Status").isEmpty()) {
4436
return null;
4537
} else {
46-
- ChunkPos chunkPos = new ChunkPos(tag.getInt("xPos"), tag.getInt("zPos"));
38+
- ChunkPos chunkPos = new ChunkPos(tag.getIntOr("xPos", 0), tag.getIntOr("zPos", 0));
4739
+ // Paper start - Do not let the server load chunks from newer versions
48-
+ if (tag.contains("DataVersion", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) {
49-
+ final int dataVersion = tag.getInt("DataVersion");
40+
+ if (tag.get("DataVersion") instanceof net.minecraft.nbt.NumericTag dataVersionTag) {
41+
+ final int dataVersion = dataVersionTag.intValue();
5042
+ if (!JUST_CORRUPT_IT && dataVersion > CURRENT_DATA_VERSION) {
5143
+ new RuntimeException("Server attempted to load chunk saved with newer version of minecraft! " + dataVersion + " > " + CURRENT_DATA_VERSION).printStackTrace();
5244
+ System.exit(1);
5345
+ }
5446
+ }
5547
+ // Paper end - Do not let the server load chunks from newer versions
56-
+ ChunkPos chunkPos = new ChunkPos(tag.getInt("xPos"), tag.getInt("zPos")); // Paper - guard against serializing mismatching coordinates; diff on change, see ChunkSerializer#getChunkCoordinate
57-
long _long = tag.getLong("LastUpdate");
58-
long _long1 = tag.getLong("InhabitedTime");
59-
ChunkStatus chunkStatus = ChunkStatus.byName(tag.getString("Status"));
60-
@@ -181,7 +209,7 @@ public record SerializableChunkData(
61-
ListTag list7 = tag.getList("sections", 10);
62-
List<SerializableChunkData.SectionData> list8 = new ArrayList<>(list7.size());
48+
+ ChunkPos chunkPos = new ChunkPos(tag.getIntOr("xPos", 0), tag.getIntOr("zPos", 0)); // Paper - guard against serializing mismatching coordinates; diff on change, see ChunkSerializer#getChunkCoordinate
49+
long longOr = tag.getLongOr("LastUpdate", 0L);
50+
long longOr1 = tag.getLongOr("InhabitedTime", 0L);
51+
ChunkStatus chunkStatus = tag.read("Status", ChunkStatus.CODEC).orElse(ChunkStatus.EMPTY);
52+
@@ -154,7 +_,7 @@
53+
ListTag listOrEmpty2 = tag.getListOrEmpty("sections");
54+
List<SerializableChunkData.SectionData> list5 = new ArrayList<>(listOrEmpty2.size());
6355
Registry<Biome> registry = registries.lookupOrThrow(Registries.BIOME);
6456
- Codec<PalettedContainerRO<Holder<Biome>>> codec = makeBiomeCodec(registry);
6557
+ Codec<PalettedContainer<Holder<Biome>>> codec = makeBiomeCodecRW(registry); // CraftBukkit - read/write
6658

67-
for (int i2 = 0; i2 < list7.size(); i2++) {
68-
CompoundTag compound2 = list7.getCompound(i2);
69-
@@ -199,7 +227,7 @@ public record SerializableChunkData(
70-
);
71-
}
72-
73-
- PalettedContainerRO<Holder<Biome>> palettedContainerRo;
74-
+ PalettedContainer<Holder<Biome>> palettedContainerRo; // CraftBukkit - read/write
75-
if (compound2.contains("biomes", 10)) {
76-
palettedContainerRo = codec.parse(NbtOps.INSTANCE, compound2.getCompound("biomes"))
77-
.promotePartial(string -> logErrors(chunkPos, _byte, string))
78-
@@ -239,6 +267,7 @@ public record SerializableChunkData(
79-
list5,
80-
list6,
81-
compound1
59+
for (int i2 = 0; i2 < listOrEmpty2.size(); i2++) {
60+
Optional<CompoundTag> compound = listOrEmpty2.getCompound(i2);
61+
@@ -174,7 +_,7 @@
62+
Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES
63+
)
64+
);
65+
- PalettedContainerRO<Holder<Biome>> palettedContainerRo = compoundTag.getCompound("biomes")
66+
+ PalettedContainer<Holder<Biome>> palettedContainerRo = compoundTag.getCompound("biomes") // CraftBukkit - read/write
67+
.map(
68+
compoundTag1 -> codec.parse(NbtOps.INSTANCE, compoundTag1)
69+
.promotePartial(string -> logErrors(chunkPos, byteOr, string))
70+
@@ -215,6 +_,7 @@
71+
list3,
72+
list4,
73+
compoundOrEmpty
8274
+ , tag.get("ChunkBukkitValues") // CraftBukkit - ChunkBukkitValues
8375
);
8476
}
8577
}
86-
@@ -316,6 +345,12 @@ public record SerializableChunkData(
78+
@@ -292,6 +_,12 @@
8779
}
8880
}
8981

@@ -96,21 +88,7 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
9688
chunkAccess.setLightCorrect(this.lightCorrect);
9789
EnumSet<Heightmap.Types> set = EnumSet.noneOf(Heightmap.Types.class);
9890

99-
@@ -346,6 +381,13 @@ public record SerializableChunkData(
100-
}
101-
102-
for (CompoundTag compoundTag : this.blockEntities) {
103-
+ // Paper start - do not read tile entities positioned outside the chunk
104-
+ final BlockPos blockposition = BlockEntity.getPosFromTag(compoundTag);
105-
+ if ((blockposition.getX() >> 4) != this.chunkPos.x || (blockposition.getZ() >> 4) != this.chunkPos.z) {
106-
+ LOGGER.warn("Tile entity serialized in chunk {} in world '{}' positioned at {} is located outside of the chunk", this.chunkPos, level.getWorld().getName(), blockposition);
107-
+ continue;
108-
+ }
109-
+ // Paper end - do not read tile entities positioned outside the chunk
110-
protoChunk1.setBlockEntityNbt(compoundTag);
111-
}
112-
113-
@@ -370,6 +412,12 @@ public record SerializableChunkData(
91+
@@ -346,6 +_,12 @@
11492
);
11593
}
11694

@@ -123,7 +101,7 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
123101
public static SerializableChunkData copyOf(ServerLevel level, ChunkAccess chunk) {
124102
if (!chunk.canBeSerialized()) {
125103
throw new IllegalArgumentException("Chunk can't be serialized: " + chunk);
126-
@@ -428,6 +476,12 @@ public record SerializableChunkData(
104+
@@ -404,6 +_,12 @@
127105
CompoundTag compoundTag = packStructureData(
128106
StructurePieceSerializationContext.fromLevel(level), pos, chunk.getAllStarts(), chunk.getAllReferences()
129107
);
@@ -136,15 +114,15 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
136114
return new SerializableChunkData(
137115
level.registryAccess().lookupOrThrow(Registries.BIOME),
138116
pos,
139-
@@ -447,6 +501,7 @@ public record SerializableChunkData(
117+
@@ -423,6 +_,7 @@
140118
list2,
141119
list1,
142120
compoundTag
143121
+ , persistentDataContainer // CraftBukkit - persistentDataContainer
144122
);
145123
}
146124
}
147-
@@ -525,6 +580,11 @@ public record SerializableChunkData(
125+
@@ -489,6 +_,11 @@
148126
this.heightmaps.forEach((types, longs) -> compoundTag2.put(types.getSerializationKey(), new LongArrayTag(longs)));
149127
compoundTag.put("Heightmaps", compoundTag2);
150128
compoundTag.put("structures", this.structureData);
@@ -156,26 +134,12 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
156134
return compoundTag;
157135
}
158136

159-
@@ -562,6 +622,13 @@ public record SerializableChunkData(
160-
chunk.setBlockEntityNbt(compoundTag);
161-
} else {
162-
BlockPos posFromTag = BlockEntity.getPosFromTag(compoundTag);
163-
+ // Paper start - do not read tile entities positioned outside the chunk
164-
+ ChunkPos chunkPos = chunk.getPos();
165-
+ if ((posFromTag.getX() >> 4) != chunkPos.x || (posFromTag.getZ() >> 4) != chunkPos.z) {
166-
+ LOGGER.warn("Tile entity serialized in chunk " + chunkPos + " in world '" + level.getWorld().getName() + "' positioned at " + posFromTag + " is located outside of the chunk");
167-
+ continue;
168-
+ }
169-
+ // Paper end - do not read tile entities positioned outside the chunk
170-
BlockEntity blockEntity = BlockEntity.loadStatic(posFromTag, chunk.getBlockState(posFromTag), compoundTag, level.registryAccess());
171-
if (blockEntity != null) {
172-
chunk.setBlockEntity(blockEntity);
173-
@@ -610,6 +677,12 @@ public record SerializableChunkData(
137+
@@ -562,6 +_,12 @@
174138
} else {
175-
StructureStart structureStart = StructureStart.loadStaticStart(context, compound.getCompound(string), seed);
139+
StructureStart structureStart = StructureStart.loadStaticStart(context, compoundOrEmpty.getCompoundOrEmpty(string), seed);
176140
if (structureStart != null) {
177141
+ // CraftBukkit start - load persistent data for structure start
178-
+ net.minecraft.nbt.Tag persistentBase = compound.getCompound(string).get("StructureBukkitValues");
142+
+ net.minecraft.nbt.Tag persistentBase = compoundOrEmpty.getCompoundOrEmpty(string).get("StructureBukkitValues");
179143
+ if (persistentBase instanceof CompoundTag compoundTag) {
180144
+ structureStart.persistentDataContainer.putAll(compoundTag);
181145
+ }
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
From 3aeeaf31b7a7f888f54e47826e8ec0ddbe65c4bf Mon Sep 17 00:00:00 2001
2-
From: File <[email protected]>
3-
Date: Sun, 20 Apr 1997 14:37:42 +0100
4-
Subject: [PATCH] paper File Patches
5-
6-
7-
diff --git a/net/minecraft/world/level/storage/DimensionDataStorage.java b/net/minecraft/world/level/storage/DimensionDataStorage.java
8-
index 693edd43b9ff2a9f93889eb321c3c7b943b98708..d9a3b5a2e6495b7e22c114506c2bd1e406f58f8f 100644
91
--- a/net/minecraft/world/level/storage/DimensionDataStorage.java
102
+++ b/net/minecraft/world/level/storage/DimensionDataStorage.java
11-
@@ -139,7 +139,7 @@ public class DimensionDataStorage implements AutoCloseable {
3+
@@ -150,7 +_,7 @@
124
} else {
135
int i = Util.maxAllowedExecutorThreads();
146
int size = map.size();
@@ -17,12 +9,12 @@ index 693edd43b9ff2a9f93889eb321c3c7b943b98708..d9a3b5a2e6495b7e22c114506c2bd1e4
179
this.pendingWriteFuture = this.pendingWriteFuture.thenCompose(object -> {
1810
List<CompletableFuture<?>> list = new ArrayList<>(i);
1911
int i1 = Mth.positiveCeilDiv(size, i);
20-
@@ -160,7 +160,7 @@ public class DimensionDataStorage implements AutoCloseable {
12+
@@ -171,7 +_,7 @@
2113
object -> CompletableFuture.allOf(
2214
map.entrySet()
2315
.stream()
24-
- .map(entry -> CompletableFuture.runAsync(() -> tryWrite(entry.getKey(), entry.getValue()), Util.ioPool()))
25-
+ .map(entry -> CompletableFuture.runAsync(() -> tryWrite(entry.getKey(), entry.getValue()), Util.DIMENSION_DATA_IO_POOL)) // Paper - Separate dimension data IO pool
16+
- .map(entry -> CompletableFuture.runAsync(() -> this.tryWrite(entry.getKey(), entry.getValue()), Util.ioPool()))
17+
+ .map(entry -> CompletableFuture.runAsync(() -> this.tryWrite(entry.getKey(), entry.getValue()), Util.DIMENSION_DATA_IO_POOL)) // Paper - Separate dimension data IO pool
2618
.toArray(CompletableFuture[]::new)
2719
)
2820
);

paper-server/patches/rejected/net/minecraft/world/level/storage/PrimaryLevelData.java.patch paper-server/patches/sources/net/minecraft/world/level/storage/PrimaryLevelData.java.patch

+13-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
From 3aeeaf31b7a7f888f54e47826e8ec0ddbe65c4bf Mon Sep 17 00:00:00 2001
2-
From: File <[email protected]>
3-
Date: Sun, 20 Apr 1997 14:37:42 +0100
4-
Subject: [PATCH] paper File Patches
5-
6-
7-
diff --git a/net/minecraft/world/level/storage/PrimaryLevelData.java b/net/minecraft/world/level/storage/PrimaryLevelData.java
8-
index 385d424ed08a6f3202c263cc8acedbc32cdeae7c..2f4922a2035cc7d628dd2c979137163feb90e19f 100644
91
--- a/net/minecraft/world/level/storage/PrimaryLevelData.java
102
+++ b/net/minecraft/world/level/storage/PrimaryLevelData.java
11-
@@ -74,6 +74,21 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
3+
@@ -74,6 +_,21 @@
124
private final Set<String> removedFeatureFlags;
135
private final TimerQueue<MinecraftServer> scheduledEvents;
146

@@ -30,7 +22,7 @@ index 385d424ed08a6f3202c263cc8acedbc32cdeae7c..2f4922a2035cc7d628dd2c979137163f
3022
private PrimaryLevelData(
3123
@Nullable CompoundTag loadedPlayerTag,
3224
boolean wasModded,
33-
@@ -237,7 +252,7 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
25+
@@ -237,7 +_,7 @@
3426
nbt.put("Version", compoundTag);
3527
NbtUtils.addCurrentDataVersion(nbt);
3628
DynamicOps<Tag> dynamicOps = registry.createSerializationContext(NbtOps.INSTANCE);
@@ -39,16 +31,16 @@ index 385d424ed08a6f3202c263cc8acedbc32cdeae7c..2f4922a2035cc7d628dd2c979137163f
3931
.resultOrPartial(Util.prefix("WorldGenSettings: ", LOGGER::error))
4032
.ifPresent(worldOptionsTag -> nbt.put("WorldGenSettings", worldOptionsTag));
4133
nbt.putInt("GameType", this.settings.gameType().getId());
42-
@@ -281,6 +296,8 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
43-
if (this.wanderingTraderId != null) {
44-
nbt.putUUID("WanderingTraderId", this.wanderingTraderId);
45-
}
34+
@@ -276,6 +_,8 @@
35+
nbt.putInt("WanderingTraderSpawnDelay", this.wanderingTraderSpawnDelay);
36+
nbt.putInt("WanderingTraderSpawnChance", this.wanderingTraderSpawnChance);
37+
nbt.storeNullable("WanderingTraderId", UUIDUtil.CODEC, this.wanderingTraderId);
4638
+ nbt.putString("Bukkit.Version", org.bukkit.Bukkit.getName() + "/" + org.bukkit.Bukkit.getVersion() + "/" + org.bukkit.Bukkit.getBukkitVersion()); // CraftBukkit
4739
+ this.world.getWorld().storeBukkitValues(nbt); // CraftBukkit - add pdc
4840
}
4941

5042
private static ListTag stringCollectionToTag(Set<String> stringCollection) {
51-
@@ -358,6 +375,25 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
43+
@@ -353,6 +_,25 @@
5244

5345
@Override
5446
public void setThundering(boolean thundering) {
@@ -74,7 +66,7 @@ index 385d424ed08a6f3202c263cc8acedbc32cdeae7c..2f4922a2035cc7d628dd2c979137163f
7466
this.thundering = thundering;
7567
}
7668

77-
@@ -378,6 +414,26 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
69+
@@ -373,6 +_,26 @@
7870

7971
@Override
8072
public void setRaining(boolean isRaining) {
@@ -101,7 +93,7 @@ index 385d424ed08a6f3202c263cc8acedbc32cdeae7c..2f4922a2035cc7d628dd2c979137163f
10193
this.raining = isRaining;
10294
}
10395

104-
@@ -444,6 +500,12 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
96+
@@ -439,6 +_,12 @@
10597
@Override
10698
public void setDifficulty(Difficulty difficulty) {
10799
this.settings = this.settings.withDifficulty(difficulty);
@@ -114,18 +106,18 @@ index 385d424ed08a6f3202c263cc8acedbc32cdeae7c..2f4922a2035cc7d628dd2c979137163f
114106
}
115107

116108
@Override
117-
@@ -580,6 +642,14 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
109+
@@ -574,6 +_,14 @@
110+
public LevelSettings getLevelSettings() {
118111
return this.settings.copy();
119112
}
120-
113+
+
121114
+ // CraftBukkit start - Check if the name stored in NBT is the correct one
122115
+ public void checkName(String name) {
123116
+ if (!this.settings.levelName.equals(name)) {
124117
+ this.settings.levelName = name;
125118
+ }
126119
+ }
127120
+ // CraftBukkit end
128-
+
121+
129122
@Deprecated
130123
public static enum SpecialWorldProperty {
131-
NONE,

0 commit comments

Comments
 (0)