Worldgen shape updates schedule their ticks in the proto chunks
StructureTemplate.updateShapeAtEdge (every tree, structure pieces) and Block.updateFromNeighbourShapes run updateShape on a WorldGenRegion, where LeavesBlock.updateShape schedules a one-tick block tick to re-measure its distance and waterlogged blocks schedule fluid ticks: vanilla keeps them in ProtoChunkTicks and runs them once the chunk is live. Horizon ran updateShape against a throwaway tick scheduler and lost them, so leaves where trees overlap kept the distance their own tree gave them (one more than vanilla's for thousands of leaves in a taiga), and could decay where vanilla's don't. level::Ticks gains a capture mode; the decoration world schedules what a shape update captured, in order, before the update's own setBlock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,18 @@ pub struct Ticks {
|
||||
pub block_events: Vec<super::pistons::BlockEventData>,
|
||||
/// `ServerLevel.isHandlingTick` (true while scheduled ticks run).
|
||||
pub(crate) handling_tick: bool,
|
||||
/// Worldgen shape updates collect the ticks they schedule here, for the
|
||||
/// proto chunks of their region, instead of scheduling them.
|
||||
pub(crate) capture: Option<Vec<CapturedTick>>,
|
||||
}
|
||||
/// A tick scheduled while `Ticks::capture` is set.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) struct CapturedTick {
|
||||
pub fluid: bool,
|
||||
/// `BlockId` for block ticks, `FluidKind` for fluid ticks.
|
||||
pub kind: u32,
|
||||
pub pos: BlockPos,
|
||||
pub delay: i32,
|
||||
}
|
||||
impl Default for Ticks {
|
||||
fn default() -> Self {
|
||||
@@ -56,6 +68,7 @@ impl Ticks {
|
||||
next_block_entity_id: 0,
|
||||
block_events: Vec::new(),
|
||||
handling_tick: false,
|
||||
capture: None,
|
||||
}
|
||||
}
|
||||
/// Register a loaded chunk's saved block and fluid ticks.
|
||||
@@ -89,6 +102,15 @@ impl Ticks {
|
||||
delay: i32,
|
||||
priority: TickPriority,
|
||||
) -> ScheduleResult {
|
||||
if let Some(captured) = &mut self.capture {
|
||||
captured.push(CapturedTick {
|
||||
fluid: false,
|
||||
kind: u32::from(block.0),
|
||||
pos,
|
||||
delay,
|
||||
});
|
||||
return ScheduleResult::Added;
|
||||
}
|
||||
let tick = ScheduledTick {
|
||||
kind: TickTypeId(u32::from(block.0)),
|
||||
pos,
|
||||
@@ -105,6 +127,15 @@ impl Ticks {
|
||||
fluid: FluidKind,
|
||||
delay: i32,
|
||||
) -> ScheduleResult {
|
||||
if let Some(captured) = &mut self.capture {
|
||||
captured.push(CapturedTick {
|
||||
fluid: true,
|
||||
kind: fluid as u32,
|
||||
pos,
|
||||
delay,
|
||||
});
|
||||
return ScheduleResult::Added;
|
||||
}
|
||||
let tick = ScheduledTick {
|
||||
kind: TickTypeId(fluid as u32),
|
||||
pos,
|
||||
|
||||
@@ -511,13 +511,16 @@ impl World<'_> {
|
||||
direction: Direction,
|
||||
neighbor_pos: [i32; 3],
|
||||
neighbor: BlockStateId,
|
||||
) -> BlockStateId {
|
||||
) -> (BlockStateId, Vec<crate::level::ticks::CapturedTick>) {
|
||||
let mut level = ShapeLevel {
|
||||
world: self,
|
||||
random: horizon_core::random::LegacyRandom::new(0),
|
||||
};
|
||||
// The ticks updateShape schedules (LeavesBlock re-measuring its
|
||||
// distance, waterlogged blocks' fluid) go to the proto chunks.
|
||||
let mut ticks = crate::level::Ticks::new(0);
|
||||
behaviours.update_shape(
|
||||
ticks.capture = Some(Vec::new());
|
||||
let updated = behaviours.update_shape(
|
||||
&mut level,
|
||||
&mut ticks,
|
||||
state,
|
||||
@@ -525,7 +528,28 @@ impl World<'_> {
|
||||
direction,
|
||||
BlockPos::new(neighbor_pos[0], neighbor_pos[1], neighbor_pos[2]),
|
||||
neighbor,
|
||||
)
|
||||
);
|
||||
(updated, ticks.capture.take().unwrap_or_default())
|
||||
}
|
||||
/// Schedule ticks a shape update requested in the region's proto chunks.
|
||||
fn schedule_captured(
|
||||
&mut self,
|
||||
behaviours: &crate::level::Behaviours,
|
||||
ticks: Vec<crate::level::ticks::CapturedTick>,
|
||||
) -> Result<(), PlacementQueryError> {
|
||||
for t in ticks {
|
||||
let at = [t.pos.x, t.pos.y, t.pos.z];
|
||||
if t.fluid {
|
||||
let fluid = crate::fluid::FluidKind::ALL[t.kind as usize];
|
||||
self.schedule_fluid_tick(at, fluid, t.delay)?;
|
||||
} else {
|
||||
let state = behaviours
|
||||
.table
|
||||
.default_state(crate::level::BlockId(t.kind as u16));
|
||||
self.schedule_block_tick(at, state, t.delay)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl DecorationWorld for World<'_> {
|
||||
@@ -879,7 +903,7 @@ impl PlacementContext for World<'_> {
|
||||
let neighbor_pos = [position[0] + n[0], position[1] + n[1], position[2] + n[2]];
|
||||
let state = self.region.block(position).map_err(query)?;
|
||||
let neighbor = self.region.block(neighbor_pos).map_err(query)?;
|
||||
let new_state = self.shape_update(
|
||||
let (new_state, ticks) = self.shape_update(
|
||||
behaviours,
|
||||
state,
|
||||
position,
|
||||
@@ -887,11 +911,12 @@ impl PlacementContext for World<'_> {
|
||||
neighbor_pos,
|
||||
neighbor,
|
||||
);
|
||||
self.schedule_captured(behaviours, ticks)?;
|
||||
if new_state != state {
|
||||
self.set_block(position, new_state, flags & !1)
|
||||
.map_err(query)?;
|
||||
}
|
||||
let new_neighbor = self.shape_update(
|
||||
let (new_neighbor, ticks) = self.shape_update(
|
||||
behaviours,
|
||||
neighbor,
|
||||
neighbor_pos,
|
||||
@@ -899,6 +924,7 @@ impl PlacementContext for World<'_> {
|
||||
position,
|
||||
new_state,
|
||||
);
|
||||
self.schedule_captured(behaviours, ticks)?;
|
||||
if new_neighbor != neighbor {
|
||||
self.set_block(neighbor_pos, new_neighbor, flags & !1)
|
||||
.map_err(query)?;
|
||||
@@ -927,7 +953,7 @@ impl PlacementContext for World<'_> {
|
||||
let n = direction.normal();
|
||||
let neighbor_pos = [position[0] + n[0], position[1] + n[1], position[2] + n[2]];
|
||||
let neighbor = self.region.block(neighbor_pos).map_err(query)?;
|
||||
new_state = self.shape_update(
|
||||
let (updated, ticks) = self.shape_update(
|
||||
behaviours,
|
||||
new_state,
|
||||
position,
|
||||
@@ -935,6 +961,8 @@ impl PlacementContext for World<'_> {
|
||||
neighbor_pos,
|
||||
neighbor,
|
||||
);
|
||||
self.schedule_captured(behaviours, ticks)?;
|
||||
new_state = updated;
|
||||
}
|
||||
if new_state != state {
|
||||
self.set_block(position, new_state, flags).map_err(query)?;
|
||||
|
||||
Reference in New Issue
Block a user