From 2143c26a2e6205af93ef55729f9db45866c2bc84 Mon Sep 17 00:00:00 2001 From: FusselTV Date: Sun, 25 Oct 2026 23:00:07 +0100 Subject: [PATCH 1/4] Saves: write points of interest Horizon finds villager POIs from the blocks and kept no poi folder, so a world it made had none. Vanilla rebuilds a missing section on load, but until a chunk is loaded nothing knows its beds, job sites, bells, nests, portals or lodestones. Saving a chunk now writes its POI records the way PoiManager saves its sections: each section with POI blocks, valid, one record per block of PoiTypes with its max tickets, free_tickets left out at 0. A chunk that lost its last POI and had a record gets an empty one, since vanilla trusts a valid section. The records are built on the region writer thread, which reads the saved record there, so unloading chunks reads no files on the tick thread. A straw bed is no home (PoiTypes.BEDS is the sixteen colours); /locate poi uses the same table. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/commands.rs | 33 +- crates/horizon-client/src/save.rs | 419 +++++++++++++++++++-- 2 files changed, 388 insertions(+), 64 deletions(-) diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 76e10cb57..7ed8f9658 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -2572,38 +2572,7 @@ impl Game<'_> { /// `PoiTypes`: the point of interest type of a block state. fn poi_type(&self, state: horizon_world::registry::BlockStateId) -> Option<&'static str> { let s = self.pack.assets.registry.state(state)?; - let name = s.name.strip_prefix("minecraft:")?; - Some(match name { - "blast_furnace" => "minecraft:armorer", - "smoker" => "minecraft:butcher", - "cartography_table" => "minecraft:cartographer", - "brewing_stand" => "minecraft:cleric", - "composter" => "minecraft:farmer", - "barrel" => "minecraft:fisherman", - "fletching_table" => "minecraft:fletcher", - "cauldron" | "lava_cauldron" | "water_cauldron" | "powder_snow_cauldron" => { - "minecraft:leatherworker" - } - "lectern" => "minecraft:librarian", - "stonecutter" => "minecraft:mason", - "loom" => "minecraft:shepherd", - "smithing_table" => "minecraft:toolsmith", - "grindstone" => "minecraft:weaponsmith", - "bell" => "minecraft:meeting", - "beehive" => "minecraft:beehive", - "bee_nest" => "minecraft:bee_nest", - "nether_portal" => "minecraft:nether_portal", - "lodestone" => "minecraft:lodestone", - "test_instance_block" => "minecraft:test_instance", - n if n.ends_with("_bed") => { - if s.properties.get("part").map(String::as_str) != Some("head") { - return None; - } - "minecraft:home" - } - n if n.ends_with("lightning_rod") => "minecraft:lightning_rod", - _ => return None, - }) + horizon_client::save::poi_type(s).map(|(kind, _)| kind) } /// `LocateCommand.locatePoi`: `PoiManager.findClosestWithType` within /// 256 blocks of the source, over the loaded chunks. diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index 0c353bb38..246bacbac 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -247,6 +247,44 @@ pub struct SaveTables { block_entity: Vec, heightmaps: crate::assets::Properties, air: u32, + /// The POI type and its max tickets of each state (`PoiTypes`). + poi: Vec>, +} +/// `PoiTypes.register`: the POI type of a block state and its max tickets. +pub fn poi_type(state: &horizon_world::chunk::BlockState) -> Option<(&'static str, i32)> { + let name = state.name.strip_prefix("minecraft:")?; + Some(match name { + "blast_furnace" => ("minecraft:armorer", 1), + "smoker" => ("minecraft:butcher", 1), + "cartography_table" => ("minecraft:cartographer", 1), + "brewing_stand" => ("minecraft:cleric", 1), + "composter" => ("minecraft:farmer", 1), + "barrel" => ("minecraft:fisherman", 1), + "fletching_table" => ("minecraft:fletcher", 1), + "cauldron" | "lava_cauldron" | "water_cauldron" | "powder_snow_cauldron" => { + ("minecraft:leatherworker", 1) + } + "lectern" => ("minecraft:librarian", 1), + "stonecutter" => ("minecraft:mason", 1), + "loom" => ("minecraft:shepherd", 1), + "smithing_table" => ("minecraft:toolsmith", 1), + "grindstone" => ("minecraft:weaponsmith", 1), + "bell" => ("minecraft:meeting", 32), + "beehive" => ("minecraft:beehive", 0), + "bee_nest" => ("minecraft:bee_nest", 0), + "nether_portal" => ("minecraft:nether_portal", 0), + "lodestone" => ("minecraft:lodestone", 0), + "test_instance_block" => ("minecraft:test_instance", 0), + // PoiTypes.BEDS is the sixteen colours: no straw bed. + bed if bed.ends_with("_bed") && bed != "straw_bed" => { + if state.properties.get("part").map(String::as_str) != Some("head") { + return None; + } + ("minecraft:home", 1) + } + rod if rod.ends_with("lightning_rod") => ("minecraft:lightning_rod", 0), + _ => return None, + }) } impl SaveTables { pub fn new(assets: &crate::assets::Assets) -> Self { @@ -275,6 +313,9 @@ impl SaveTables { block_entity: Vec::new(), heightmaps: assets.properties.clone(), air: registry.default_state("minecraft:air").map_or(0, |s| s.0), + poi: (0..registry.len()) + .map(|id| registry.state(BlockStateId(id as u32)).and_then(poi_type)) + .collect(), } } /// Tables with only the heightmaps' state facts, for tests. @@ -287,6 +328,7 @@ impl SaveTables { block_entity: Vec::new(), heightmaps, air: 0, + poi: Vec::new(), } } /// Which states carry a block entity (`BlockFacts`), to drop entries for @@ -734,6 +776,103 @@ pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::contain Some((pos, entity)) } +/// The chunk's points of interest as `PoiManager` saves them: each section +/// with POI blocks, valid, with a record per block at its max tickets (a +/// freshly made world). None when the chunk has none. +pub fn encode_poi(chunk: &Chunk, tables: &SaveTables) -> Option { + let kind = |v: u32| tables.poi.get(v as usize).copied().flatten(); + let mut sections = Compound::new(); + let mut states = [0u32; 4096]; + for (si, section) in chunk.sections.iter().enumerate() { + if !section.blocks.maybe_has(|v| kind(v).is_some()) { + continue; + } + section.unpack(&mut states); + let y = (MIN_Y >> 4) + si as i32; + let records: Vec = states + .iter() + .enumerate() + .filter_map(|(i, &v)| { + let (id, tickets) = kind(v)?; + let i = i as i32; + let pos = [ + chunk.x * 16 + (i & 15), + y * 16 + (i >> 8), + chunk.z * 16 + ((i >> 4) & 15), + ]; + let mut record = vec![("pos", Tag::IntArray(pos.to_vec())), ("type", string(id))]; + // PoiRecord.CODEC: free_tickets defaults to 0 and is then left out. + if tickets != 0 { + record.push(("free_tickets", Tag::Int(tickets))); + } + Some(Tag::compound(record)) + }) + .collect(); + if !records.is_empty() { + sections.insert( + y.to_string().as_str().into(), + Tag::compound([("Valid", Tag::Byte(1)), ("Records", Tag::List(records))]), + ); + } + } + (!sections.is_empty()).then(|| poi_root(sections)) +} +/// A record's `free_tickets` from the POI file the chunk had, while the same +/// POI is still there: a bed or job site a villager claimed stays claimed. +fn keep_claims(saved: &mut NamedTag, old: &NamedTag) { + let key = |r: &Tag| match (r.get("pos"), text(r.get("type"))) { + (Some(Tag::IntArray(pos)), Some(kind)) => Some((pos.clone(), kind)), + _ => None, + }; + let mut claims = HashMap::new(); + if let Some(Tag::Compound(sections)) = old.tag.get("Sections") { + for section in sections.values() { + if let Some(Tag::List(records)) = section.get("Records") { + for r in records { + if let Some(k) = key(r) { + claims.insert(k, number(r.get("free_tickets")).unwrap_or(0) as i32); + } + } + } + } + } + let Tag::Compound(root) = &mut saved.tag else { + return; + }; + let Some(Tag::Compound(sections)) = root.get_mut(&"Sections".into()) else { + return; + }; + for section in sections.values_mut() { + let Tag::Compound(section) = section else { + continue; + }; + let Some(Tag::List(records)) = section.get_mut(&"Records".into()) else { + continue; + }; + for r in records { + let Some(&tickets) = key(r).and_then(|k| claims.get(&k)) else { + continue; + }; + if let Tag::Compound(r) = r { + if tickets == 0 { + r.remove(&"free_tickets".into()); + } else { + r.insert("free_tickets".into(), Tag::Int(tickets)); + } + } + } + } +} +fn poi_root(sections: Compound) -> NamedTag { + NamedTag { + name: "".into(), + tag: Tag::compound([ + ("DataVersion", Tag::Int(DATA_VERSION)), + ("Sections", Tag::Compound(sections)), + ]), + } +} + /// A column's sections as `Heightmap.primeHeightmaps` reads them. struct HeightmapView<'a> { sections: &'a [Arc
], @@ -1555,6 +1694,9 @@ enum Record { Tag(Arc), /// A chunk to encode on the writer thread. Chunk(Arc, Arc), + /// A chunk's points of interest, made on the writer thread against the + /// saved ones (`resolve_poi`). + Poi(Arc, Arc), Delete, } /// What encoding a chunk needs, captured when it is queued. @@ -1575,14 +1717,86 @@ impl Record { e.tables.as_deref(), e.sky_light, ))), + Record::Poi(c, t) => encode_poi(c, t).map(Arc::new), Record::Delete => None, } } } +/// A queued POI record as it is written: claims kept from the saved one, and +/// a chunk that lost its last POI gets an empty one, as vanilla trusts a +/// saved section. None when the chunk never had any. +fn resolve_poi( + root: &Path, + cache: &RegionCache, + (x, z): (i32, i32), + record: &Record, +) -> Option { + let Record::Poi(chunk, tables) = record else { + return Some(record.clone()); + }; + let old = read_region_record(root, cache, "poi", x, z).unwrap_or_else(|e| { + log::warn!("Horizon: could not read the poi record of chunk {x} {z}: {e}"); + None + }); + let tag = match (encode_poi(chunk, tables), old) { + (Some(mut tag), Some(old)) => { + keep_claims(&mut tag, &old); + tag + } + (Some(tag), None) => tag, + (None, Some(_)) => poi_root(Compound::new()), + (None, None) => return None, + }; + Some(Record::Tag(Arc::new(tag))) +} +fn read_region_record( + root: &Path, + cache: &RegionCache, + folder: &str, + x: i32, + z: i32, +) -> Result> { + let key = (x >> 5, z >> 5); + let path = region_path(root, folder, key.0, key.1); + let Some(region) = cached_region(cache, key, &path, false)? else { + return Ok(None); + }; + let record = region + .lock() + .map_err(|_| "region file poisoned")? + .read(ChunkPos::new(x, z))?; + Ok(match record { + Some(r) => Some(r.nbt(Limits::default())?), + None => None, + }) +} /// Chunk and entity records waiting for the writer thread, by (entities?, /// x, z): reads see them before the region files do. -type PendingWrites = Mutex>; -type WriteBatch = (bool, Vec<((i32, i32), Record, u64)>); +type PendingWrites = Mutex>; +type WriteBatch = (Folder, Vec<((i32, i32), Record, u64)>); +/// The region folders of a dimension. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +enum Folder { + Region, + Entities, + Poi, +} +impl Folder { + fn of(name: &str) -> Self { + match name { + "entities" => Self::Entities, + "poi" => Self::Poi, + _ => Self::Region, + } + } + fn name(self) -> &'static str { + match self { + Self::Region => "region", + Self::Entities => "entities", + Self::Poi => "poi", + } + } +} /// The background thread that encodes chunks and writes them into the region files, in /// submission order. @@ -1604,6 +1818,7 @@ pub struct SaveDir { pub root: PathBuf, regions: Arc, entity_regions: Arc, + poi_regions: Arc, pending: Arc, sequence: AtomicU64, writer: Mutex>, @@ -1620,6 +1835,7 @@ impl SaveDir { root, regions: Default::default(), entity_regions: Default::default(), + poi_regions: Default::default(), pending: Default::default(), sequence: AtomicU64::new(0), writer: Mutex::new(None), @@ -1636,21 +1852,17 @@ impl SaveDir { .pending .lock() .ok()? - .get(&(folder != "region", x, z)) + .get(&(Folder::of(folder), x, z)) .map(|(_, r)| r.clone()); if let Some(record) = pending { return record.tag().map(|t| (*t).clone()); } - let key = (x >> 5, z >> 5); - let cache = if folder == "region" { - &self.regions - } else { - &self.entity_regions + let cache = match Folder::of(folder) { + Folder::Region => &self.regions, + Folder::Entities => &self.entity_regions, + Folder::Poi => &self.poi_regions, }; - let path = self.region_path(folder, key.0, key.1); - let region = cached_region(cache, key, &path, false).ok()??; - let record = region.lock().ok()?.read(ChunkPos::new(x, z)).ok()??; - record.nbt(Limits::default()).ok() + read_region_record(&self.root, cache, folder, x, z).ok()? } pub fn load(&self, x: i32, z: i32, registry: &BlockRegistry, biomes: &Biomes) -> Option { let root = self.read_record("region", x, z)?; @@ -1710,16 +1922,16 @@ impl SaveDir { .into_iter() .map(|(k, t)| (k, t.map_or(Record::Delete, |t| Record::Tag(Arc::new(t))))) .collect(); - self.queue(folder != "region", records, wait) + self.queue(Folder::of(folder), records, wait) } - fn queue(&self, entities: bool, records: Vec<((i32, i32), Record)>, wait: bool) -> Result<()> { + fn queue(&self, folder: Folder, records: Vec<((i32, i32), Record)>, wait: bool) -> Result<()> { if !records.is_empty() { let mut batch = Vec::with_capacity(records.len()); { let mut pending = self.pending.lock().map_err(|_| "pending writes poisoned")?; for (key, record) in records { let seq = self.sequence.fetch_add(1, Ordering::Relaxed); - pending.insert((entities, key.0, key.1), (seq, record.clone())); + pending.insert((folder, key.0, key.1), (seq, record.clone())); batch.push((key, record, seq)); } } @@ -1730,7 +1942,7 @@ impl SaveDir { .map_err(|_| "writer poisoned")? += 1; let mut writer = self.writer.lock().map_err(|_| "writer poisoned")?; let writer = writer.get_or_insert_with(|| self.start_writer()); - if writer.send.send((entities, batch)).is_err() { + if writer.send.send((folder, batch)).is_err() { *self .outstanding .error @@ -1753,30 +1965,36 @@ impl SaveDir { fn start_writer(&self) -> Writer { let (send, receive) = mpsc::channel::(); let root = self.root.clone(); - let (regions, entity_regions) = (self.regions.clone(), self.entity_regions.clone()); + let (regions, entity_regions, poi_regions) = ( + self.regions.clone(), + self.entity_regions.clone(), + self.poi_regions.clone(), + ); let pending = self.pending.clone(); let outstanding = self.outstanding.clone(); let thread = std::thread::Builder::new() .name("horizon-region-writer".into()) .spawn(move || { - for (entities, batch) in receive { - let (folder, cache) = if entities { - ("entities", &entity_regions) - } else { - ("region", ®ions) + for (kind, batch) in receive { + let cache = match kind { + Folder::Region => ®ions, + Folder::Entities => &entity_regions, + Folder::Poi => &poi_regions, }; + let folder = kind.name(); // IOWorker.pendingWrites: a chunk queued again since is // written once, by its newest batch. let newest = |k: &(i32, i32), seq: u64| { pending.lock().map_or(true, |p| { - p.get(&(entities, k.0, k.1)).is_none_or(|p| p.0 <= seq) + p.get(&(kind, k.0, k.1)).is_none_or(|p| p.0 <= seq) }) }; - let records: Vec<_> = batch + let resolved: Vec<_> = batch .iter() .filter(|(k, _, seq)| newest(k, *seq)) - .map(|(k, r, _)| (*k, r)) + .filter_map(|(k, r, _)| Some((*k, resolve_poi(&root, cache, *k, r)?))) .collect(); + let records: Vec<_> = resolved.iter().map(|(k, r)| (*k, r)).collect(); let result = write_region_records(&root, cache, folder, &records); if let Err(e) = &result { let message = format!("failed to write {folder} files: {e}"); @@ -1788,11 +2006,8 @@ impl SaveDir { && let Ok(mut pending) = pending.lock() { for (k, _, seq) in &batch { - if pending - .get(&(entities, k.0, k.1)) - .is_some_and(|p| p.0 == *seq) - { - pending.remove(&(entities, k.0, k.1)); + if pending.get(&(kind, k.0, k.1)).is_some_and(|p| p.0 == *seq) { + pending.remove(&(kind, k.0, k.1)); } } } @@ -1861,8 +2076,19 @@ impl SaveDir { }) .collect(); self.write_records("region", records, true)?; + self.save_poi(chunks, true)?; Ok(chunks.len()) } + fn save_poi(&self, chunks: &[Arc], wait: bool) -> Result<()> { + let Some(tables) = self.tables.get() else { + return Ok(()); + }; + let records = chunks + .iter() + .map(|c| ((c.x, c.z), Record::Poi(c.clone(), tables.clone()))) + .collect(); + self.queue(Folder::Poi, records, wait) + } /// `save` on the writer thread: returns before the files are written; /// loads see the chunks meanwhile. pub fn save_later( @@ -1881,7 +2107,8 @@ impl SaveDir { .iter() .map(|c| ((c.x, c.z), Record::Chunk(c.clone(), encoding.clone()))) .collect(); - self.queue(false, records, false)?; + self.queue(Folder::Region, records, false)?; + self.save_poi(chunks, false)?; Ok(chunks.len()) } /// Write the entity chunks (`EntityStorage`): an empty list deletes it. @@ -3326,7 +3553,7 @@ impl SaveDir { .pending .lock() .ok()? - .get(&(false, x, z)) + .get(&(Folder::Region, x, z)) .map(|(_, record)| record.clone()); let root = if let Some(record) = pending { record.tag().map(|tag| (*tag).clone())? @@ -3436,6 +3663,134 @@ impl ChunkGenerator for Persistent { #[cfg(test)] mod tests { + #[test] + fn points_of_interest_save_as_poi_sections() { + let Some(root) = std::env::var_os("HORIZON_TEST_RESOURCES") else { + return; + }; + let assets = crate::assets::Assets::load(&PathBuf::from(root)).expect("assets"); + let tables = SaveTables::new(&assets); + let state = |name: &str, props: &[(&str, &str)]| { + let mut s = assets + .registry + .state(assets.registry.default_state(name).unwrap()) + .unwrap() + .clone(); + for (k, v) in props { + s.properties.insert((*k).into(), (*v).into()); + } + assets.registry.id(&s).unwrap().0 + }; + let mut chunk = Chunk::empty(2, -1); + chunk.set(1, 70, 1, state("minecraft:red_bed", &[("part", "head")])); + chunk.set(1, 70, 2, state("minecraft:red_bed", &[("part", "foot")])); + chunk.set(5, 71, 5, state("minecraft:bell", &[])); + chunk.set(6, 71, 5, state("minecraft:stone", &[])); + chunk.set(9, 70, 9, state("minecraft:straw_bed", &[("part", "head")])); + assert!(encode_poi(&Chunk::empty(0, 0), &tables).is_none()); + let saved = encode_poi(&chunk, &tables).expect("records"); + let Some(Tag::Compound(sections)) = saved.tag.get("Sections") else { + panic!("no sections"); + }; + assert_eq!(sections.len(), 1); + let section = §ions[&"4".into()]; + assert_eq!(section.get("Valid"), Some(&Tag::Byte(1))); + let Some(Tag::List(records)) = section.get("Records") else { + panic!("no records"); + }; + let records: Vec<_> = records + .iter() + .map(|r| { + ( + text(r.get("type")).unwrap(), + r.get("pos").cloned(), + number(r.get("free_tickets")), + ) + }) + .collect(); + assert_eq!( + records, + [ + ( + "minecraft:home".into(), + Some(Tag::IntArray(vec![33, 70, -15])), + Some(1) + ), + ( + "minecraft:meeting".into(), + Some(Tag::IntArray(vec![37, 71, -11])), + Some(32) + ), + ] + ); + } + + #[test] + fn a_chunk_that_loses_its_last_poi_saves_empty_sections() { + let Some(root) = std::env::var_os("HORIZON_TEST_RESOURCES") else { + return; + }; + let root = PathBuf::from(root); + let assets = crate::assets::Assets::load(&root).expect("assets"); + let biomes = Arc::new(Biomes::load(&root).expect("biomes")); + let bell = assets.registry.default_state("minecraft:bell").unwrap().0; + let dir = std::env::temp_dir().join(format!("horizon-poi-save-{}", std::process::id())); + fs::create_dir_all(&dir).unwrap(); + let save = SaveDir::new(dir.clone()); + let _ = save.tables.set(Arc::new(SaveTables::new(&assets))); + let mut chunk = Chunk::empty(0, 0); + chunk.set(5, 71, 5, bell); + let sections = |save: &SaveDir| match save.read_record("poi", 0, 0)?.tag.get("Sections") { + Some(Tag::Compound(s)) => Some(s.len()), + _ => None, + }; + save.save_later(&[Arc::new(chunk.clone())], assets.registry, &biomes) + .unwrap(); + save.flush().unwrap(); + assert_eq!(sections(&save), Some(1)); + chunk.set(5, 71, 5, 0); + save.save_later(&[Arc::new(chunk)], assets.registry, &biomes) + .unwrap(); + save.flush().unwrap(); + assert_eq!(sections(&SaveDir::new(dir.clone())), Some(0)); + let _ = fs::remove_dir_all(&dir); + } + + #[test] + fn saved_poi_records_keep_their_claims() { + let record = |pos: [i32; 3], kind: &str, tickets: Option| { + let mut r = vec![("pos", Tag::IntArray(pos.to_vec())), ("type", string(kind))]; + if let Some(t) = tickets { + r.push(("free_tickets", Tag::Int(t))); + } + Tag::compound(r) + }; + let poi = |records: Vec| { + let mut sections = Compound::new(); + sections.insert( + "4".into(), + Tag::compound([("Valid", Tag::Byte(1)), ("Records", Tag::List(records))]), + ); + poi_root(sections) + }; + let old = poi(vec![ + record([1, 70, 1], "minecraft:home", None), + record([5, 71, 5], "minecraft:meeting", Some(30)), + ]); + let mut saved = poi(vec![ + record([1, 70, 1], "minecraft:home", Some(1)), + record([5, 71, 5], "minecraft:meeting", Some(32)), + record([9, 71, 9], "minecraft:home", Some(1)), + ]); + keep_claims(&mut saved, &old); + let expected = poi(vec![ + record([1, 70, 1], "minecraft:home", None), + record([5, 71, 5], "minecraft:meeting", Some(30)), + record([9, 71, 9], "minecraft:home", Some(1)), + ]); + assert_eq!(saved.tag, expected.tag); + } + #[test] fn saved_far_surface_reads_builds_and_water_without_gameplay_chunks() { let Some(root) = std::env::var_os("HORIZON_TEST_RESOURCES") else { From dbbe3a45d97da62cca77f2810bc5013e493c8b7b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 16:29:09 +0100 Subject: [PATCH 2/4] CI: check the launcher's workspace on every push to main and on pull requests that touch it verify's cargo runs never build launcher/ (its own workspace), so #2059 and the registry ratings commit each passed alone and left main's launcher failing to compile (E0061). The new launcher job runs its rustfmt, clippy -D warnings and lib tests when a pull request changes the launcher, a crate it builds or the root manifests, and on every push to main. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 36 +++++++++++++++++++++++++++++++++++ tests/test_ci_rust_changes.py | 13 ++++++++++++- tools/ci/rust_changes.py | 27 ++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eff82fa99..39ea920da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,42 @@ jobs: run: | cargo +stable test --workspace --lib --bins --tests --features horizon-client/mods,horizon-mods/pack cargo +stable test --workspace --doc --features horizon-client/mods,horizon-mods/pack + # The launcher is its own workspace (launcher/Cargo.toml), so verify's cargo runs never build it. A pull request that + # changes it or a crate it builds is checked here, and so is every push to main: two pull requests can each pass + # alone and break it together (#2059 and the registry ratings did, 2026-10-26). + launcher: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Does this pull request change the launcher or a crate it builds? + if: github.event_name == 'pull_request' + id: launcher + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: python3 tools/ci/rust_changes.py --launcher "$BASE_SHA" "$HEAD_SHA" >> "$GITHUB_OUTPUT" + - name: Install Rust and the headers GPUI links against + if: steps.launcher.outputs.required != 'false' + run: | + sudo apt-get update && sudo apt-get install -y --no-install-recommends libxkbcommon-x11-dev libwayland-dev \ + libx11-xcb-dev libfontconfig-dev libvulkan-dev libasound2-dev libudev-dev + rustup toolchain install stable --profile minimal --component rustfmt --component clippy + - uses: Swatinem/rust-cache@v2 + if: steps.launcher.outputs.required != 'false' + with: + workspaces: launcher + shared-key: launcher + save-if: ${{ github.ref == 'refs/heads/main' }} + - name: Check the launcher's formatting, lint and tests + if: steps.launcher.outputs.required != 'false' + working-directory: launcher + run: | + cargo +stable fmt --check + cargo +stable clippy --all-targets --locked -- -D warnings + cargo +stable test --locked --lib # Most pull requests leave the harnesses to parity-main, which runs them on main a batch of merges at a time # (.github/workflows/parity-main.yml; releases wait for it). A pull request still runs them itself when it changes # a harness, an oracle, a probe or the runner, or carries the run-parity label (run-parity.yml, when it is added). diff --git a/tests/test_ci_rust_changes.py b/tests/test_ci_rust_changes.py index 6fd7621da..6db218b9f 100644 --- a/tests/test_ci_rust_changes.py +++ b/tests/test_ci_rust_changes.py @@ -4,7 +4,7 @@ import subprocess import tempfile import unittest -from tools.ci.rust_changes import changed_paths, needs_rust +from tools.ci.rust_changes import changed_paths, needs_launcher, needs_rust class RustChangesTests(unittest.TestCase): @@ -21,6 +21,17 @@ class RustChangesTests(unittest.TestCase): with self.subTest(path=path): self.assertTrue(needs_rust(["README.md", path])) + def test_launcher_checks_follow_the_crates_it_builds(self): + for path in ["crates/horizon-client/src/game.rs", "launcher/links.json", "launcher/docs/a.md", + "launcher/README.md", "website/src/index.html", "tools/pr_ready.py"]: + with self.subTest(path=path): + self.assertFalse(needs_launcher([path])) + for path in ["launcher/src/main.rs", "launcher/Cargo.lock", "crates/horizon-port-pack/src/net.rs", + "crates/horizon-theme/src/lib.rs", "Cargo.toml", "Cargo.lock", + ".github/workflows/ci.yml"]: + with self.subTest(path=path): + self.assertTrue(needs_launcher(["README.md", path])) + def test_moving_source_into_docs_still_requires_rust(self): with tempfile.TemporaryDirectory() as directory: def git(*args): diff --git a/tools/ci/rust_changes.py b/tools/ci/rust_changes.py index d2bf41713..f856778e9 100644 --- a/tools/ci/rust_changes.py +++ b/tools/ci/rust_changes.py @@ -1,8 +1,21 @@ #!/usr/bin/env python3 -"""Keep verify's Rust steps for any change beyond website content or documentation.""" +"""Keep verify's Rust steps for any change beyond website content or documentation. + +--launcher: whether the change is built into the launcher, its own workspace (release_train.LAUNCHER_PATHS). +""" import argparse import subprocess +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) +import release_train # noqa: E402 + +# The root workspace's manifest and toolchain files: the launcher's path crates inherit from them. +ROOT_RUST = {"Cargo.toml", "Cargo.lock", "rust-toolchain.toml", "rustfmt.toml", "clippy.toml"} +# The check itself: a change to it runs it. +LAUNCHER_CHECK = {".github/workflows/ci.yml", "tools/ci/rust_changes.py", "tools/release_train.py"} def needs_rust(paths): @@ -12,6 +25,14 @@ def needs_rust(paths): ) for path in paths) +def needs_launcher(paths): + return any(path in ROOT_RUST or path in LAUNCHER_CHECK or ( + path.startswith(tuple(release_train.LAUNCHER_PATHS)) + and not path.startswith(tuple(release_train.LAUNCHER_IGNORED)) + and not path.endswith(".md") + ) for path in paths) + + def changed_paths(base, head): # Renames must include deletions too: moving source into docs still affects Rust. output = subprocess.check_output([ @@ -24,5 +45,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("base") parser.add_argument("head") + parser.add_argument("--launcher", action="store_true", help="answer for the launcher instead") args = parser.parse_args() - print(f"required={str(needs_rust(changed_paths(args.base, args.head))).lower()}") + needs = needs_launcher if args.launcher else needs_rust + print(f"required={str(needs(changed_paths(args.base, args.head))).lower()}") From 9f1784dc0c3e91c860a9c12b6f975f6a0f7f286f Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:14:46 +0100 Subject: [PATCH 3/4] rust_changes: append the repository root to sys.path instead of prepending tools/ Prepending tools/ made unittest discovery import tools/test_decoration_parity.py in place of tests/test_decoration_parity.py. Co-Authored-By: Claude Opus 5.5 --- tools/ci/rust_changes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/ci/rust_changes.py b/tools/ci/rust_changes.py index f856778e9..a22b86f12 100644 --- a/tools/ci/rust_changes.py +++ b/tools/ci/rust_changes.py @@ -9,8 +9,9 @@ import subprocess import sys from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -import release_train # noqa: E402 +# The repository root, appended so a script run finds `tools` without shadowing anything already importable. +sys.path.append(str(Path(__file__).resolve().parents[2])) +from tools import release_train # noqa: E402 # The root workspace's manifest and toolchain files: the launcher's path crates inherit from them. ROOT_RUST = {"Cargo.toml", "Cargo.lock", "rust-toolchain.toml", "rustfmt.toml", "clippy.toml"} From d8e68148beec68cb857537ebbf0f6ef5b2c46d18 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:18:47 +0100 Subject: [PATCH 4/4] /recipe gives and takes each target's own recipes cmd_recipe changed self.level.recipe_book for every target, so `/recipe give|take ` changed the book of whoever ran it (or the dedicated server's own) and the target's client heard nothing. Each target now runs with its state swapped in (for_player), as ServerPlayer.awardRecipes/resetRecipes do on the player's own ServerRecipeBook: the guest's book changes and its client gets ClientboundRecipeBookAdd/RemovePacket. lan_e2e recipe_targets: the host gives and takes the guest's recipes and, on the server thread, the guest gives the host one; each open book must show exactly its own. Co-Authored-By: Claude Opus 5.5 --- .../src/game/commands/world_cmds.rs | 47 ++++++++------- tools/lan_e2e.py | 58 +++++++++++++++++++ 2 files changed, 85 insertions(+), 20 deletions(-) diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs index 30f019997..687eb3f88 100644 --- a/crates/horizon-client/src/game/commands/world_cmds.rs +++ b/crates/horizon-client/src/game/commands/world_cmds.rs @@ -49,26 +49,12 @@ impl Game<'_> { let mut tracker = Tracker::default(); for &t in &targets { let h = holder(self.target_name(t)); - // ServerRecipeBook.addRecipes/removeRecipes count recipe book - // displays (a transmute recipe has one per material count). - let mut n = 0; - // ServerPlayer.awardRecipes / resetRecipes: the displays changed. - let index = &self.res.stations().recipe_index; - n += if give { - let (count, unlocked) = self.level.recipe_book.add_recipes(index, &recipes); - self.recipe_unlocked(&unlocked); - count as i32 - } else { - let removed = self.level.recipe_book.remove_recipes(index, &recipes); - let count = removed.len() as i32; - // A network player's client drops them from its book. - if self.lan_acting.is_some() && !removed.is_empty() { - self.guest_packets.push(C::RecipeBookRemove( - horizon_protocol::packets::recipes::RecipeBookRemove { ids: removed }, - )); - } - count - }; + // ServerPlayer.awardRecipes / resetRecipes on the target's own + // ServerRecipeBook: a guest's is swapped in for the call, and the + // packets go to its client. + let n = self + .for_player(t, |g| g.change_recipes(give, &recipes)) + .unwrap_or(0); tracker.track(&h, n); } let verb = if give { "give" } else { "take" }; @@ -92,6 +78,27 @@ impl Game<'_> { Ok(total) } + /// ServerRecipeBook.addRecipes/removeRecipes for the player in place: how + /// many recipe book displays changed (a transmute recipe has one per + /// material count). + fn change_recipes(&mut self, give: bool, recipes: &[String]) -> i32 { + let index = &self.res.stations().recipe_index; + if give { + let (count, unlocked) = self.level.recipe_book.add_recipes(index, recipes); + self.recipe_unlocked(&unlocked); + return count as i32; + } + let removed = self.level.recipe_book.remove_recipes(index, recipes); + let count = removed.len() as i32; + // A network player's client drops them from its book. + if self.lan_acting.is_some() && !removed.is_empty() { + self.guest_packets.push(C::RecipeBookRemove( + horizon_protocol::packets::recipes::RecipeBookRemove { ids: removed }, + )); + } + count + } + // ---- /damage ---------------------------------------------------------------- fn damage_kind(ty: &str) -> DamageKind { diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 246729d1f..b5c3e6c1f 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -91,6 +91,8 @@ address. The script then checks, from both sides, what a guest's game used to ge places a log in the inventory's crafting grid (the server places it). - recipe_removal: the host and guest each forget all and individual recipes while the book is open; it stays empty when reopened, and a later grant appears (#1495). +- recipe_targets: `/recipe give|take ` changes that player's book, the host's + for the guest and (server thread) the guest's for the host; their open book shows it. - feedback: the guest's command feedback names the guest and shows the numbers, and the host (an operator) is told of it as `[Guest: ...]`. - clicks: with real mouse presses (not click-slot, which skips the screen's press and drag @@ -6222,6 +6224,62 @@ CHECKS += ['recipe_removal'] CHECK_FNS.update(recipe_removal=check_recipe_removal) +def check_recipe_targets(host, guest, out): + """RecipeCommand gives and takes the recipes of each target's own ServerRecipeBook: a + `/recipe give|take ` changes that player's book and reaches their client, + not the book of the player who typed it. An in-frame host isn't one of the players a guest's + command can name (`command_players` lists the guests), so the guest gives the host a recipe + only when the host is a client of its server thread.""" + host_name = host.raw('lan', 'status').get('host', 'Player') + books = {} + for game in (host, guest): + back_to_game(game) + game('command', command='clear @s') + game('command', command='recipe take @s *') + host.wait(20) + for game in (host, guest): + game.raw('key', 'e', 'tap') + game.wait(5) + book = game('screen').get('recipe_book') + assert book, f'{game.name}: the inventory has no recipe book' + if len(book['targets']) == 1: + game.raw('click-at', *centre(book['targets'][0])) + game.wait(5) + + def known(): + return {game.name: game('screen')['recipe_book']['known'] for game in (host, guest)} + + try: + books['empty'] = known() + assert books['empty'] == {host.name: 0, guest.name: 0}, books + host('command', command=f'recipe give {GUEST_NAME} minecraft:oak_planks') + host('command', command=f'recipe give {GUEST_NAME} minecraft:stick') + host.wait(20) + books['host gives guest'] = known() + if SERVER_THREAD: + guest('command', command=f'recipe give {host_name} minecraft:stick') + guest.wait(20) + books['guest gives host'] = known() + host('command', command=f'recipe take {GUEST_NAME} minecraft:stick') + host.wait(20) + books['host takes from guest'] = known() + host.shot(out, 'recipe-targets-host') + guest.shot(out, 'recipe-targets-guest') + by_guest = int(SERVER_THREAD) + expected = {'empty': (0, 0), 'host gives guest': (0, 2), 'guest gives host': (by_guest, 2), + 'host takes from guest': (by_guest, 1)} + for step, (in_host, in_guest) in expected.items(): + assert books[step] == {host.name: in_host, guest.name: in_guest}, (step, books) + finally: + back_to_game(host) + back_to_game(guest) + return books + + +CHECKS += ['recipe_targets'] +CHECK_FNS.update(recipe_targets=check_recipe_targets) + + def check_shulker_bullets(host, guest, out): """ShulkerAttackGoal's bullets reach ClientPacketListener.handleAddEntity, then the existing projectile renderer and interpolation, with distinct ids from the server's entity counter."""