Files
horizon-airdef/crates/horizon-world/examples/loot_fill.rs
T
Ludovic Marie 231dd0c851 Fill container loot tables like vanilla LootTable.fill
New horizon_world::loot: pools, weighted and nested entries, the item
modifiers chest tables use (counts, damage, random and level-based
enchanting, potions, stew effects, instruments, filtered/discard),
conditions, the stack splitter and the slot shuffle, all with vanilla's
random draw order. tools/compare_loot_fill.py runs a new vanilla oracle
(VanillaLootFillOracle) against the loot_fill example: all 58 chest
tables match slot for slot over 42 seeds.

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

37 lines
1.3 KiB
Rust

//! Container loot in the vanilla loot-fill oracle's line format.
//!
//! loot_fill <client resource dir> <table[,table...]> <seed>...: prints
//! `table TABLE SEED` then `fill TABLE SEED SLOT ITEM COUNT DAMAGE [ENCH=LVL...]`.
use horizon_world::loot::LootData;
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut args = std::env::args().skip(1);
let root = PathBuf::from(args.next().ok_or("client resource directory")?);
let data = LootData::load(&root)?;
let tables: Vec<String> = args
.next()
.ok_or("table")?
.split(',')
.map(str::to_owned)
.collect();
let seeds: Vec<i64> = args.map(|s| s.parse()).collect::<Result<_, _>>()?;
for table in &tables {
for &seed in &seeds {
println!("table {table} {seed}");
for (slot, stack) in data.fill(table, seed, 27, None).into_iter().enumerate() {
let Some(s) = stack else { continue };
let mut line = format!(
"fill {table} {seed} {slot} {} {} {}",
s.item, s.count, s.damage
);
for (name, level) in &s.enchantments {
line.push_str(&format!(" {name}={level}"));
}
println!("{line}");
}
}
}
Ok(())
}