2021-12-12 02:50:45 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
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
2024-12-03 17:58:41 +01:00
index be44b03527bd17344f5d835ba9d0b47e4b55d45f..08956b81b9a3e5caf3adce6699149491ff190d90 100644
2021-12-12 02:50:45 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
2024-06-13 16:45:27 +02:00
@@ -338,14 +338,17 @@ public class CraftChunk implements Chunk {
2023-02-07 16:55:53 +01:00
PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>[] biome = (includeBiome || includeBiomeTempRain) ? new PalettedContainer[cs.length] : null;
2021-12-12 02:50:45 +01:00
2024-10-23 22:10:14 +02:00
Registry<net.minecraft.world.level.biome.Biome> iregistry = this.worldServer.registryAccess().lookupOrThrow(Registries.BIOME);
- Codec<PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>> biomeCodec = PalettedContainer.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
2022-02-28 23:02:20 +01:00
2021-12-12 02:50:45 +01:00
for (int i = 0; i < cs.length; i++) {
- CompoundTag data = new CompoundTag();
2024-10-23 22:10:14 +02:00
- data.put("block_states", SerializableChunkData.BLOCK_STATE_CODEC.encodeStart(NbtOps.INSTANCE, cs[i].getStates()).getOrThrow());
- sectionBlockIDs[i] = SerializableChunkData.BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, data.getCompound("block_states")).getOrThrow(SerializableChunkData.ChunkReadException::new);
2024-06-13 16:45:27 +02:00
- sectionEmpty[i] = cs[i].hasOnlyAir();
2024-01-18 22:00:40 +01:00
+ // Paper start - Fix ChunkSnapshot#isSectionEmpty(int); and remove codec usage
+ sectionEmpty[i] = cs[i].hasOnlyAir(); // fix sectionEmpty array not being filled
2021-12-12 02:50:45 +01:00
+ if (!sectionEmpty[i]) {
2024-01-18 22:00:40 +01:00
+ sectionBlockIDs[i] = cs[i].getStates().copy(); // use copy instead of round tripping with codecs
2021-12-12 02:50:45 +01:00
+ } else {
2024-01-18 22:00:40 +01:00
+ sectionBlockIDs[i] = CraftChunk.emptyBlockIDs; // use cached instance for empty block sections
2021-12-12 02:50:45 +01:00
+ }
2024-01-18 22:00:40 +01:00
+ // Paper end - Fix ChunkSnapshot#isSectionEmpty(int)
2021-12-12 02:50:45 +01:00
2023-04-07 20:39:13 +02:00
LevelLightEngine lightengine = this.worldServer.getLightEngine();
2023-10-27 01:34:58 +02:00
DataLayer skyLightArray = lightengine.getLayerListener(LightLayer.SKY).getDataLayerData(SectionPos.of(this.x, chunk.getSectionYFromSectionIndex(i), this.z)); // SPIGOT-7498: Convert section index
2024-06-13 16:45:27 +02:00
@@ -364,8 +367,7 @@ public class CraftChunk implements Chunk {
2021-12-12 02:50:45 +01:00
}
if (biome != null) {
2024-04-24 18:15:59 +02:00
- data.put("biomes", biomeCodec.encodeStart(NbtOps.INSTANCE, cs[i].getBiomes()).getOrThrow());
2024-10-23 22:10:14 +02:00
- biome[i] = biomeCodec.parse(NbtOps.INSTANCE, data.getCompound("biomes")).getOrThrow(SerializableChunkData.ChunkReadException::new);
2024-01-18 22:00:40 +01:00
+ biome[i] = ((PalettedContainer<Holder<net.minecraft.world.level.biome.Biome>>) cs[i].getBiomes()).copy(); // Paper - Perf: use copy instead of round tripping with codecs
2021-12-12 02:50:45 +01:00
}
}