Merge pull request #2078 from RoyalPixelsDE/fix/structure-starts
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Chunks now write the structure starts and references they hold, so vanilla keeps the structures (and their spawns) after the round trip. Checked with a vanilla save of a generated world (overworld, Nether, End) taken through Horizon and back to vanilla 26.3 on the server thread and in-frame. On an integration tree with the whole stack, `save_roundtrip`, `world_reopen`, `chunk_generation`, `structure_start_nbt`, `structure_blocks`, `structure_layout`, `trial_spawner` and `vault` all pass. Thanks @FusselTV!
This commit is contained in:
@@ -161,6 +161,9 @@ pub struct Chunk {
|
||||
/// Structure starts reaching into this chunk (`structures.References`):
|
||||
/// structure id and the start's chunk.
|
||||
pub structure_refs: Vec<(Arc<str>, (i32, i32))>,
|
||||
/// The starts generation made in this chunk (`structures.starts`), saved
|
||||
/// with the state their placement has reached by then.
|
||||
pub structure_starts: Vec<Arc<horizon_world::worldgen::structure::start::StructureStart>>,
|
||||
}
|
||||
impl Chunk {
|
||||
pub fn empty(x: i32, z: i32) -> Self {
|
||||
@@ -178,6 +181,7 @@ impl Chunk {
|
||||
block_entities: Vec::new(),
|
||||
block_names: Vec::new(),
|
||||
structure_refs: Vec::new(),
|
||||
structure_starts: Vec::new(),
|
||||
postprocess: Vec::new(),
|
||||
saved: None,
|
||||
entities: Vec::new(),
|
||||
|
||||
@@ -1097,6 +1097,25 @@ pub fn encode_with(
|
||||
.collect();
|
||||
s.insert("References".into(), Tag::Compound(refs));
|
||||
}
|
||||
let starts: Compound = chunk
|
||||
.structure_starts
|
||||
.iter()
|
||||
.filter_map(|start| match start.save() {
|
||||
Some(tag) => Some((start.name.as_str().into(), tag)),
|
||||
None => {
|
||||
log::warn!(
|
||||
"Horizon: structure start {} not saved: one of its pieces cannot be",
|
||||
start.name
|
||||
);
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if !starts.is_empty()
|
||||
&& let Some(Tag::Compound(s)) = map.get_mut(&"structures".into())
|
||||
{
|
||||
s.insert("starts".into(), Tag::Compound(starts));
|
||||
}
|
||||
map.entry("PostProcessing".into())
|
||||
.or_insert_with(|| Tag::List(vec![Tag::List(Vec::new()); shape.section_count()]));
|
||||
}
|
||||
|
||||
@@ -158,6 +158,12 @@ impl VanillaTerrain {
|
||||
chunk.terrain.min_y().max(MIN_Y),
|
||||
(chunk.terrain.min_y() + chunk.terrain.height()).min(MIN_Y + HEIGHT),
|
||||
);
|
||||
out.structure_refs = chunk
|
||||
.structures()
|
||||
.into_iter()
|
||||
.map(|(id, start, _, _)| (Arc::from(id), (start.x, start.z)))
|
||||
.collect();
|
||||
out.structure_starts = chunk.own_starts();
|
||||
let mut values = Box::new([0u32; 4096]);
|
||||
for si in 0..SECTIONS as i32 {
|
||||
let base = MIN_Y + si * 16;
|
||||
@@ -574,11 +580,6 @@ impl ChunkGenerator for VanillaTerrain {
|
||||
extras.block_entities = unmodelled;
|
||||
out.saved = Some(Arc::new(extras));
|
||||
}
|
||||
out.structure_refs = chunk
|
||||
.structures()
|
||||
.into_iter()
|
||||
.map(|(id, start, _, _)| (Arc::from(id), (start.x, start.z)))
|
||||
.collect();
|
||||
let entities = std::mem::take(&mut chunk.entities);
|
||||
out.entities = entities
|
||||
.into_iter()
|
||||
|
||||
@@ -618,6 +618,15 @@ impl ProtoChunk {
|
||||
pub fn is_decorated(&self) -> bool {
|
||||
self.decorated
|
||||
}
|
||||
/// The structure starts this chunk holds itself (`structures.starts`).
|
||||
pub fn own_starts(&self) -> Vec<Arc<super::structure::start::StructureStart>> {
|
||||
let pos = self.position();
|
||||
self.structure_starts
|
||||
.iter()
|
||||
.filter(|s| s.chunk == pos)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
/// Also restores a saved proto chunk that was decorated before it was saved.
|
||||
pub fn set_decorated(&mut self) {
|
||||
self.decorated = true;
|
||||
|
||||
Reference in New Issue
Block a user