Merge pull request #2154 from kacpherek/fix/daylight-detector

🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `DaylightDetectorBlock.updateSignalStrength` (sky light minus darkening, the sun-angle curve, the inverted mode) and its update when used. Main conflicted with its new campfire block entity, so I merged main into the branch, keeping both block entities. Gate: this wave's 55 PRs merged on main in one tree: clippy `-D warnings` clean, 1186 horizon-client and 163 horizon-world tests pass, and of the 101 harnesses `parity.py --changed-files` picked, 100 pass (`block_removal` failed on one spawner case from #2199's orb merging, fixed there). `lan_e2e.py` passes 24 checks with the host on its server thread and in-frame (chest, xp, pvp, doors, villagers, beds, frames, projectiles, arrows, fishing, damage, mobs, blast, drops, elytra, breath, predict, cracks, barter, kills, hurt, contacts, underwater, plates), plus forced-levels on the server thread. Thanks @kacpherek!
This commit is contained in:
Ludovic Marie
2026-10-26 19:48:14 +01:00
committed by GitHub
7 changed files with 95 additions and 5 deletions
+13 -3
View File
@@ -98,6 +98,9 @@ pub enum BlockEntity {
Campfire(Box<Campfire>),
/// `SkullBlockEntity` of every skull and head block.
Skull(Skull),
/// `DaylightDetectorBlockEntity`: no data, only the ticker
/// (`DaylightDetectorBlock.tickEntity`).
DaylightDetector,
}
/// `CampfireBlockEntity`: four cooking slots, each with its
/// `cookingProgress` and `cookingTime` (the recipe's).
@@ -363,6 +366,9 @@ impl BlockEntity {
if is_skull(name) {
return Some(Self::Skull(Skull::default()));
}
if name == "minecraft:daylight_detector" {
return Some(Self::DaylightDetector);
}
if name == "minecraft:beacon" {
return Some(Self::Beacon(Box::new(Beacon {
last_check_y: i32::MIN / 2,
@@ -412,6 +418,7 @@ impl BlockEntity {
Self::Beehive(_) => "minecraft:beehive",
Self::CommandBlock(_) => "minecraft:command_block",
Self::Skull(_) => "minecraft:skull",
Self::DaylightDetector => "minecraft:daylight_detector",
Self::Campfire(_) => "minecraft:campfire",
}
}
@@ -429,7 +436,8 @@ impl BlockEntity {
| Self::Vault(_)
| Self::Beehive(_)
| Self::CommandBlock(_)
| Self::Skull(_) => Vec::new(),
| Self::Skull(_)
| Self::DaylightDetector => Vec::new(),
Self::Lectern(l) => l.book.iter().cloned().collect(),
Self::Sculk(_) => Vec::new(),
Self::Banner(_) => Vec::new(),
@@ -448,7 +456,8 @@ impl BlockEntity {
| Self::Lectern(_)
| Self::Sculk(_)
| Self::Banner(_)
| Self::Skull(_) => &[],
| Self::Skull(_)
| Self::DaylightDetector => &[],
Self::Crafter(c) => &c.items,
Self::CreakingHeart(_)
| Self::Spawner(_)
@@ -471,7 +480,8 @@ impl BlockEntity {
| Self::Lectern(_)
| Self::Sculk(_)
| Self::Banner(_)
| Self::Skull(_) => &mut [],
| Self::Skull(_)
| Self::DaylightDetector => &mut [],
Self::Crafter(c) => &mut c.items,
Self::CreakingHeart(_)
| Self::Spawner(_)
+14
View File
@@ -537,6 +537,8 @@ struct GameLevel<'w> {
events: &'w mut Vec<LevelEvent>,
dimension: LevelDimension,
darken: i32,
/// The environment of the level's dimension (`SUN_ANGLE`).
environment: &'w Environment,
raining: bool,
thundering: bool,
player_box: Option<([f64; 3], [f64; 3])>,
@@ -803,6 +805,11 @@ impl LevelAccess for GameLevel<'_> {
fn sky_darken(&self) -> i32 {
self.darken
}
fn sun_angle(&self, _pos: BlockPos) -> f32 {
self.environment
.sample(self.world.day_time, None, None)
.sun_angle
}
fn is_raining(&self) -> bool {
self.raining
}
@@ -2548,6 +2555,11 @@ impl Game<'_> {
events: &mut self.level_events,
dimension,
darken,
environment: match dimension {
LevelDimension::Overworld => self.res.environment(),
LevelDimension::Nether => self.res.nether_environment(),
LevelDimension::End => self.res.end_environment(),
},
raining: rain > 0.2,
thundering: thunder > 0.9,
player_box,
@@ -5394,6 +5406,7 @@ impl Game<'_> {
| BlockEntity::Beehive(_)
| BlockEntity::CommandBlock(_)
| BlockEntity::Skull(_)
| BlockEntity::DaylightDetector
| BlockEntity::Campfire(_),
) => {}
None => {
@@ -5665,6 +5678,7 @@ impl Game<'_> {
| BlockEntity::Beehive(_)
| BlockEntity::CommandBlock(_)
| BlockEntity::Skull(_)
| BlockEntity::DaylightDetector
| BlockEntity::Campfire(_),
) => {}
None if self.mount_active() => self.draw_mount_background(batch, ox, oy),
@@ -10,6 +10,7 @@ use horizon_client::{
block_entities::{Pos, Ticking},
containers::{BlockEntity, FurnaceKind, HOPPER_SLOTS},
};
use horizon_core::position::BlockPos;
use horizon_world::registry::BlockStateId;
impl Game<'_> {
@@ -56,6 +57,7 @@ impl Game<'_> {
Some(BlockEntity::Beehive(_)) => self.tick_beehive(pos),
Some(BlockEntity::Furnace(_)) => self.tick_furnace(pos)?,
Some(BlockEntity::Brewing(_)) => self.tick_brewing_stand(pos)?,
Some(BlockEntity::DaylightDetector) => self.tick_daylight_detector(pos),
Some(BlockEntity::Campfire(_)) => self.tick_campfire(pos)?,
_ => {}
}
@@ -94,6 +96,7 @@ impl Game<'_> {
| "minecraft:beehive"
| "minecraft:bee_nest"
| "minecraft:brewing_stand"
| "minecraft:daylight_detector"
// Lit, cookTick; unlit, cooldownTick.
| "minecraft:campfire"
| "minecraft:soul_campfire" => Ticking::Yes,
@@ -117,6 +120,16 @@ impl Game<'_> {
let levels = self.tickets.levels();
move |x, z| levels.block_ticking_at(x, z)
}
/// `DaylightDetectorBlock.tickEntity` of the detector at `pos`.
fn tick_daylight_detector(&mut self, pos: Pos) {
// It updates every 20 game ticks (the behaviour checks this too).
if self.world.game_time % 20 != 0 {
return;
}
let at = BlockPos::new(pos.0, pos.1, pos.2);
self.with_level(|b, level, ticks| b.tick_daylight_detector(level, ticks, at));
let _ = self.process_level_events();
}
/// `AbstractFurnaceBlockEntity.serverTick` of the furnace at `pos`, and
/// its block's `lit` following it.
fn tick_furnace(&mut self, pos: Pos) -> Result<()> {
+3 -1
View File
@@ -648,6 +648,7 @@ pub fn encode_block_entity(
BlockEntity::Vault(v) => entries.extend(v.save()),
BlockEntity::Beehive(h) => entries.extend(h.to_nbt()),
BlockEntity::CommandBlock(c) => entries.extend(c.save()),
BlockEntity::DaylightDetector => {}
}
Tag::compound(entries)
}
@@ -845,7 +846,8 @@ pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::contain
| BlockEntity::Lectern(_)
| BlockEntity::Banner(_)
| BlockEntity::CreakingHeart(_)
| BlockEntity::Skull(_) => {}
| BlockEntity::Skull(_)
| BlockEntity::DaylightDetector => {}
BlockEntity::Spawner(s) => **s = crate::mobs::spawner::Spawner::load(tag),
BlockEntity::TrialSpawner(s) => **s = crate::mobs::trial_spawner::TrialSpawner::load(tag),
BlockEntity::Vault(v) => **v = crate::vault::Vault::load(tag),
@@ -195,6 +195,7 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
let next = table.cycle(state, p.inverted);
self.set_block(pos, next, 2);
self.game_event(pos, "minecraft:block_change");
self.daylight_detector_update_signal(pos, next);
Success
}
Class::Cake => {
+22
View File
@@ -328,6 +328,10 @@ pub trait LevelAccess {
fn sky_darken(&self) -> i32 {
0
}
/// `EnvironmentAttributes.SUN_ANGLE` at `pos`, in degrees (0 at noon).
fn sun_angle(&self, _pos: BlockPos) -> f32 {
0.0
}
fn is_raining(&self) -> bool {
false
}
@@ -763,6 +767,24 @@ impl Behaviours {
) {
self.sim(level, ticks).entity_inside(pos);
}
/// `DaylightDetectorBlock.tickEntity` of the daylight detector at `pos`:
/// its signal follows the sky every 20 game ticks. The detector's ticker
/// exists only where the dimension has sky light.
pub fn tick_daylight_detector<L: LevelAccess + ?Sized>(
&self,
level: &mut L,
ticks: &mut Ticks,
pos: BlockPos,
) {
if level.dimension() == Dimension::Nether || level.game_time() % 20 != 0 {
return;
}
let mut sim = self.sim(level, ticks);
let state = sim.state(pos);
if sim.b.data(state).is(classes::Class::DaylightDetector) {
sim.daylight_detector_update_signal(pos, state);
}
}
/// `BigDripleafBlock.entityInside` for an entity whose box is inside
/// `pos`: whether it is on the ground and its feet's y (`canEntityTilt`).
pub fn entity_on_big_dripleaf<L: LevelAccess + ?Sized>(
+29 -1
View File
@@ -11,7 +11,10 @@ use super::{
};
use crate::registry::BlockStateId;
use horizon_core::{
geometry::Direction, position::BlockPos, random::RandomSource, ticks::TickPriority,
geometry::{Direction, trig},
position::BlockPos,
random::RandomSource,
ticks::TickPriority,
};
const SIGNAL_ORDER: [Direction; 6] = [
@@ -892,6 +895,31 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
}
self.game_event(pos, "minecraft:block_deactivate");
}
/// `DaylightDetectorBlock.updateSignalStrength`: the effective sky light
/// at the detector, shaped by the sun's angle (or inverted), as its
/// power.
pub(crate) fn daylight_detector_update_signal(&mut self, pos: BlockPos, state: BlockStateId) {
let b = self.b;
let mut target = (self.level.sky_light(pos) - self.level.sky_darken()).max(0);
if b.table.bool(state, b.props.inverted) {
target = 15 - target;
} else if target > 0 {
let mut sun_angle = self.level.sun_angle(pos) * trig::DEG_TO_RAD;
let offset = if sun_angle < std::f32::consts::PI {
0.0
} else {
std::f32::consts::TAU
};
sun_angle += (offset - sun_angle) * 0.2;
// Math.round(float).
let scaled = target as f32 * trig::cos(f64::from(sun_angle));
target = (f64::from(scaled) + 0.5).floor() as i32;
}
let target = target.clamp(0, 15);
if b.table.int(state, b.props.power) != target {
self.set_block_and_update(pos, b.table.set_int(state, b.props.power, target));
}
}
/// `LeverBlock.pull`.
pub(crate) fn lever_pull(&mut self, pos: BlockPos, state: BlockStateId) {
let b = self.b;