cb19660fbe
Add version-bound core, world data, geometry, generation and feature implementations with native client/server comparison tools and scoped evidence reports. Apply Horizon project branding. Workspace tests, Clippy and 147 Python tests passed. Full 51-family survival and expanded provider comparisons are still running; complete gameplay parity and a playable Rust client remain unfinished. Private game artifacts and the isolated simple-block placement work are excluded.
96 lines
3.6 KiB
Rust
96 lines
3.6 KiB
Rust
//! Differential transport for replacement rules over pinned block identities.
|
|
use horizon_core::random::{LegacyRandom, RandomSource, XoroshiroRandom};
|
|
use horizon_world::{
|
|
DATA_VERSION,
|
|
nbt::Tag,
|
|
registry::{BlockRegistry, BlockStateId},
|
|
worldgen::{block_feature::FeatureBlockBindings, rule_test::RuleTest, tags::TagDefinitions},
|
|
};
|
|
use serde_json::Value;
|
|
use std::{
|
|
fs,
|
|
io::{self, Write},
|
|
path::Path,
|
|
};
|
|
fn fixture(
|
|
f: &Value,
|
|
bindings: &FeatureBlockBindings<'_>,
|
|
mut random: impl RandomSource,
|
|
out: &mut impl Write,
|
|
) -> Result<(), Box<dyn std::error::Error>> {
|
|
match RuleTest::from_json(f["definition"].as_str().unwrap(), bindings) {
|
|
Err(_) => writeln!(out, "decode error")?,
|
|
Ok(rule) => {
|
|
writeln!(out, "decode ok")?;
|
|
let mut index = 0;
|
|
let heights = f["heights"].as_array().unwrap();
|
|
for _ in 0..f["repeats"].as_u64().unwrap() {
|
|
for state in f["states"].as_array().unwrap() {
|
|
let y = heights[index % heights.len()].as_i64().unwrap() as i32;
|
|
index += 1;
|
|
let result = rule.test(
|
|
BlockStateId(state.as_u64().unwrap() as u32),
|
|
[17, y, -33],
|
|
&mut random,
|
|
);
|
|
writeln!(out, "test {result} {}", random.next_long())?;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
writeln!(out, "tail {}", random.next_long())?;
|
|
Ok(())
|
|
}
|
|
fn tag(v: &Value) -> Tag {
|
|
match v {
|
|
Value::String(s) => Tag::String(s.as_str().into()),
|
|
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
|
|
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
|
|
Value::Object(m) => {
|
|
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
|
|
}
|
|
_ => panic!("invalid registry metadata"),
|
|
}
|
|
}
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let arg = std::env::args().nth(1).expect("private fixture directory");
|
|
let dir = Path::new(&arg);
|
|
let facts: Value = serde_json::from_str(&fs::read_to_string(dir.join("facts-server.json"))?)?;
|
|
let registry = BlockRegistry::from_nbt(&Tag::compound([
|
|
("DataVersion", Tag::Int(DATA_VERSION)),
|
|
("states", tag(&facts["states"])),
|
|
("defaults", tag(&facts["defaults"])),
|
|
]))?;
|
|
let integers = facts["integers"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.map(|v| {
|
|
(
|
|
v[0].as_str().unwrap().to_owned(),
|
|
v[1].as_str().unwrap().to_owned(),
|
|
)
|
|
})
|
|
.collect();
|
|
let resources: Value = serde_json::from_str(&fs::read_to_string(dir.join("tags.json"))?)?;
|
|
let mut definitions = TagDefinitions::default();
|
|
for (name, text) in resources.as_object().unwrap() {
|
|
definitions.apply_json(name, "vanilla", text.as_str().unwrap())?;
|
|
}
|
|
let built =
|
|
definitions.build(|name, _| registry.default_state(name).map(|_| name.to_owned()))?;
|
|
assert!(built.missing.is_empty());
|
|
let bindings = FeatureBlockBindings::with_tags(®istry, integers, &built.tags)?;
|
|
let mut out = io::BufWriter::new(fs::File::create(dir.join("rust.txt"))?);
|
|
for line in fs::read_to_string(dir.join("inputs.txt"))?.lines() {
|
|
let f: Value = serde_json::from_str(line)?;
|
|
let seed = f["seed"].as_i64().unwrap();
|
|
if f["legacy"].as_bool().unwrap() {
|
|
fixture(&f, &bindings, LegacyRandom::new(seed), &mut out)?;
|
|
} else {
|
|
fixture(&f, &bindings, XoroshiroRandom::new(seed), &mut out)?;
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|