Build against the 26.3 dev bundle (26.3.build.151-beta; no stable build
exists yet).
26.3 rewrote the block palette in region files: a default-state block is a
bare string, any other state is {id, properties}, and a list mixing both
wraps the strings as {"": name}. The parser cast every entry to a
compound with Name/Properties, so every chunk saved by 26.3 threw
ClassCastException and the whole region failed to render. Both formats are
read now (a region holds a mix until every chunk is re-saved), and a chunk
that fails to parse is skipped instead of aborting the region.
This commit is contained in:
1 parent
8d4b7df1ce
commit
9f6b0772f0
6 files changed
+112
-10
No files matched your search
@@ -263,8 +263,7 @@ public class ChunkSectionParser {
|
||||
if (blockStates.contains("palette", Tag.TAG_LIST)) {
|
||||
Tag.ListTag paletteList = blockStates.getList("palette", Tag.TAG_COMPOUND);
|
||||
for (int i = 0; i < paletteList.items().size(); i++) {
|
||||
Tag.Compound stateTag = (Tag.Compound) paletteList.items().get(i);
|
||||
BlockState blockState = parseBlockState(stateTag);
|
||||
BlockState blockState = parsePaletteEntry(paletteList.items().get(i));
|
||||
blockPalette.add(blockState);
|
||||
blockNames.add(blockState.name());
|
||||
}
|
||||
@@ -345,22 +344,57 @@ public class ChunkSectionParser {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* One {@code block_states.palette} entry, in any of the shapes a region file
|
||||
* can hold.
|
||||
*
|
||||
* <p>Up to 26.2 every entry is {@code {Name: "...", Properties: {...}}}. From
|
||||
* 26.3 a block in its default state is written as a bare string
|
||||
* ({@code "minecraft:stone"}) and any other state as
|
||||
* {@code {id: "...", properties: {...}}}; a list mixing both shapes has to be
|
||||
* all compounds, so the bare strings are wrapped as {@code {"": "..."}}.
|
||||
* A region keeps chunks in both formats until every chunk has been re-saved,
|
||||
* so the old shape stays supported. No properties means the default state,
|
||||
* which is also how Xaero reads a state written without them.</p>
|
||||
*/
|
||||
private static BlockState parsePaletteEntry(Tag entry) {
|
||||
if (entry instanceof Tag.StringTag str) {
|
||||
return new BlockState(str.value(), BlockState.EMPTY_PROPERTIES);
|
||||
}
|
||||
if (entry instanceof Tag.Compound compound) {
|
||||
return parseBlockState(compound);
|
||||
}
|
||||
// Keeps palette indices aligned with the data array.
|
||||
return new BlockState("minecraft:air", BlockState.EMPTY_PROPERTIES);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析单个方块状态的NBT
|
||||
*
|
||||
* <p>格式: {Name: "minecraft:grass_block", Properties: {snowy: "false"}}</p>
|
||||
* <p>格式: {Name: "minecraft:grass_block", Properties: {snowy: "false"}}
|
||||
* (26.3+: {@code id} / {@code properties}, or {@code ""} for a wrapped bare name)</p>
|
||||
*
|
||||
* @param stateTag 方块状态的NBT复合标签
|
||||
* @return 解析后的BlockState对象
|
||||
*/
|
||||
private static BlockState parseBlockState(Tag.Compound stateTag) {
|
||||
String name = stateTag.getString("Name");
|
||||
if (name.isEmpty()) {
|
||||
name = stateTag.getString("id");
|
||||
}
|
||||
if (name.isEmpty()) {
|
||||
name = stateTag.getString("");
|
||||
}
|
||||
if (name.isEmpty()) {
|
||||
name = "minecraft:air";
|
||||
}
|
||||
|
||||
if (!stateTag.contains("Properties", Tag.TAG_COMPOUND)) {
|
||||
String propsKey = stateTag.contains("Properties", Tag.TAG_COMPOUND) ? "Properties" : "properties";
|
||||
if (!stateTag.contains(propsKey, Tag.TAG_COMPOUND)) {
|
||||
return new BlockState(name, BlockState.EMPTY_PROPERTIES);
|
||||
}
|
||||
|
||||
Tag.Compound propsTag = stateTag.getCompound("Properties");
|
||||
Tag.Compound propsTag = stateTag.getCompound(propsKey);
|
||||
if (propsTag.children().isEmpty()) {
|
||||
return new BlockState(name, BlockState.EMPTY_PROPERTIES);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,12 @@ public final class McaRegionLoader {
|
||||
if (nbt == null) {
|
||||
continue;
|
||||
}
|
||||
grid[localX][localZ] = ChunkDataParser.parseChunk(localX, localZ, nbt, worldHeightRange);
|
||||
try {
|
||||
grid[localX][localZ] = ChunkDataParser.parseChunk(localX, localZ, nbt, worldHeightRange);
|
||||
} catch (RuntimeException e) {
|
||||
// One malformed chunk must not cost the whole region.
|
||||
LOGGER.warn("Failed to parse chunk ({}, {}), skipping: {}", localX, localZ, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return grid;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.mapsyncer.mca;
|
||||
|
||||
import com.mapsyncer.nbt.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/** Palette shapes as written by 26.2 and 26.3 servers (DataVersion 4790 / 5023). */
|
||||
class ChunkSectionParserTest {
|
||||
|
||||
@Test
|
||||
void readsPre263Compounds() {
|
||||
var section = parse(List.of(
|
||||
compound(Map.of("Name", str("minecraft:stone"))),
|
||||
compound(Map.of("Name", str("minecraft:oak_log"),
|
||||
"Properties", compound(Map.of("axis", str("x")))))));
|
||||
assertEquals(List.of("minecraft:stone", "minecraft:oak_log"), section.blockNames());
|
||||
assertEquals(Map.of("axis", "x"), section.blockPalette().get(1).properties());
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsBareStrings() {
|
||||
var section = parse(List.of(str("minecraft:bedrock"), str("minecraft:deepslate")));
|
||||
assertEquals(List.of("minecraft:bedrock", "minecraft:deepslate"), section.blockNames());
|
||||
assertEquals(Map.of(), section.blockPalette().get(1).properties());
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsMixed263Compounds() {
|
||||
var section = parse(List.of(
|
||||
compound(Map.of("", str("minecraft:deepslate"))),
|
||||
compound(Map.of("id", str("minecraft:pointed_dripstone"),
|
||||
"properties", compound(Map.of("vertical_direction", str("down")))))));
|
||||
assertEquals(List.of("minecraft:deepslate", "minecraft:pointed_dripstone"), section.blockNames());
|
||||
assertEquals(Map.of("vertical_direction", "down"), section.blockPalette().get(1).properties());
|
||||
}
|
||||
|
||||
private static ChunkSectionParser.SectionData parse(List<Tag> palette) {
|
||||
Map<String, Tag> blockStates = new LinkedHashMap<>();
|
||||
blockStates.put("palette", new Tag.ListTag("palette", Tag.TAG_COMPOUND, palette));
|
||||
Map<String, Tag> section = new LinkedHashMap<>();
|
||||
section.put("Y", new Tag.Byte("Y", (byte) 0));
|
||||
section.put("block_states", new Tag.Compound("block_states", blockStates));
|
||||
return ChunkSectionParser.parseSection(new Tag.Compound("", section));
|
||||
}
|
||||
|
||||
private static Tag.StringTag str(String value) {
|
||||
return new Tag.StringTag("", value);
|
||||
}
|
||||
|
||||
private static Tag.Compound compound(Map<String, Tag> children) {
|
||||
return new Tag.Compound("", children);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user