Merge pull request #2439 from RoyalPixelsDE/fix/generated-block-entities
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `WorldGenRegion.setBlock` gives a block with a block entity a `DUMMY` entry that becomes `newBlockEntity`'s default, so the deep dark's sensors, catalysts and shriekers and potent sulfur get theirs, while placed data is kept. 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 @FusselTV!
This commit is contained in:
@@ -66,6 +66,7 @@ pub fn block_entity_type(name: &str) -> Option<&'static str> {
|
||||
"sculk_catalyst" => "minecraft:sculk_catalyst",
|
||||
"sculk_shrieker" => "minecraft:sculk_shrieker",
|
||||
"crafter" => "minecraft:crafter",
|
||||
"potent_sulfur" => "minecraft:potent_sulfur",
|
||||
"chiseled_bookshelf" => "minecraft:chiseled_bookshelf",
|
||||
"trial_spawner" => "minecraft:trial_spawner",
|
||||
"vault" => "minecraft:vault",
|
||||
|
||||
@@ -42,6 +42,8 @@ pub struct VanillaTerrain {
|
||||
tick_blocks: Vec<u32>,
|
||||
/// Block index -> default state id: `tick_blocks` the other way.
|
||||
tick_states: Vec<u32>,
|
||||
/// Block state id -> the block entity type of its block, if it has one.
|
||||
block_entity_types: Vec<Option<&'static str>>,
|
||||
seed: i64,
|
||||
dimension: String,
|
||||
/// When the last proto chunk was generated, in milliseconds since
|
||||
@@ -54,6 +56,51 @@ enum VanillaProto {
|
||||
Ready(Box<ProtoChunk>),
|
||||
Failed(i32, i32),
|
||||
}
|
||||
/// WorldGenRegion.setBlock gives every block with a block entity a new
|
||||
/// one: the blocks nothing placed data for (a sculk patch's sensors) get
|
||||
/// vanilla's defaults.
|
||||
fn add_default_block_entities(kinds: &[Option<&str>], out: &mut Chunk, raw: &mut Vec<Tag>) {
|
||||
let kind = |v: u32| kinds.get(v as usize).copied().flatten();
|
||||
let mut states = [0u32; 4096];
|
||||
for (si, section) in out.sections.iter().enumerate() {
|
||||
if !section.blocks.maybe_has(|v| kind(v).is_some()) {
|
||||
continue;
|
||||
}
|
||||
section.unpack(&mut states);
|
||||
for (i, &v) in states.iter().enumerate() {
|
||||
let Some(id) = kind(v) else {
|
||||
continue;
|
||||
};
|
||||
let i = i as i32;
|
||||
let pos = [
|
||||
out.x * 16 + (i & 15),
|
||||
MIN_Y + si as i32 * 16 + (i >> 8),
|
||||
out.z * 16 + ((i >> 4) & 15),
|
||||
];
|
||||
let at = |t: &Tag| {
|
||||
["x", "y", "z"]
|
||||
.iter()
|
||||
.zip(pos)
|
||||
.all(|(k, p)| t.get(k) == Some(&Tag::Int(p)))
|
||||
};
|
||||
if raw.iter().any(at) || out.block_entities.iter().any(|(p, _)| *p == pos.into()) {
|
||||
continue;
|
||||
}
|
||||
let tag = Tag::compound([
|
||||
("id", Tag::String(id.into())),
|
||||
("x", Tag::Int(pos[0])),
|
||||
("y", Tag::Int(pos[1])),
|
||||
("z", Tag::Int(pos[2])),
|
||||
]);
|
||||
let tag = crate::block_entity_nbt::canonical(&tag).unwrap_or(tag);
|
||||
match crate::save::decode_block_entity(&tag) {
|
||||
Some(modelled) => out.block_entities.push(modelled),
|
||||
None => raw.push(tag),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VanillaTerrain {
|
||||
fn client_surface(&self, surface: SurfaceSample) -> crate::lod::Surface {
|
||||
crate::lod::Surface {
|
||||
@@ -122,6 +169,7 @@ impl VanillaTerrain {
|
||||
}
|
||||
let mut tick_blocks = Vec::with_capacity(registry.len());
|
||||
let mut tick_states = Vec::new();
|
||||
let mut block_entity_types = Vec::with_capacity(registry.len());
|
||||
let mut last: Option<&str> = None;
|
||||
let mut index = 0u32;
|
||||
for id in 0..registry.len() {
|
||||
@@ -136,6 +184,7 @@ impl VanillaTerrain {
|
||||
}
|
||||
last = Some(name);
|
||||
tick_blocks.push(index);
|
||||
block_entity_types.push(crate::lan::chunks::block_entity_type(name));
|
||||
}
|
||||
Ok(Self {
|
||||
generator,
|
||||
@@ -148,6 +197,7 @@ impl VanillaTerrain {
|
||||
query: std::sync::Mutex::new(None),
|
||||
tick_blocks,
|
||||
tick_states,
|
||||
block_entity_types,
|
||||
seed,
|
||||
dimension: dimension.to_owned(),
|
||||
last_proto: std::sync::atomic::AtomicU64::new(0),
|
||||
@@ -575,7 +625,7 @@ impl ChunkGenerator for VanillaTerrain {
|
||||
// The block entities Horizon does not model (decorated pots with their
|
||||
// sherds and loot table, brushable blocks) stay as placed, like a
|
||||
// loaded chunk's.
|
||||
let unmodelled: Vec<Tag> = chunk
|
||||
let mut unmodelled: Vec<Tag> = chunk
|
||||
.block_entities
|
||||
.iter()
|
||||
.filter(|(pos, _)| {
|
||||
@@ -595,6 +645,7 @@ impl ChunkGenerator for VanillaTerrain {
|
||||
Some(Tag::Compound(nbt))
|
||||
})
|
||||
.collect();
|
||||
add_default_block_entities(&self.block_entity_types, &mut out, &mut unmodelled);
|
||||
if !unmodelled.is_empty() || !rolled_loot.is_empty() {
|
||||
let mut extras = out
|
||||
.saved
|
||||
@@ -618,3 +669,35 @@ impl ChunkGenerator for VanillaTerrain {
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod default_block_entity_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn generated_blocks_get_their_block_entities() {
|
||||
let mut out = Chunk::empty(-2, 3);
|
||||
out.set(4, -40, 9, 7);
|
||||
out.set(5, -40, 9, 6);
|
||||
let mut kinds = vec![None; 8];
|
||||
kinds[6] = Some("minecraft:potent_sulfur");
|
||||
kinds[7] = Some("minecraft:sculk_sensor");
|
||||
let mut raw = vec![];
|
||||
add_default_block_entities(&kinds, &mut out, &mut raw);
|
||||
assert!(matches!(
|
||||
out.block_entities[..],
|
||||
[((-28, -40, 57), crate::containers::BlockEntity::Sculk(_))]
|
||||
));
|
||||
assert_eq!(raw.len(), 1);
|
||||
assert_eq!(
|
||||
raw[0].get("id"),
|
||||
Some(&Tag::String("minecraft:potent_sulfur".into()))
|
||||
);
|
||||
add_default_block_entities(&kinds, &mut out, &mut raw);
|
||||
assert_eq!(
|
||||
(out.block_entities.len(), raw.len()),
|
||||
(1, 1),
|
||||
"a placed block entity is kept, not doubled"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user