Skip to content

Commit 8c189d0

Browse files
committed
Create sections for chunk conversion if non-existant
Required to add in the new biome sections
1 parent 358ceb8 commit 8c189d0

File tree

1 file changed

+49
-48
lines changed

1 file changed

+49
-48
lines changed

patches/server/0781-Rewrite-dataconverter-system.patch

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15313,10 +15313,10 @@ index 0000000000000000000000000000000000000000..d28ade80499dce882a9a84309a2a0da5
1531315313
+}
1531415314
diff --git a/src/main/java/ca/spottedleaf/dataconverter/minecraft/versions/V2832.java b/src/main/java/ca/spottedleaf/dataconverter/minecraft/versions/V2832.java
1531515315
new file mode 100644
15316-
index 0000000000000000000000000000000000000000..6a975a5e69f4aad4b65aaf1300b5136d72ea6499
15316+
index 0000000000000000000000000000000000000000..b1049823fc2ff1c8183f4664ff4d40da6495f9ee
1531715317
--- /dev/null
1531815318
+++ b/src/main/java/ca/spottedleaf/dataconverter/minecraft/versions/V2832.java
15319-
@@ -0,0 +1,919 @@
15319+
@@ -0,0 +1,920 @@
1532015320
+package ca.spottedleaf.dataconverter.minecraft.versions;
1532115321
+
1532215322
+import ca.spottedleaf.dataconverter.converters.DataConverter;
@@ -15710,73 +15710,74 @@ index 0000000000000000000000000000000000000000..6a975a5e69f4aad4b65aaf1300b5136d
1571015710
+ final MapType<String>[] newBiomes = createBiomeSections(level, isOverworld, minSection, isAlreadyExtended);
1571115711
+ final MapType<String> wrappedEmptyBlockPalette = getEmptyBlockPalette();
1571215712
+
15713-
+ final ListType sections = level.getList("Sections", ObjectType.MAP);
15713+
+ ListType sections = level.getList("Sections", ObjectType.MAP);
15714+
+ if (sections == null) {
15715+
+ level.setList("Sections", sections = Types.NBT.createEmptyList());
15716+
+ }
1571415717
+
1571515718
+ // must update sections for two things:
1571615719
+ // 1. the biomes are now stored per section, so we must insert the biomes palette into each section (and create them if they don't exist)
1571715720
+ // 2. each section must now have block states (or at least DFU is ensuring they do, but current code does not require)
1571815721
+ V2841.SimplePaletteReader bottomSection = null;
1571915722
+ final Set<String> allBlocks = new HashSet<>();
15720-
+ if (sections != null) {
15721-
+ final IntOpenHashSet existingSections = new IntOpenHashSet();
15723+
+ final IntOpenHashSet existingSections = new IntOpenHashSet();
1572215724
+
15723-
+ for (int i = 0, len = sections.size(); i < len; ++i) {
15724-
+ final MapType<String> section = sections.getMap(i);
15725+
+ for (int i = 0, len = sections.size(); i < len; ++i) {
15726+
+ final MapType<String> section = sections.getMap(i);
1572515727
+
15726-
+ final int y = section.getInt("Y");
15727-
+ final int sectionIndex = y - minSection;
15728+
+ final int y = section.getInt("Y");
15729+
+ final int sectionIndex = y - minSection;
1572815730
+
15729-
+ existingSections.add(y);
15731+
+ existingSections.add(y);
1573015732
+
15731-
+ // add in relevant biome section
15732-
+ if (sectionIndex >= 0 && sectionIndex < newBiomes.length) {
15733-
+ // exclude out of bounds sections (i.e the light sections above and below the world)
15734-
+ section.setMap("biomes", newBiomes[sectionIndex]);
15735-
+ }
15733+
+ // add in relevant biome section
15734+
+ if (sectionIndex >= 0 && sectionIndex < newBiomes.length) {
15735+
+ // exclude out of bounds sections (i.e the light sections above and below the world)
15736+
+ section.setMap("biomes", newBiomes[sectionIndex]);
15737+
+ }
1573615738
+
15737-
+ // update palette
15738-
+ final ListType palette = section.getList("Palette", ObjectType.MAP);
15739-
+ final long[] blockStates = section.getLongs("BlockStates");
15739+
+ // update palette
15740+
+ final ListType palette = section.getList("Palette", ObjectType.MAP);
15741+
+ final long[] blockStates = section.getLongs("BlockStates");
1574015742
+
15741-
+ section.remove("Palette");
15742-
+ section.remove("BlockStates");
15743+
+ section.remove("Palette");
15744+
+ section.remove("BlockStates");
1574315745
+
15744-
+ if (palette != null) {
15745-
+ for (int j = 0, len2 = palette.size(); j < len2; ++j) {
15746-
+ allBlocks.add(V2841.getBlockId(palette.getMap(j)));
15747-
+ }
15746+
+ if (palette != null) {
15747+
+ for (int j = 0, len2 = palette.size(); j < len2; ++j) {
15748+
+ allBlocks.add(V2841.getBlockId(palette.getMap(j)));
1574815749
+ }
15750+
+ }
1574915751
+
15750-
+ final MapType<String> palettedContainer;
15751-
+ if (palette != null && blockStates != null) {
15752-
+ // only if both exist, same as DFU, same as legacy chunk loading code
15753-
+ section.setMap("block_states", palettedContainer = wrapPaletteOptimised(palette, blockStates));
15754-
+ } else {
15755-
+ section.setMap("block_states", palettedContainer = wrappedEmptyBlockPalette.copy()); // must write a palette now, copy so that later edits do not edit them all
15756-
+ }
15752+
+ final MapType<String> palettedContainer;
15753+
+ if (palette != null && blockStates != null) {
15754+
+ // only if both exist, same as DFU, same as legacy chunk loading code
15755+
+ section.setMap("block_states", palettedContainer = wrapPaletteOptimised(palette, blockStates));
15756+
+ } else {
15757+
+ section.setMap("block_states", palettedContainer = wrappedEmptyBlockPalette.copy()); // must write a palette now, copy so that later edits do not edit them all
15758+
+ }
1575715759
+
15758-
+ if (section.getInt("Y", Integer.MAX_VALUE) == 0) {
15759-
+ bottomSection = new V2841.SimplePaletteReader(palettedContainer.getList("palette", ObjectType.MAP), palettedContainer.getLongs("data"));
15760-
+ }
15760+
+ if (section.getInt("Y", Integer.MAX_VALUE) == 0) {
15761+
+ bottomSection = new V2841.SimplePaletteReader(palettedContainer.getList("palette", ObjectType.MAP), palettedContainer.getLongs("data"));
1576115762
+ }
15763+
+ }
1576215764
+
15763-
+ // all existing sections updated, now we must create new sections just for the biomes migration
15764-
+ for (int sectionIndex = 0; sectionIndex < newBiomes.length; ++sectionIndex) {
15765-
+ final int sectionY = sectionIndex + minSection;
15766-
+ if (!existingSections.add(sectionY)) {
15767-
+ // exists already
15768-
+ continue;
15769-
+ }
15765+
+ // all existing sections updated, now we must create new sections just for the biomes migration
15766+
+ for (int sectionIndex = 0; sectionIndex < newBiomes.length; ++sectionIndex) {
15767+
+ final int sectionY = sectionIndex + minSection;
15768+
+ if (!existingSections.add(sectionY)) {
15769+
+ // exists already
15770+
+ continue;
15771+
+ }
1577015772
+
15771-
+ final MapType<String> newSection = Types.NBT.createEmptyMap();
15772-
+ sections.addMap(newSection);
15773+
+ final MapType<String> newSection = Types.NBT.createEmptyMap();
15774+
+ sections.addMap(newSection);
1577315775
+
15774-
+ newSection.setByte("Y", (byte)sectionY);
15775-
+ // must write a palette now, copy so that later edits do not edit them all
15776-
+ newSection.setMap("block_states", wrappedEmptyBlockPalette.copy());
15776+
+ newSection.setByte("Y", (byte)sectionY);
15777+
+ // must write a palette now, copy so that later edits do not edit them all
15778+
+ newSection.setMap("block_states", wrappedEmptyBlockPalette.copy());
1577715779
+
15778-
+ newSection.setGeneric("biomes", newBiomes[sectionIndex]);
15779-
+ }
15780+
+ newSection.setGeneric("biomes", newBiomes[sectionIndex]);
1578015781
+ }
1578115782
+
1578215783
+ // update status so interpolation can take place

0 commit comments

Comments
 (0)