Files
horizon-airdef/crates/horizon-client/examples/scene_collision_probe.rs
T
Ludovic Marie 6ce83021b5 Powder snow: sinking, freezing, leather boots, buckets and falling blocks
Powder snow was inert: the player's collision context never carried its
fall distance or boots, block-inside effects never ran for the player,
frozen ticks stayed 0 and the empty bucket only took fluids.

Player (PlayerMotion, LivingEntity.aiStep order):
- PowderSnowBlock.getCollisionShape gets the player's fall distance and
  leather boots: it sinks through, walks on top in leather boots (sinks
  when crouching), lands on the 0.9-high shape after a fall of more
  than 2.5 blocks.
- Entity.applyEffectsFromBlocks over this tick's movement path (the
  ported block sweep, StepBasedCollector steps): entityInside makes it
  stuck (0.9, 1.5, 0.9) while its feet are in powder snow and sends the
  server's snowflake from the level random; FREEZE sets isInPowderSnow
  and adds a frozen tick per step; EXTINGUISH destroys the snow if the
  player burns and puts the fire out. ServerPlayer.onInsideBlock fires
  enter_block for every block entered (which also unlocks the boat
  recipes in water, and the end gateway advancement).
- baseTick's wasInPowderSnow lets leather boots climb out (living_air).
- Server freezing: thawing 2 a tick, the powder_snow frost modifier
  (-0.05 x percent frozen, not over air), freeze damage every 40 ticks
  when fully frozen; leather armor (#freeze_immune_wearables) and
  spectators don't freeze.
- HUD: the powder snow outline overlay and frozen hearts.

Items and blocks:
- BucketItem.use on powder snow: pickupBlock (2001), used statistic,
  fill sound, FLUID_PICKUP, createFilledResult, filled_bucket trigger.
- SolidBucketItem: the empty_powder_snow place sound and an empty bucket
  back in survival.
- Falling blocks land on powder snow, or end up inside it and break
  after a fall of more than 2.5 blocks.

test_native_scene_motion gains powder snow fixtures ("snow_tick": the
oracle runs vanilla's real applyEffectsFromBlocks and freezing) and
prints frozen ticks, the snow flags and the stuck multiplier.

Fixes #62

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 15:45:55 +02:00

78 lines
2.6 KiB
Rust

//! Headless transport exercising the actual client resource loader and chunks.
#![forbid(unsafe_code)]
use horizon_client::{assets, collisions, world};
use horizon_core::geometry::{Aabb, Vec3};
use serde_json::Value;
use std::{
fs,
io::{BufRead, Write},
path::PathBuf,
};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
fn vector(value: &Value) -> Result<Vec3> {
let a = value
.as_array()
.filter(|v| v.len() == 3)
.ok_or("expected vector")?;
let number = |i: usize| -> Result<f64> {
Ok(f64::from_bits(u64::from_str_radix(
a[i].as_str().ok_or("expected double bits")?,
16,
)?))
};
Ok(Vec3::new(number(0)?, number(1)?, number(2)?))
}
fn main() -> Result<()> {
let args: Vec<_> = std::env::args().skip(1).collect();
if args.len() != 3 {
return Err("usage: scene_collision_probe RESOURCES FIXTURE_DIRECTORY RADIUS".into());
}
let resources = PathBuf::from(&args[0]);
let dir = PathBuf::from(&args[1]);
let radius: i32 = args[2].parse()?;
if !(1..=16).contains(&radius) {
return Err("radius must be 1..16".into());
}
let assets = assets::Assets::load(&resources)?;
let world = world::World::test_scene(&assets, radius)?;
let binding = collisions::load(&resources, assets.registry)?;
let mut scene = collisions::SceneCollisions {
world: &world,
binding: &binding,
subject: None,
};
fs::write(
dir.join("scene.json"),
serde_json::to_vec(&serde_json::json!({
"radius":radius,"resident_chunks":world.chunks.len(),"model_gallery":assets.model_gallery,
}))?,
)?;
let mut output = std::io::BufWriter::new(fs::File::create(dir.join("rust.txt"))?);
for line in std::io::BufReader::new(fs::File::open(dir.join("inputs.txt"))?).lines() {
let f: Value = serde_json::from_str(&line?)?;
let bounds = Aabb::new(vector(&f["min"])?, vector(&f["max"])?);
let delta = vector(&f["delta"])?;
let step = f32::from_bits(u32::from_str_radix(
f["step"].as_str().ok_or("expected step bits")?,
16,
)?);
let movement = scene.resolve(
bounds,
delta,
step,
f["grounded"].as_bool().ok_or("expected grounded flag")?,
)?;
writeln!(
output,
"move {:016x} {:016x} {:016x} clear {} {}",
movement.x.to_bits(),
movement.y.to_bits(),
movement.z.to_bits(),
scene.unobstructed(bounds)?,
scene.unobstructed(bounds.move_by(movement))?
)?;
}
Ok(())
}