Fix the chunk oracle's enabled features so jigsaw final states parse

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-10 07:25:59 +02:00
parent 50084d03d4
commit afb92f7c84
3 changed files with 55 additions and 9 deletions
@@ -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,
@@ -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());
}
+7 -2
View File
@@ -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])