aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason <[email protected]>2021-12-11 17:50:45 -0800
committerGitHub <[email protected]>2021-12-11 17:50:45 -0800
commit29bd57b4c8f3b2a1aa2263244e65ebcf6c3f876d (patch)
tree8fa6799b68b340b3c0008758d513956d2546dcd7
parent901fd942f6f0cb69face80c30dc806da90670a7e (diff)
downloadPaper-29bd57b4c8f3b2a1aa2263244e65ebcf6c3f876d.tar.gz
Paper-29bd57b4c8f3b2a1aa2263244e65ebcf6c3f876d.zip
Remove codec usage in chunk snapshot creation (#7093)
-rw-r--r--patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int-and-optimize-Pa.patch44
-rw-r--r--patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int.patch26
2 files changed, 44 insertions, 26 deletions
diff --git a/patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int-and-optimize-Pa.patch b/patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int-and-optimize-Pa.patch
new file mode 100644
index 0000000000..6f7e30efa6
--- /dev/null
+++ b/patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int-and-optimize-Pa.patch
@@ -0,0 +1,44 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jason Penilla <[email protected]>
+Date: Thu, 9 Dec 2021 00:08:11 -0800
+Subject: [PATCH] Fix ChunkSnapshot#isSectionEmpty(int) and optimize
+ PalettedContainer copying by not using codecs
+
+
+diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+index db344e5b9f96f317a232304587e6b1673fc6067d..d51476ca2aad08a0dd93a2e772dd7750afc939dc 100644
+--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
++++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+@@ -280,14 +280,17 @@ public class CraftChunk implements Chunk {
+ boolean[] sectionEmpty = new boolean[cs.length];
+ PalettedContainer<Biome>[] biome = (includeBiome || includeBiomeTempRain) ? new PalettedContainer[cs.length] : null;
+
+- Registry<Biome> iregistry = this.worldServer.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
+- Codec<PalettedContainer<Biome>> biomeCodec = PalettedContainer.codec(iregistry, iregistry.byNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS), null); // Paper - Anti-Xray - Add preset biomes
+
+ for (int i = 0; i < cs.length; i++) {
+- CompoundTag data = new CompoundTag();
+
+- data.put("block_states", ChunkSerializer.BLOCK_STATE_CODEC.encodeStart(NbtOps.INSTANCE, cs[i].getStates()).get().left().get());
+- sectionBlockIDs[i] = ChunkSerializer.BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, data.getCompound("block_states")).get().left().get();
++ // Paper start
++ sectionEmpty[i] = cs[i].hasOnlyAir(); // Paper - fix sectionEmpty array not being filled
++ if (!sectionEmpty[i]) {
++ sectionBlockIDs[i] = cs[i].getStates().copy(); // Paper - use copy instead of round tripping with codecs
++ } else {
++ sectionBlockIDs[i] = CraftChunk.emptyBlockIDs; // Paper - use cached instance for empty block sections
++ }
++ // Paper end
+
+ LevelLightEngine lightengine = chunk.level.getLightEngine();
+ DataLayer skyLightArray = lightengine.getLayerListener(LightLayer.SKY).getDataLayerData(SectionPos.of(x, i, z));
+@@ -306,8 +309,7 @@ public class CraftChunk implements Chunk {
+ }
+
+ if (biome != null) {
+- data.put("biomes", biomeCodec.encodeStart(NbtOps.INSTANCE, cs[i].getBiomes()).get().left().get());
+- biome[i] = biomeCodec.parse(NbtOps.INSTANCE, data.getCompound("biomes")).get().left().get();
++ biome[i] = cs[i].getBiomes().copy(); // Paper - use copy instead of round tripping with codecs
+ }
+ }
+
diff --git a/patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int.patch b/patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int.patch
deleted file mode 100644
index 8b84bbcaa0..0000000000
--- a/patches/server/0828-Fix-ChunkSnapshot-isSectionEmpty-int.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Jason Penilla <[email protected]>
-Date: Thu, 9 Dec 2021 00:08:11 -0800
-Subject: [PATCH] Fix ChunkSnapshot#isSectionEmpty(int)
-
-
-diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
-index db344e5b9f96f317a232304587e6b1673fc6067d..b4f7b91ac165e3171ffcf7d6a993af248d268959 100644
---- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
-+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
-@@ -286,8 +286,15 @@ public class CraftChunk implements Chunk {
- for (int i = 0; i < cs.length; i++) {
- CompoundTag data = new CompoundTag();
-
-+ // Paper start
-+ sectionEmpty[i] = cs[i].hasOnlyAir();
-+ if (!sectionEmpty[i]) {
- data.put("block_states", ChunkSerializer.BLOCK_STATE_CODEC.encodeStart(NbtOps.INSTANCE, cs[i].getStates()).get().left().get());
- sectionBlockIDs[i] = ChunkSerializer.BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, data.getCompound("block_states")).get().left().get();
-+ } else {
-+ sectionBlockIDs[i] = CraftChunk.emptyBlockIDs;
-+ }
-+ // Paper end
-
- LevelLightEngine lightengine = chunk.level.getLightEngine();
- DataLayer skyLightArray = lightengine.getLayerListener(LightLayer.SKY).getDataLayerData(SectionPos.of(x, i, z));