chunk_generation: compare scheduled ticks; HORIZON_ORDER decoration order

Both dumps list each proto chunk's scheduled block and fluid ticks in
scheduling order (`t block|fluid NAME X Y Z PRIORITY`) and the harness
compares them: they run once the chunk is live, and the leaf ticks of
updateShapeAtEdge were missing without any block differing at FEATURES.

HORIZON_ORDER names a file of `x z` lines both sides decorate in, instead of
row-major: decoration is order dependent (a chunk's features write into its
neighbours), and vanilla's chunk system decorates around a player in its own
order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-13 23:38:02 +02:00
parent 897ca2aa5e
commit 2c8de2b015
3 changed files with 101 additions and 29 deletions
+72 -27
View File
@@ -4,11 +4,13 @@
//! With HORIZON_SCAN set, one rectangle lists the structure starts in it.
//!
//! Chunks are generated through biomes, terrain and carvers, then decorated in
//! row-major order over the target rectangle grown by one chunk, each with its
//! eight neighbours so feature spill persists, exactly as the oracle does.
//! row-major order over the target rectangle grown by one chunk (or in the
//! order HORIZON_ORDER lists), each with its eight neighbours so feature spill
//! persists, exactly as the oracle does.
//! For every target chunk this prints `chunk X Z`, one `q QY NAME...` line per
//! quart layer (16 columns, z-major), one `y Y ID...` line per block row and
//! one `be X Y Z CANONICAL_NBT` line per block entity.
//! one `be X Y Z CANONICAL_NBT` line per block entity and one `t block|fluid
//! NAME X Y Z PRIORITY` line per scheduled tick.
use horizon_core::position::ChunkPos;
use horizon_world::{
DATA_VERSION,
@@ -116,7 +118,8 @@ fn main() -> Result<(), Error> {
Ok(v)
})
.collect::<Result<Vec<_>, Error>>()?;
let data = GeneratorData::load(&resources.join("worldgen"), registry(&resources)?)?;
let blocks = registry(&resources)?;
let data = GeneratorData::load(&resources.join("worldgen"), blocks)?;
let generator = OverworldGenerator::for_dimension(data, seed, "minecraft:normal", &dimension)?;
let mut worker = generator.worker();
// HORIZON_PHASE: terrain (no decoration), structures (pieces only) or full.
@@ -171,31 +174,43 @@ fn main() -> Result<(), Error> {
}
let mut failed = 0;
let margin = i32::from(std::env::var_os("HORIZON_ISOLATED").is_none());
for z in z0 - margin..=z1 + margin {
for x in x0 - margin..=x1 + margin {
let mut region = Vec::with_capacity(9);
for dz in -1..=1 {
for dx in -1..=1 {
region.push(chunks.remove(&(x + dx, z + dz)).ok_or("missing chunk")?);
}
}
let mut region: [ProtoChunk; 9] = region.try_into().map_err(|_| "region size")?;
let stats = if phase == "terrain" {
Default::default()
} else {
worker.decorate(&mut region)?
};
if stats.failed > 0 || stats.unsupported > 0 {
failed += 1;
eprintln!(
"chunk {x} {z}: {} failed, {} unsupported {:?}",
stats.failed, stats.unsupported, stats.skipped
);
}
for (i, chunk) in region.into_iter().enumerate() {
chunks.insert((x + i as i32 % 3 - 1, z + i as i32 / 3 - 1), chunk);
// HORIZON_ORDER: a file of `x z` lines, the chunks to decorate in that
// order (the oracle reads the same file); row-major by default.
let order: Vec<(i32, i32)> = match std::env::var_os("HORIZON_ORDER") {
Some(path) => fs::read_to_string(path)?
.lines()
.filter_map(|l| {
let mut t = l.split_whitespace().map(str::parse::<i32>);
Some((t.next()?.ok()?, t.next()?.ok()?))
})
.collect(),
None => (z0 - margin..=z1 + margin)
.flat_map(|z| (x0 - margin..=x1 + margin).map(move |x| (x, z)))
.collect(),
};
for (x, z) in order {
let mut region = Vec::with_capacity(9);
for dz in -1..=1 {
for dx in -1..=1 {
region.push(chunks.remove(&(x + dx, z + dz)).ok_or("missing chunk")?);
}
}
let mut region: [ProtoChunk; 9] = region.try_into().map_err(|_| "region size")?;
let stats = if phase == "terrain" {
Default::default()
} else {
worker.decorate(&mut region)?
};
if stats.failed > 0 || stats.unsupported > 0 {
failed += 1;
eprintln!(
"chunk {x} {z}: {} failed, {} unsupported {:?}",
stats.failed, stats.unsupported, stats.skipped
);
}
for (i, chunk) in region.into_iter().enumerate() {
chunks.insert((x + i as i32 % 3 - 1, z + i as i32 / 3 - 1), chunk);
}
}
if failed > 0 {
eprintln!("{failed} chunks had failed or unsupported features");
@@ -233,6 +248,36 @@ fn main() -> Result<(), Error> {
canonical(&Tag::Compound(nbt.clone()), &mut text);
writeln!(w, "be {bx} {by} {bz}\t{text}")?;
}
// Scheduled ticks, in scheduling order (the order they run in).
for t in chunk.terrain.block_ticks().pack(0) {
let name = blocks
.state(horizon_world::registry::BlockStateId(t.kind.0))
.map_or("?", |s| s.name.as_str());
let p = t.pos;
writeln!(
w,
"t block {name} {} {} {} {}",
p.x, p.y, p.z, t.priority as i32
)?;
}
for t in chunk.terrain.fluid_ticks().pack(0) {
let name = [
"minecraft:empty",
"minecraft:flowing_water",
"minecraft:water",
"minecraft:flowing_lava",
"minecraft:lava",
]
.get(t.kind.0 as usize)
.copied()
.unwrap_or("?");
let p = t.pos;
writeln!(
w,
"t fluid {name} {} {} {} {}",
p.x, p.y, p.z, t.priority as i32
)?;
}
}
}
}
@@ -382,7 +382,19 @@ public final class VanillaChunkGenerationOracle {
Heightmap.primeHeightmaps(chunk, EnumSet.of(Heightmap.Types.MOTION_BLOCKING, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Heightmap.Types.OCEAN_FLOOR, Heightmap.Types.WORLD_SURFACE));
chunk.setPersistedStatus(ChunkStatus.TERRAIN);
}
for (int z = fz0; z <= fz1 && !phase.equals("terrain"); z++) for (int x = fx0; x <= fx1; x++) {
// HORIZON_ORDER: a file of "x z" lines, the chunks to decorate in that order (default: row-major).
List<int[]> order = new ArrayList<>();
if (System.getenv("HORIZON_ORDER") != null) {
for (String line : java.nio.file.Files.readAllLines(java.nio.file.Path.of(System.getenv("HORIZON_ORDER")))) {
String[] t = line.trim().split("\\s+");
if (t.length == 2) order.add(new int[]{Integer.parseInt(t[0]), Integer.parseInt(t[1])});
}
} else {
for (int z = fz0; z <= fz1; z++) for (int x = fx0; x <= fx1; x++) order.add(new int[]{x, z});
}
for (int[] at : order) {
if (phase.equals("terrain")) break;
int x = at[0], z = at[1];
var chunk = chunkAt.apply(x, z);
var region = regionFor.apply(ChunkStatus.FEATURES, chunk);
generator.applyBiomeDecoration(region, chunk, OracleLevel.structures.forWorldGenRegion(region));
@@ -423,6 +435,13 @@ public final class VanillaChunkGenerationOracle {
if ("DUMMY".equals(tag.getStringOr("id", ""))) tag = absent = fresh;
w.println("be " + pos.getX() + " " + pos.getY() + " " + pos.getZ() + "\t" + canonicalOf(tag) + "\t" + canonicalOf(absent));
}
// Scheduled ticks, in scheduling order (the order they run in).
if (target instanceof net.minecraft.world.level.chunk.ProtoChunk proto) {
for (var t : ((net.minecraft.world.ticks.ProtoChunkTicks<net.minecraft.world.level.block.Block>) proto.getBlockTicks()).scheduledTicks())
w.println("t block " + net.minecraft.core.registries.BuiltInRegistries.BLOCK.getKey(t.type()) + " " + t.pos().getX() + " " + t.pos().getY() + " " + t.pos().getZ() + " " + t.priority().getValue());
for (var t : ((net.minecraft.world.ticks.ProtoChunkTicks<net.minecraft.world.level.material.Fluid>) proto.getFluidTicks()).scheduledTicks())
w.println("t fluid " + net.minecraft.core.registries.BuiltInRegistries.FLUID.getKey(t.type()) + " " + t.pos().getX() + " " + t.pos().getY() + " " + t.pos().getZ() + " " + t.priority().getValue());
}
}
}
}
+9 -1
View File
@@ -88,13 +88,15 @@ def parse(path):
if line.startswith('chunk '):
_, x, z = line.split()
current = (int(x), int(z))
chunks[current] = {'q': {}, 'y': {}, 'be': {}}
chunks[current] = {'q': {}, 'y': {}, 'be': {}, 't': []}
elif line.startswith('q '):
_, q, row = line.split(' ', 2)
chunks[current]['q'][int(q)] = row
elif line.startswith('y '):
_, y, row = line.split(' ', 2)
chunks[current]['y'][int(y)] = row
elif line.startswith('t '):
chunks[current]['t'].append(line[2:])
elif line.startswith('be '):
head, *forms = line.split('\t')
parts = head.split(' ')
@@ -228,6 +230,12 @@ def compare(vanilla, rust, names, label, limit=6, quiet=False):
for key in sorted(set(a['be']) | set(b['be'])):
if not entity_matches(a['be'].get(key), b['be'].get(key)):
entity_diffs.append((key, a['be'].get(key, [None])[0], (b['be'].get(key) or [None])[0]))
# Scheduled ticks run once the chunk is live (leaves at a tree's edge, lake fluids).
if a.get('t', []) != b.get('t', []):
ta, tb = a.get('t', []), b.get('t', [])
first = next((i for i, (u, v) in enumerate(zip(ta, tb)) if u != v), min(len(ta), len(tb)))
block_diffs.append((pos[0] * 16, 0, pos[1] * 16, f'{len(ta)} ticks, #{first}: {ta[first] if first < len(ta) else "-"}',
f'{len(tb)} ticks, #{first}: {tb[first] if first < len(tb) else "-"}'))
if block_diffs or biome_diffs or entity_diffs:
chunks += 1
blocks += len(block_diffs)