From afb92f7c8415f2fb321050a0d69a7b928e7bb277 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 10 Oct 2026 07:25:59 +0200 Subject: [PATCH] Fix the chunk oracle's enabled features so jigsaw final states parse Co-Authored-By: Claude Sonnet 5.5 --- .../src/worldgen/generator_decoration.rs | 51 +++++++++++++++++-- .../parity/VanillaChunkGenerationOracle.java | 4 +- tools/test_chunk_generation_parity.py | 9 +++- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/crates/horizon-world/src/worldgen/generator_decoration.rs b/crates/horizon-world/src/worldgen/generator_decoration.rs index 7cef04bd9..1f35b08fa 100644 --- a/crates/horizon-world/src/worldgen/generator_decoration.rs +++ b/crates/horizon-world/src/worldgen/generator_decoration.rs @@ -634,14 +634,55 @@ impl PlacementContext for World<'_> { .map(|shape| shape.is_empty()) .map_err(query) } - /// Block entities are not stored in proto chunks; loot tables are no-ops. + /// RandomizableContainer.setBlockEntityLootTable: only a container block that + /// is actually there takes the table, and then it draws the loot seed. fn set_block_entity_loot_table( &mut self, - _: [i32; 3], - _: &str, - _: &mut impl horizon_core::random::RandomSource, + position: [i32; 3], + table: &str, + random: &mut impl horizon_core::random::RandomSource, ) -> Result<(), PlacementQueryError> { - Ok(()) + use crate::nbt::Tag; + let chunk = self.region.chunk(position[0] >> 4, position[2] >> 4)?; + let state = chunk.block(position[0], position[1], position[2]); + let registry = self.decoration.bindings.registry(); + let Some(name) = registry.state(state).map(|s| s.name.to_string()) else { + return Ok(()); + }; + if !matches!( + name.as_str(), + "minecraft:chest" | "minecraft:trapped_chest" | "minecraft:barrel" + ) { + return Ok(()); + } + let mut nbt = crate::nbt::Compound::new(); + nbt.insert("id".into(), Tag::String(name.as_str().into())); + nbt.insert("LootTable".into(), Tag::String(table.into())); + nbt.insert("LootTableSeed".into(), Tag::Long(random.next_long())); + self.set_block_entity(position, nbt) + } + /// SpawnerBlockEntity.setEntityId: the next spawn data and no potentials. + fn configure_spawner( + &mut self, + position: [i32; 3], + entity: &str, + ) -> Result<(), PlacementQueryError> { + use crate::nbt::Tag; + let chunk = self.region.chunk(position[0] >> 4, position[2] >> 4)?; + let state = chunk.block(position[0], position[1], position[2]); + let registry = self.decoration.bindings.registry(); + if registry.state(state).map(|s| s.name.as_str()) != Some("minecraft:spawner") { + return Ok(()); + } + let mut mob = crate::nbt::Compound::new(); + mob.insert("id".into(), Tag::String(entity.into())); + let mut data = crate::nbt::Compound::new(); + data.insert("entity".into(), Tag::Compound(mob)); + let mut nbt = crate::nbt::Compound::new(); + nbt.insert("id".into(), Tag::String("minecraft:mob_spawner".into())); + nbt.insert("SpawnData".into(), Tag::Compound(data)); + nbt.insert("SpawnPotentials".into(), Tag::List(Vec::new())); + self.set_block_entity(position, nbt) } fn attachment_at( &mut self, diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaChunkGenerationOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaChunkGenerationOracle.java index 97844fe80..825f6e3d2 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaChunkGenerationOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaChunkGenerationOracle.java @@ -101,7 +101,7 @@ public final class VanillaChunkGenerationOracle { } @Override public net.minecraft.world.flag.FeatureFlagSet enabledFeatures() { - return net.minecraft.world.flag.FeatureFlagSet.of(); + return net.minecraft.world.flag.FeatureFlags.DEFAULT_FLAGS; // an empty set filters every block out of holderLookup, so jigsaw final states fail to parse } @Override public RegistryAccess registryAccess() { @@ -318,7 +318,7 @@ public final class VanillaChunkGenerationOracle { var id = access.lookupOrThrow(Registries.STRUCTURE).getKey(start.getStructure()); if (System.getenv("HORIZON_PIECES") != null) for (var piece : start.getPieces()) { var pb = piece.getBoundingBox(); - w.println("piece " + x + " " + z + " " + net.minecraft.core.registries.BuiltInRegistries.STRUCTURE_PIECE.getKey(piece.getType()) + " " + pb.minX() + " " + pb.minY() + " " + pb.minZ() + " " + pb.maxX() + " " + pb.maxY() + " " + pb.maxZ()); + w.println("piece " + x + " " + z + " " + net.minecraft.core.registries.BuiltInRegistries.STRUCTURE_PIECE.getKey(piece.getType()) + " " + pb.minX() + " " + pb.minY() + " " + pb.minZ() + " " + pb.maxX() + " " + pb.maxY() + " " + pb.maxZ() + (piece instanceof net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece pool ? " " + pool.getElement() + " rot=" + pool.getRotation() : "")); } w.println("start " + id + " " + x + " " + z + " " + box.minX() + " " + box.minY() + " " + box.minZ() + " " + box.maxX() + " " + box.maxY() + " " + box.maxZ()); } diff --git a/tools/test_chunk_generation_parity.py b/tools/test_chunk_generation_parity.py index 2a1a13177..441da5a20 100644 --- a/tools/test_chunk_generation_parity.py +++ b/tools/test_chunk_generation_parity.py @@ -144,6 +144,8 @@ def nbt_matches(vanilla, rust, default): Horizon sets must match, and every other vanilla key must be the fresh default.""" if isinstance(vanilla, dict) and isinstance(rust, dict): default = default if isinstance(default, dict) else {} + if 'LootTableSeed' in rust and 'LootTable' not in rust: + rust = {k: v for k, v in rust.items() if k != 'LootTableSeed'} # vanilla saves the seed only with a table for key, value in vanilla.items(): if key in ('x', 'y', 'z') or (key == 'components' and value == {}): continue @@ -152,7 +154,7 @@ def nbt_matches(vanilla, rust, default): return False elif value != default.get(key): return False - return all(key in vanilla or key in ('x', 'y', 'z') for key in rust) + return all(key in vanilla or key in ('x', 'y', 'z') or nbt_matches(default.get(key), rust[key], None) for key in rust) if isinstance(vanilla, list) and isinstance(rust, list): return len(vanilla) == len(rust) and all(nbt_matches(a, b, None) for a, b in zip(vanilla, rust)) if isinstance(vanilla, tuple) and isinstance(rust, tuple) and vanilla[0] in 'bsil' and rust[0] in 'bsil': @@ -162,8 +164,11 @@ def nbt_matches(vanilla, rust, default): def entity_matches(vanilla, rust): - if rust is None or vanilla is None: + if vanilla is None: return False + if rust is None: + # A DUMMY pending entry in a proto chunk: vanilla creates the default block entity on demand. + return nbt_matches(parse_nbt(vanilla[0])[0], {}, parse_nbt(vanilla[1])[0]) return nbt_matches(parse_nbt(vanilla[0])[0], parse_nbt(rust[0])[0], parse_nbt(vanilla[1])[0])