Structures: load the template's block entity NBT into every container and sign

This commit is contained in:
Kacpherek
2026-10-26 20:31:16 +01:00
parent e704a8dccb
commit 041ecb7b7a
+19 -15
View File
@@ -185,23 +185,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.
/// hands the template's block entity NBT to `loadWithComponents`, which is
/// what a chunk load does with a saved one.
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())),
_ => {}
let fallback = BlockEntity::for_block(block)?;
let mut tag = nbt.clone();
// RandomizableContainer.tryLoadLootTable: with a table the items are not read.
if text(&tag, "LootTable").is_some() {
tag.remove(&JavaString::from("Items"));
}
Some(entity)
// Programmatic block entities (and a template that saved none) carry no id.
if !tag.contains_key(&JavaString::from("id")) {
tag.insert("id".into(), Tag::String(fallback.id().into()));
}
for axis in ["x", "y", "z"] {
tag.insert(axis.into(), Tag::Int(0));
}
// A saved kind the client cannot decode keeps the block's own entity.
Some(
crate::save::decode_block_entity(&Tag::Compound(tag))
.map_or(fallback, |(_, entity)| entity),
)
}
/// Client block entities for the generated block entities of a chunk, and the