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
2023-10-22 21:12:00 +02:00
index 593c73bf497ff571ea4c19867aa9be4b8272f39b..e03345e5b29040b851eec285b994df831aabef81 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
2023-09-23 04:06:03 +02:00
@@ -290,13 +290,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
2023-02-07 16:55:53 +01:00
Registry<net.minecraft.world.level.biome.Biome> iregistry = this.worldServer.registryAccess().registryOrThrow(Registries.BIOME);
- Codec<PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>> biomeCodec = PalettedContainer.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, iregistry.getHolderOrThrow(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();
- 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
2023-04-07 20:39:13 +02:00
LevelLightEngine lightengine = this.worldServer.getLightEngine();
2023-10-22 21:12:00 +02:00
DataLayer skyLightArray = lightengine.getLayerListener(LightLayer.SKY).getDataLayerData(SectionPos.of(x, chunk.getSectionYFromSectionIndex(i), z)); // SPIGOT-7498: Convert section index
2023-09-23 04:06:03 +02:00
@@ -315,8 +319,7 @@ public class CraftChunk implements Chunk {
2021-12-12 02:50:45 +01:00
}
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();
2023-02-07 16:55:53 +01:00
+ biome[i] = ((PalettedContainer<Holder<net.minecraft.world.level.biome.Biome>>) cs[i].getBiomes()).copy(); // Paper - use copy instead of round tripping with codecs
2021-12-12 02:50:45 +01:00
}
}