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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-09 00:28:31 +02:00
parent ebb1180bd5
commit 2a7f199b5f
6 changed files with 99 additions and 4 deletions
@@ -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,
@@ -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(
+38
View File
@@ -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<Self> {
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.
@@ -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<BlockStateId>,
/// VegetationBlock obstacles (short grass, fern): air once unsupported.
vegetation: BTreeSet<BlockStateId>,
air: BlockStateId,
}
impl<W: Write> World<'_, '_, W> {
fn get(&self, p: [i32; 3]) -> BlockStateId {
@@ -190,6 +196,33 @@ impl<W: Write> SurvivalWorld for World<'_, '_, W> {
}
}
impl<W: Write> 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<dyn std::error::Error>> {
&fluid_tags.tags,
)?;
let chest = registry.default_state("minecraft:chest").unwrap();
let vegetation: BTreeSet<BlockStateId> = ["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<dyn std::error::Error>> {
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() {
@@ -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<net.minecraft.world.level.storage.loot.LootTable> table,long seed){out.println("loot "+xyz(key)+" "+table.identifier()+" "+seed);super.setLootTable(table,seed);}});
+10 -1
View File
@@ -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