Skip to content

Commit

Permalink
Upgrade chunk data in memory for 1.17 chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHeijden committed Dec 2, 2021
1 parent 292c8fa commit ec143b4
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,28 @@ public LevelChunkSection[] getChunkSections() throws IOException {

int sectionsCount = serverLevel.getSectionsCount();
var chunkSections = new LevelChunkSection[sectionsCount];
var chunkMap = serverLevel.getChunkSource().chunkMap;
var chunkPos = new ChunkPos(chunkX, chunkZ);

CompoundTag tag = serverLevel.getChunkSource().chunkMap.read(new ChunkPos(chunkX, chunkZ));
CompoundTag tag = chunkMap.read(chunkPos);
if (tag == null) return chunkSections;
tag = chunkMap.upgradeChunkTag(
serverLevel.getTypeKey(),
() -> serverLevel.getServer().overworld().getDataStorage(),
tag,
chunkMap.generator.getTypeNameForDataFixer(),
chunkPos,
serverLevel
);

ListTag sectionsTagList = tag.getList("sections", 10);

DataResult<PalettedContainer<BlockState>> dataResult;
for (var i = 0; i < sectionsTagList.size(); i++) {
CompoundTag sectionTag = sectionsTagList.getCompound(i);
var chunkSectionPart = sectionTag.getByte("Y");
var sectionIndex = serverLevel.getSectionIndexFromSectionY(chunkSectionPart);
if (sectionIndex < 0 || sectionIndex >= chunkSections.length) continue;

PalettedContainer<BlockState> blockStateContainer;
if (sectionTag.contains("block_states", 10)) {
Expand All @@ -72,7 +84,7 @@ public LevelChunkSection[] getChunkSections() throws IOException {
}

LevelChunkSection chunkSection = new LevelChunkSection(chunkSectionPart, blockStateContainer, null);
chunkSections[serverLevel.getSectionIndexFromSectionY(chunkSectionPart)] = chunkSection;
chunkSections[sectionIndex] = chunkSection;
}

return chunkSections;
Expand Down

0 comments on commit ec143b4

Please sign in to comment.