Merge pull request #2457 from kacpherek/fix/template-block-entity-nbt
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `StructureTemplate.placeInWorld` loads each block's template NBT into its block entity, as here. Gate: this wave's 50 PRs merged on main in one tree (union 9033a9c3b): fmt and clippy `-D warnings` clean, the horizon-client (1136 lib plus the integration tests), horizon-client-core (37), horizon-world (165) and horizon-protocol (100) tests pass, the fast build links, and the 140 harnesses `parity.py` picks for the tree's changed files pass on playhorizon (remote_fireworks, a known load flake there, passed on a rerun on a quiet Mac mini). `lan_e2e.py` passes 14 checks with the host on its server thread and in-frame (chest, xp, damage, kills, projectiles, mobs, drops, body, stopsound, digging, instant_digging, books, knockback, barter); `hurt` fails on main too when run after `damage` (check-order dependency, not this wave). Thanks @kacpherek!
This commit is contained in:
@@ -196,23 +196,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
|
||||
|
||||
Reference in New Issue
Block a user