de8cb0dfa6
The last two workstation menus guests couldn't use, both now on the shared menu engine, which single player runs too: - Lectern: LecternMenu on the engine (Kind::Lectern): the page buttons (1, 2, 100+) and Take Book (3, mayBuild) as ContainerButtonClick, the page as data slot 0 clamped to the book, the book in its one slot (removeItem, setItem a no-op, max 1). The host opens minecraft:lectern for a guest, applies the menu to the block entity (powered pulse, page turn level event 1043, has_book), resends changes and closes it on stillValid. Guests drive it from the book screen. - Cartography table: CartographyTableMenu on the engine (Kind::Cartography, setupResultSlot, onTake, onCraftedBy's new map ids through a Maps env), replacing the old station code; guests get the same through guest_menu_op. - LAN item stacks carry map_post_processing and writable/written book contents (they were blank for guests); map_post_processing is no longer saved (ItemStack.CODEC never saves it). - A guest who enchants gets the enchant_item stat. - Click parity: VanillaMenuOracle and menu_fixture gain both menus. - lan_e2e: new lectern and cartography checks; enchanting checks the stat; server_count/server_reply ignore the guest's own operator broadcast echo on --server-thread; the grindstone check counts levels as well as points. Fixes #868 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.7 KiB
Rust
98 lines
3.7 KiB
Rust
//! Recipe book placements for tools/test_place_recipe_parity.py: reads one
|
|
//! JSON case per line (menu, inventory, grid, recipe, max, creative,
|
|
//! selected) and the oracle's order of the counted items, runs
|
|
//! `Menu::place_recipe` and prints the oracle's line.
|
|
//!
|
|
//! usage: place_recipe_fixture RESOURCES CASES ORDERS OUTPUT
|
|
use horizon_client::{
|
|
crafting::Recipes,
|
|
item_data::{canon_stack, parse_stack},
|
|
items::Items,
|
|
menu::{Env, Kind, Menu, place::PostPlace},
|
|
};
|
|
use serde_json::Value;
|
|
use std::{fs, path::Path};
|
|
|
|
fn state(menu: &Menu) -> String {
|
|
let slots: Vec<String> = (0..menu.slot_count())
|
|
.map(|i| canon_stack(menu.slot(i)))
|
|
.collect();
|
|
let data: String = menu.data.iter().map(|d| format!(" {d}")).collect();
|
|
let inv: Vec<String> = (0..41).map(|i| canon_stack(menu.player_item(i))).collect();
|
|
format!(
|
|
"{} | {} |{data} | {} | inv {}",
|
|
slots.join(" "),
|
|
canon_stack(menu.carried.as_ref()),
|
|
menu.drops.join(";"),
|
|
inv.join(" ")
|
|
)
|
|
}
|
|
|
|
fn main() -> horizon_client::Result<()> {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
let usage = "usage: place_recipe_fixture RESOURCES CASES ORDERS OUTPUT";
|
|
let root = Path::new(args.get(1).ok_or(usage)?);
|
|
let cases = fs::read_to_string(args.get(2).ok_or(usage)?)?;
|
|
let orders = fs::read_to_string(args.get(3).ok_or(usage)?)?;
|
|
let items = Items::catalog(root)?;
|
|
let recipes = Recipes::load(root, &items)?;
|
|
let brewing = horizon_client::brewing::Brewing::load(root, &items);
|
|
let banners = horizon_client::banner::Banners::default();
|
|
let station_recipes = horizon_client::stations::StationRecipes::default();
|
|
let enchantments = horizon_client::enchant::Enchantments::default();
|
|
let names = horizon_client::creative::Names::default();
|
|
let env = Env {
|
|
items: &items,
|
|
recipes: &recipes,
|
|
brewing: &brewing,
|
|
banners: &banners,
|
|
station_recipes: &station_recipes,
|
|
enchantments: &enchantments,
|
|
names: &names,
|
|
trade: None,
|
|
maps: None,
|
|
};
|
|
let mut out = String::new();
|
|
for (line, order) in cases.lines().zip(orders.lines()) {
|
|
let case: Value = serde_json::from_str(line)?;
|
|
let kind = Kind::parse(case["menu"].as_str().unwrap_or_default()).ok_or("menu kind")?;
|
|
let mut menu = Menu::new(kind);
|
|
menu.creative = case["creative"].as_bool().unwrap_or(false);
|
|
menu.selected = case["selected"].as_u64().unwrap_or(0) as usize;
|
|
for pair in case["inventory"].as_array().ok_or("inventory")? {
|
|
menu.set_player_item(
|
|
pair[0].as_u64().unwrap_or(0) as usize,
|
|
parse_stack(pair[1].as_str().unwrap_or("-"))?,
|
|
);
|
|
}
|
|
for pair in case["grid"].as_array().ok_or("grid")? {
|
|
menu.set_slot(
|
|
&env,
|
|
pair[0].as_u64().unwrap_or(0) as usize,
|
|
parse_stack(pair[1].as_str().unwrap_or("-"))?,
|
|
);
|
|
}
|
|
menu.drops.clear();
|
|
let order: Vec<String> = order.split_whitespace().map(str::to_owned).collect();
|
|
let recipe = case["recipe"].as_str().unwrap_or_default();
|
|
let impossible = recipes.placement(recipe).is_none_or(|p| p.impossible());
|
|
let post = if impossible {
|
|
"-"
|
|
} else {
|
|
match menu.place_recipe(
|
|
&env,
|
|
recipe,
|
|
case["max"].as_bool().unwrap_or(false),
|
|
menu.creative,
|
|
Some(&order),
|
|
) {
|
|
PostPlace::Nothing => "NOTHING",
|
|
PostPlace::Ghost => "PLACE_GHOST_RECIPE",
|
|
}
|
|
};
|
|
out += &format!("post {post} | {}\n", state(&menu));
|
|
}
|
|
fs::write(args.get(4).ok_or(usage)?, out)?;
|
|
Ok(())
|
|
}
|