From 2a7f199b5f94075ab8077e1bf4cb3e77e502fbfe Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 9 Oct 2026 00:28:31 +0200 Subject: [PATCH] Fix the tree feature harness and the scene probes The tree fixture world now applies vanilla's edge shape updates for its obstacles (faceless vines, unsupported short grass), the vanilla fixture world answers environment attributes with defaults, and features that need structure templates or the pale moss registry, directly or through named features, are left to the decoration harnesses. The scene probes build their scene with World::test_scene since TestWorld was removed. Co-Authored-By: Claude Opus 5.5 --- .../examples/scene_collision_probe.rs | 2 +- .../examples/scene_motion_probe.rs | 4 +- crates/horizon-client/src/world.rs | 38 +++++++++++++++ .../examples/tree_feature_fixture.rs | 47 +++++++++++++++++++ .../parity/VanillaTreeFeatureOracle.java | 1 + tools/test_tree_feature_parity.py | 11 ++++- 6 files changed, 99 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/examples/scene_collision_probe.rs b/crates/horizon-client/examples/scene_collision_probe.rs index f1a0696de..bcbe1f745 100644 --- a/crates/horizon-client/examples/scene_collision_probe.rs +++ b/crates/horizon-client/examples/scene_collision_probe.rs @@ -35,7 +35,7 @@ fn main() -> Result<()> { return Err("radius must be 1..16".into()); } let assets = assets::Assets::load(&resources)?; - let world = world::TestWorld::new(&assets, radius)?; + let world = world::World::test_scene(&assets, radius)?; let binding = collisions::load(&resources, &assets.registry)?; let mut scene = collisions::SceneCollisions { world: &world, diff --git a/crates/horizon-client/examples/scene_motion_probe.rs b/crates/horizon-client/examples/scene_motion_probe.rs index 388d47e2a..98a370e39 100644 --- a/crates/horizon-client/examples/scene_motion_probe.rs +++ b/crates/horizon-client/examples/scene_motion_probe.rs @@ -5,7 +5,7 @@ use horizon_client::{ assets::Assets, collisions, motion::{MotionEvent, MotionResources, MotionWorld, PlayerMotion}, - world::TestWorld, + world::World, }; use horizon_core::geometry::Vec3; use horizon_core::{position::BlockPos, random::RandomSource}; @@ -185,7 +185,7 @@ fn main() -> Result<()> { let root = PathBuf::from(&args[0]); let dir = PathBuf::from(&args[1]); let assets = Assets::load(&root)?; - let mut scene = TestWorld::new(&assets, 1)?; + let mut scene = World::test_scene(&assets, 1)?; let binding = collisions::load(&root, &assets.registry)?; let resources = MotionResources::load(&root, &assets)?; fs::write( diff --git a/crates/horizon-client/src/world.rs b/crates/horizon-client/src/world.rs index 32840e003..90305eed5 100644 --- a/crates/horizon-client/src/world.rs +++ b/crates/horizon-client/src/world.rs @@ -104,6 +104,44 @@ impl World { weather: Weather::default(), } } + /// A controlled blockstate scene for the native scene probes: material + /// layers, a stepped pyramid and the model gallery. Not generated terrain. + pub fn test_scene(assets: &crate::assets::Assets, radius: i32) -> crate::Result { + let air = assets.registry.default_state("minecraft:air").ok_or("missing air state")?; + let mut world = Self::new(air, 0); + for cz in -radius..=radius { + for cx in -radius..=radius { + world.chunks.insert((cx, cz), Arc::new(Chunk::empty(cx, cz))); + for z in 0..16 { + for x in 0..16 { + for y in 0..4 { + let layer = match y { + 0 => 0, + 1 | 2 => 1, + _ if (cx + cz) & 1 == 0 => 2, + _ => 3, + }; + world.set(cx * 16 + x, y, cz * 16 + z, assets.material_states[layer])?; + } + } + } + } + } + for y in 4..11 { + for z in -10_i32..=10 { + for x in -10_i32..=10 { + if x.abs().max(z.abs()) <= 10 - (y - 4) { + world.set(x, y, z, assets.material_states[if y & 1 == 0 { 4 } else { 5 }])?; + } + } + } + } + for (position, state) in &assets.model_placements { + world.set(position.x, position.y, position.z, *state)?; + } + world.revision = 0; + Ok(world) + } /// Resident storage write; marks the touched sections (and neighbours on /// section borders) for remeshing and the surrounding chunks for relighting. /// Neighbour updates, drops and block entities belong to the gameplay layer. diff --git a/crates/horizon-world/examples/tree_feature_fixture.rs b/crates/horizon-world/examples/tree_feature_fixture.rs index 93b89ad9c..b61e7fcde 100644 --- a/crates/horizon-world/examples/tree_feature_fixture.rs +++ b/crates/horizon-world/examples/tree_feature_fixture.rs @@ -126,6 +126,12 @@ struct World<'a, 'r, W> { chest: BlockStateId, world_random: LegacyRandom, water_mask: u8, + /// A vine without faces and air: the only fixture obstacle that changes + /// under a shape update (VineBlock.updateShape). + faceless_vine: Option, + /// VegetationBlock obstacles (short grass, fern): air once unsupported. + vegetation: BTreeSet, + air: BlockStateId, } impl World<'_, '_, W> { fn get(&self, p: [i32; 3]) -> BlockStateId { @@ -190,6 +196,33 @@ impl SurvivalWorld for World<'_, '_, W> { } } impl PlacementContext for World<'_, '_, W> { + /// StructureTemplate.updateShapeAtEdge: the state, then its neighbour. + /// VineBlock.updateShape drops a vine left without faces on any update + /// but from below; the other fixture states keep their shape. + fn update_shape_at_face( + &mut self, + position: [i32; 3], + direction: Direction, + flags: i32, + ) -> Result<(), PlacementQueryError> { + let n = direction.normal(); + let neighbor = [position[0] + n[0], position[1] + n[1], position[2] + n[2]]; + for (p, from) in [(position, direction), (neighbor, direction.opposite())] { + let state = self.get(p); + let drop = if Some(state) == self.faceless_vine { + from != Direction::Down + } else if self.vegetation.contains(&state) { + let survival = self.survival; + !survival.can_survive(self, state, p).map_err(query)? + } else { + false + }; + if drop { + self.set_block(p, self.air, flags & !1).map_err(query)?; + } + } + Ok(()) + } fn collision_full_block( &mut self, state: BlockStateId, @@ -569,6 +602,17 @@ fn main() -> Result<(), Box> { &fluid_tags.tags, )?; let chest = registry.default_state("minecraft:chest").unwrap(); + let vegetation: BTreeSet = ["minecraft:short_grass", "minecraft:fern"] + .iter() + .filter_map(|n| by_name.get(*n)) + .flatten() + .copied() + .collect(); + let faceless_vine = by_name.get("minecraft:vine").and_then(|ids| { + ids.iter() + .copied() + .find(|id| registry.state(*id).is_some_and(|s| s.properties.values().all(|v| v == "false"))) + }); let water_mask = fluid_tags.tags["minecraft:water"] .iter() .fold(0, |mask, name| { @@ -594,6 +638,9 @@ fn main() -> Result<(), Box> { chest, world_random: LegacyRandom::new(0), water_mask, + faceless_vine, + vegetation: vegetation.clone(), + air: BlockStateId(air), }; let seed = f["seed"].as_i64().unwrap(); if f["legacy"].as_bool().unwrap() { diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaTreeFeatureOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaTreeFeatureOracle.java index b96d7b70d..782ce358b 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaTreeFeatureOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaTreeFeatureOracle.java @@ -92,6 +92,7 @@ public final class VanillaTreeFeatureOracle { case "scheduleTick":return null; // Edge shape updates also schedule ticks; not compared. case "setCurrentlyGenerating":case "playSound":case "levelEvent":case "gameEvent":case "blockEvent":return null; case "getEntities":return java.util.List.of(); + case "environmentAttributes":return net.minecraft.world.attribute.EnvironmentAttributeReader.EMPTY; // attribute defaults case "getBlockEntity":{ if(args.length!=1)break;var p=((BlockPos)args[0]).immutable();var state=get(p); if(state.is(Blocks.CHEST))return chests.computeIfAbsent(p,key->new ChestBlockEntity(key,state){@Override public void setLootTable(net.minecraft.resources.ResourceKey table,long seed){out.println("loot "+xyz(key)+" "+table.identifier()+" "+seed);super.setLootTable(table,seed);}}); diff --git a/tools/test_tree_feature_parity.py b/tools/test_tree_feature_parity.py index a8a0781b2..66f7a6eb7 100644 --- a/tools/test_tree_feature_parity.py +++ b/tools/test_tree_feature_parity.py @@ -2,6 +2,7 @@ """Compare vanilla tree, fallen-tree and ore features block-for-block with vanilla.""" import argparse import json +import re import os from pathlib import Path import platform @@ -42,10 +43,18 @@ def corpus(facts,resources): seeds=[0,1,-1,0x5DEECE66D,0x123456789abcdef,-8070450532247928832] origins=[[8,65,8],[15,65,0],[0,65,15],[-1,65,-17],[31,65,-16],[100003,65,-4097]] trees,ores,others=[],[],[] + def needs_level(text,seen=frozenset()): + # Pale moss needs the level's feature registry and server level; templates need structure + # resources. Both are excluded directly or through named features. + if 'pale_moss' in text or '"minecraft:template"' in text:return True + for ref in set(re.findall(r'"(minecraft:[a-z0-9_/]+)"',text))-seen: + for table in ('features','placed'): + if ref in resources.get(table,{}) and needs_level(resources[table][ref],seen|{ref}):return True + return False for name,text in resources['features'].items(): value=json.loads(text);kind=value['type'].removeprefix('minecraft:') + if needs_level(text):continue if kind in ('tree','fallen_tree'): - if 'pale_moss' in text:continue # needs the level's feature registry and server level trees.append(name) elif kind in ('ore','scattered_ore'):ores.append(name) elif kind not in ('freeze_top_layer','template','fossil'):others.append(name) # templates need structure resources