Files
horizon-airdef/crates/horizon-client/examples/enchanting_fixture.rs
T
Ludovic Marie 9a3bf42574 Add a differential test of enchanting-table offers against vanilla
A Java oracle loads the vanilla data pack's enchantment registry, binds
item components and replays EnchantmentMenu's cost, clue and enchantment
selection draws; tools/test_enchanting_parity.py compares it with the Rust
stations module for every enchantable item and the book over 32 seeds and
7 bookshelf counts (51,744 lines match).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 15:47:03 +02:00

36 lines
1.7 KiB
Rust

//! Enchanting-table offers for differential tests against vanilla
//! (tools/test_enchanting_parity.py): reads "seed bookcases item" lines and
//! prints costs, clues and applied enchantments in the oracle's format.
//!
//! usage: enchanting_fixture RESOURCES INPUT OUTPUT
use horizon_client::{enchant::Enchantments, items::{ItemStack, Items}, stations};
use std::{fmt::Write as _, fs, path::Path};
fn main() -> horizon_client::Result<()> {
let args: Vec<String> = std::env::args().collect();
let root = Path::new(args.get(1).ok_or("usage: enchanting_fixture RESOURCES INPUT OUTPUT")?);
let input = fs::read_to_string(args.get(2).ok_or("missing INPUT")?)?;
let items = Items::tags_only(root)?;
let e = Enchantments::load(root);
let mut out = String::new();
for line in input.lines() {
let f: Vec<&str> = line.split(' ').collect();
let (seed, bookcases, item): (i32, i32, &str) = (f[0].parse()?, f[1].parse()?, f[2]);
let stack = ItemStack::new(item, 1);
let offers = stations::enchant_offers(&e, &items, seed, bookcases, Some(&stack));
for i in 0..3 {
let cost = offers.costs[i];
let clue = offers.clues[i].as_ref().map_or("-".to_owned(), |(id, l)| format!("{id}:{l}"));
let applied = if cost > 0 {
let list = stations::enchantment_list(&e, &items, seed, i, cost, item);
if list.is_empty() { "-".to_owned() } else { list.iter().map(|(id, l)| format!("{id}:{l}")).collect::<Vec<_>>().join(",") }
} else {
"-".to_owned()
};
writeln!(out, "{line} {i} {cost} {clue} {applied}")?;
}
}
fs::write(args.get(3).ok_or("missing OUTPUT")?, out)?;
Ok(())
}