Apply generation postprocessing when chunks go live
LevelChunk.postProcessGeneration: positions worldgen marked (aquifer fluids next to open air, sculk veins, fences, ...) get their fluid tick, LiquidBlock tick or shape update once the chunk and its neighbours are loaded, so cave water and lava start to flow and bubble columns rise. Decoration now marks the BlockBehaviour.Properties.postProcess positions of WorldGenRegion.setBlock (mushrooms themselves, above soul sand and magma blocks), which vanilla's bubble columns over underwater magma come from. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,9 @@ pub struct Chunk {
|
||||
pub fresh: bool,
|
||||
/// Block entities read from a save, moved into the world on arrival.
|
||||
pub block_entities: Vec<((i32, i32, i32), crate::containers::BlockEntity)>,
|
||||
/// Generation postprocessing marks (ProtoChunk.postProcessing) as world
|
||||
/// positions, applied once by LevelChunk.postProcessGeneration.
|
||||
pub postprocess: Vec<[i32; 3]>,
|
||||
}
|
||||
impl Chunk {
|
||||
pub fn empty(x: i32, z: i32) -> Self {
|
||||
@@ -110,6 +113,7 @@ impl Chunk {
|
||||
lit: false,
|
||||
fresh: false,
|
||||
block_entities: Vec::new(),
|
||||
postprocess: Vec::new(),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! block interaction, inventory and HUD.
|
||||
mod control;
|
||||
mod end;
|
||||
mod postprocess;
|
||||
use horizon_client::{
|
||||
Result,
|
||||
assets::Assets,
|
||||
@@ -1405,6 +1406,7 @@ impl Game<'_> {
|
||||
self.tick_sleep();
|
||||
self.tick_portal()?;
|
||||
self.tick_end()?;
|
||||
self.postprocess_chunks()?;
|
||||
self.tick_blocks()?;
|
||||
self.tick_falling()?;
|
||||
if let Some(p) = &self.player {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//! LevelChunk.postProcessGeneration: positions that worldgen marked for
|
||||
//! postprocessing (aquifer fluids next to open air, features' shape-dependent
|
||||
//! blocks) are updated once the chunk is live, which starts cave waterfalls
|
||||
//! and lava falls, raises bubble columns over magma and soul sand and fixes
|
||||
//! block shapes against their neighbours.
|
||||
use super::Game;
|
||||
use horizon_client::{Result, blocks::Fluid};
|
||||
use horizon_core::position::BlockPos;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Block.UPDATE_INVISIBLE | UPDATE_KNOWN_SHAPE | UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS.
|
||||
const POSTPROCESS_FLAGS: i32 = 276;
|
||||
|
||||
impl Game<'_> {
|
||||
pub(super) fn postprocess_chunks(&mut self) -> Result<()> {
|
||||
let ready: Vec<(i32, i32)> = self
|
||||
.world
|
||||
.chunks
|
||||
.iter()
|
||||
.filter(|(_, c)| c.lit && !c.postprocess.is_empty())
|
||||
.map(|(k, _)| *k)
|
||||
.filter(|&(x, z)| {
|
||||
(-1..=1)
|
||||
.all(|dz| (-1..=1).all(|dx| self.world.chunks.contains_key(&(x + dx, z + dz))))
|
||||
})
|
||||
.collect();
|
||||
if ready.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
for key in ready {
|
||||
let Some(chunk) = self.world.chunks.get_mut(&key) else {
|
||||
continue;
|
||||
};
|
||||
let marks = std::mem::take(&mut Arc::make_mut(chunk).postprocess);
|
||||
self.with_level(|b, level, ticks| {
|
||||
for [x, y, z] in marks {
|
||||
let pos = BlockPos::new(x, y, z);
|
||||
let state = level.world.block(x, y, z);
|
||||
let facts = level.facts.get(state);
|
||||
let (fluid, liquid_block) = (
|
||||
facts.fluid != Fluid::None,
|
||||
matches!(&*facts.name, "minecraft:water" | "minecraft:lava"),
|
||||
);
|
||||
if fluid {
|
||||
b.scheduled_fluid_tick(level, ticks, pos);
|
||||
}
|
||||
if liquid_block {
|
||||
// LiquidBlock.tick: bubble columns over soul sand and magma.
|
||||
b.scheduled_block_tick(level, ticks, pos);
|
||||
} else {
|
||||
let updated = b.update_from_neighbour_shapes(level, ticks, pos, state);
|
||||
if updated != state {
|
||||
b.set_block(level, ticks, pos, updated, POSTPROCESS_FLAGS);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
self.process_level_events()
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,17 @@ impl ChunkGenerator for VanillaTerrain {
|
||||
}
|
||||
}
|
||||
}
|
||||
let base_section = chunk.terrain.min_y() >> 4;
|
||||
for (i, marks) in chunk.terrain.postprocessing().iter().enumerate() {
|
||||
let sy = (base_section + i as i32) * 16;
|
||||
for &packed in marks {
|
||||
let p = i32::from(packed);
|
||||
let y = sy + ((p >> 4) & 15);
|
||||
if (lo..hi).contains(&y) {
|
||||
out.postprocess.push([bx + (p & 15), y, bz + ((p >> 8) & 15)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut biomes = vec![0u16; 16 * (HEIGHT as usize / 4)];
|
||||
for qy in 0..HEIGHT / 4 {
|
||||
for qz in 0..4 {
|
||||
|
||||
@@ -71,6 +71,10 @@ pub(super) struct Decoration {
|
||||
catalog: FeatureCatalog,
|
||||
/// Placed features referenced by name (feature pool elements), decoded lazily.
|
||||
named: std::sync::Mutex<HashMap<String, Option<Arc<PlacedFeatureDefinition>>>>,
|
||||
/// BlockBehaviour.Properties.postProcess: states whose worldgen writes mark
|
||||
/// their own position (mushrooms) or the one above (soul sand, magma).
|
||||
postprocess_self: Vec<BlockStateId>,
|
||||
postprocess_above: Vec<BlockStateId>,
|
||||
}
|
||||
fn resource(message: impl Into<String>) -> GeneratorError {
|
||||
GeneratorError::Resource(message.into())
|
||||
@@ -214,7 +218,17 @@ impl Decoration {
|
||||
}
|
||||
let plan = FeatureDecorationPlan::new(plan).map_err(|e| resource(e.to_string()))?;
|
||||
let weather = BiomeWeatherBindings::new(&bindings).ok();
|
||||
let states = |names: &[&str]| -> Vec<BlockStateId> {
|
||||
names
|
||||
.iter()
|
||||
.filter_map(|n| registry.default_state(n))
|
||||
.collect()
|
||||
};
|
||||
let postprocess_self = states(&["minecraft:brown_mushroom", "minecraft:red_mushroom"]);
|
||||
let postprocess_above = states(&["minecraft:soul_sand", "minecraft:magma_block"]);
|
||||
Ok(Some(Self {
|
||||
postprocess_self,
|
||||
postprocess_above,
|
||||
plan,
|
||||
names,
|
||||
features,
|
||||
@@ -452,7 +466,7 @@ impl FeatureWorld for World<'_> {
|
||||
&mut self,
|
||||
position: [i32; 3],
|
||||
state: BlockStateId,
|
||||
_flags: i32,
|
||||
flags: i32,
|
||||
) -> Result<bool, RegionError> {
|
||||
if !self
|
||||
.zone
|
||||
@@ -462,6 +476,20 @@ impl FeatureWorld for World<'_> {
|
||||
}
|
||||
self.region.set_block_worldgen(position, state)?;
|
||||
self.block_entities.retain(|(p, _)| *p != position);
|
||||
// WorldGenRegion.setBlock: BlockState.getPostProcessPos unless UPDATE_KNOWN_SHAPE.
|
||||
if flags & 16 == 0 {
|
||||
let [x, y, z] = position;
|
||||
let mark = if self.decoration.postprocess_self.contains(&state) {
|
||||
Some(y)
|
||||
} else if self.decoration.postprocess_above.contains(&state) {
|
||||
Some(y.wrapping_add(1))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(y) = mark {
|
||||
self.region.chunk_mut(x >> 4, z >> 4)?.mark_postprocessing(x, y, z);
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user