Merge pull request #1928 from levzzz5154/fix/end-city-banner-patterns

🤖 Agent: Thanks levzzz5154! End city banners keep their template patterns; I pushed 401ac1322 so the structure code and the save loader share one banner decoder. Tested together with the other wave 1 contributor PRs on current main: fmt, clippy -D warnings and the horizon-client tests (1,120 lib tests and the rest) pass; the 114 harnesses the batch affects pass; lan_e2e anvil, grindstone, replant, instant_digging, digging, frames and leads pass with the host in-frame and on its server thread.
This commit is contained in:
Ludovic Marie
2026-10-26 03:08:48 +01:00
committed by GitHub
2 changed files with 73 additions and 22 deletions
+12 -11
View File
@@ -572,6 +572,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);
@@ -605,17 +616,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 {
+61 -11
View File
@@ -128,6 +128,27 @@ fn text(nbt: &Compound, key: &str) -> Option<String> {
}
}
/// The client block entity for one of a chunk's generated block entities,
/// 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<BlockEntity> {
let mut entity = BlockEntity::for_block(block)?;
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)
}
/// Client block entities for the generated block entities of a chunk.
pub fn block_entities(
chunk: &ProtoChunk,
@@ -137,19 +158,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 +289,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());
}
}