From bb9c474c643f45ba551899bfe24ea360daeb2e6e Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Mon, 26 Oct 2026 00:48:58 +0500 Subject: [PATCH 1/2] End city banners keep their template patterns A structure template saves a banner's layers in its block entity NBT, and StructureTemplate.placeInWorld hands that NBT to the level, where BannerBlockEntity.loadAdditional reads `patterns`. Horizon built the client block entity from the block alone (BlockEntity::for_block), so the End cities' magenta banners came out bare. Fixes #1438. Co-Authored-By: [CC] --- crates/horizon-client/src/structure_blocks.rs | 89 ++++++++++++++++--- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/crates/horizon-client/src/structure_blocks.rs b/crates/horizon-client/src/structure_blocks.rs index 1e1906f6d..da5b75258 100644 --- a/crates/horizon-client/src/structure_blocks.rs +++ b/crates/horizon-client/src/structure_blocks.rs @@ -128,6 +128,44 @@ fn text(nbt: &Compound, key: &str) -> Option { } } +/// `BannerBlockEntity.loadAdditional`: the `patterns` layers and the custom +/// name a structure template saves with its banner (the End cities' tower +/// tops place black triangles this way). +fn banner_from_nbt(nbt: &Compound) -> crate::containers::Banner { + crate::containers::Banner { + layers: crate::banner::layers_from_nbt(nbt.get(&JavaString::from("patterns"))), + name: text(nbt, "CustomName"), + components: match nbt.get(&JavaString::from("components")) { + Some(Tag::Compound(c)) => c.clone(), + _ => Compound::new(), + }, + } +} + +/// The client block entity for one of a chunk's generated block entities, +/// before a container's loot is unpacked. +fn generated_block_entity(block: &str, nbt: &Compound) -> Option { + let mut entity = BlockEntity::for_block(block)?; + let tag = Tag::Compound(nbt.clone()); + // MonsterRoomFeature and the structures' setEntityId. + if let BlockEntity::Spawner(s) = &mut entity { + **s = crate::mobs::spawner::Spawner::load(&tag); + } + if let BlockEntity::TrialSpawner(s) = &mut entity { + **s = crate::mobs::trial_spawner::TrialSpawner::load(&tag); + } + if let BlockEntity::Vault(v) = &mut entity { + **v = crate::vault::Vault::load(&tag); + } + // StructureTemplate.placeInWorld hands the template's block entity NBT to + // the level, so `BannerBlockEntity.loadAdditional` keeps the banner's + // patterns (the End cities' black triangles) and its name. + if let BlockEntity::Banner(b) = &mut entity { + *b = banner_from_nbt(nbt); + } + Some(entity) +} + /// Client block entities for the generated block entities of a chunk. pub fn block_entities( chunk: &ProtoChunk, @@ -137,19 +175,9 @@ pub fn block_entities( for (pos, nbt) in &chunk.block_entities { let [x, y, z] = *pos; let block = chunk.block_name(x, y, z); - let Some(mut entity) = BlockEntity::for_block(block) else { + let Some(mut entity) = generated_block_entity(block, nbt) else { continue; }; - // MonsterRoomFeature and the structures' setEntityId. - if let BlockEntity::Spawner(s) = &mut entity { - **s = crate::mobs::spawner::Spawner::load(&Tag::Compound(nbt.clone())); - } - if let BlockEntity::TrialSpawner(s) = &mut entity { - **s = crate::mobs::trial_spawner::TrialSpawner::load(&Tag::Compound(nbt.clone())); - } - if let BlockEntity::Vault(v) = &mut entity { - **v = crate::vault::Vault::load(&Tag::Compound(nbt.clone())); - } if let (BlockEntity::Chest(slots), Some(table), Some(loot)) = (&mut entity, text(nbt, "LootTable"), loot) { @@ -278,4 +306,43 @@ mod tests { stack.exploration = None; assert!(!has_pending_map(&loot_item(&stack))); } + + /// The End cities' tower tops save their banners' patterns in the + /// template; the placed banner must keep them (`EndCityPieces`). + #[test] + fn a_generated_banner_keeps_its_template_patterns() { + let patterns = Tag::List(vec![ + Tag::compound([ + ("color", Tag::String("black".into())), + ("pattern", Tag::String("minecraft:triangle_top".into())), + ]), + Tag::compound([ + ("color", Tag::String("black".into())), + ("pattern", Tag::String("minecraft:triangle_bottom".into())), + ]), + ]); + let nbt = Tag::compound([ + ("id", Tag::String("minecraft:banner".into())), + ("patterns", patterns), + ]); + let Tag::Compound(nbt) = nbt else { + unreachable!() + }; + let Some(BlockEntity::Banner(banner)) = + generated_block_entity("minecraft:magenta_banner", &nbt) + else { + panic!("a banner block makes a banner block entity"); + }; + assert_eq!(banner.layers.len(), 2); + assert_eq!(&*banner.layers[0].pattern, "minecraft:triangle_top"); + assert_eq!(&*banner.layers[1].pattern, "minecraft:triangle_bottom"); + assert_eq!(&*banner.layers[0].color, "black"); + // A banner the template saved without patterns stays bare. + let Some(BlockEntity::Banner(bare)) = + generated_block_entity("minecraft:white_banner", &Compound::new()) + else { + panic!("a banner block makes a banner block entity"); + }; + assert!(bare.layers.is_empty()); + } } From 401ac1322ffdd9aa72f2fffd927f135176a0ec98 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 23:43:03 +0100 Subject: [PATCH 2/2] Banners: one loader for saved and generated banners The generated banner reuses save.rs's BannerBlockEntity.loadAdditional (now decode_banner) instead of a copy of it, and the generated block entity clones its NBT only for the kinds that read it. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/save.rs | 23 +++++----- crates/horizon-client/src/structure_blocks.rs | 45 ++++++------------- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index da5735c17..69b6a44f5 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -567,6 +567,17 @@ fn merge_block_entity(original: &Tag, loaded: &Tag, current: &Tag) -> Tag { } merged } +/// `BannerBlockEntity.loadAdditional` (and the `components` a block entity keeps). +pub fn decode_banner(tag: &Tag) -> crate::containers::Banner { + crate::containers::Banner { + layers: crate::banner::layers_from_nbt(tag.get("patterns")), + name: text(tag.get("CustomName")), + components: match tag.get("components") { + Some(Tag::Compound(c)) => c.clone(), + _ => Compound::new(), + }, + } +} pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::containers::BlockEntity)> { use crate::containers::BlockEntity; let int = |k: &str| number(tag.get(k)).map(|v| v as i32); @@ -600,17 +611,7 @@ pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::contain return Some((pos, BlockEntity::Lectern(lectern))); } if id == "minecraft:banner" { - return Some(( - pos, - BlockEntity::Banner(crate::containers::Banner { - layers: crate::banner::layers_from_nbt(tag.get("patterns")), - name: text(tag.get("CustomName")), - components: match tag.get("components") { - Some(Tag::Compound(c)) => c.clone(), - _ => Compound::new(), - }, - }), - )); + return Some((pos, BlockEntity::Banner(decode_banner(tag)))); } if id == "minecraft:beacon" { let beacon = crate::containers::Beacon { diff --git a/crates/horizon-client/src/structure_blocks.rs b/crates/horizon-client/src/structure_blocks.rs index da5b75258..ff51116bc 100644 --- a/crates/horizon-client/src/structure_blocks.rs +++ b/crates/horizon-client/src/structure_blocks.rs @@ -128,40 +128,23 @@ fn text(nbt: &Compound, key: &str) -> Option { } } -/// `BannerBlockEntity.loadAdditional`: the `patterns` layers and the custom -/// name a structure template saves with its banner (the End cities' tower -/// tops place black triangles this way). -fn banner_from_nbt(nbt: &Compound) -> crate::containers::Banner { - crate::containers::Banner { - layers: crate::banner::layers_from_nbt(nbt.get(&JavaString::from("patterns"))), - name: text(nbt, "CustomName"), - components: match nbt.get(&JavaString::from("components")) { - Some(Tag::Compound(c)) => c.clone(), - _ => Compound::new(), - }, - } -} - /// The client block entity for one of a chunk's generated block entities, -/// before a container's loot is unpacked. +/// before a container's loot is unpacked: `StructureTemplate.placeInWorld` +/// hands the template's block entity NBT to the level's block entity. fn generated_block_entity(block: &str, nbt: &Compound) -> Option { let mut entity = BlockEntity::for_block(block)?; - let tag = Tag::Compound(nbt.clone()); - // MonsterRoomFeature and the structures' setEntityId. - if let BlockEntity::Spawner(s) = &mut entity { - **s = crate::mobs::spawner::Spawner::load(&tag); - } - if let BlockEntity::TrialSpawner(s) = &mut entity { - **s = crate::mobs::trial_spawner::TrialSpawner::load(&tag); - } - if let BlockEntity::Vault(v) = &mut entity { - **v = crate::vault::Vault::load(&tag); - } - // StructureTemplate.placeInWorld hands the template's block entity NBT to - // the level, so `BannerBlockEntity.loadAdditional` keeps the banner's - // patterns (the End cities' black triangles) and its name. - if let BlockEntity::Banner(b) = &mut entity { - *b = banner_from_nbt(nbt); + match &mut entity { + // MonsterRoomFeature and the structures' setEntityId. + BlockEntity::Spawner(s) => { + **s = crate::mobs::spawner::Spawner::load(&Tag::Compound(nbt.clone())); + } + BlockEntity::TrialSpawner(s) => { + **s = crate::mobs::trial_spawner::TrialSpawner::load(&Tag::Compound(nbt.clone())); + } + BlockEntity::Vault(v) => **v = crate::vault::Vault::load(&Tag::Compound(nbt.clone())), + // BannerBlockEntity.loadAdditional: the End cities' black triangles. + BlockEntity::Banner(b) => *b = crate::save::decode_banner(&Tag::Compound(nbt.clone())), + _ => {} } Some(entity) }