[PR #2154] [MERGED] Daylight detectors follow the sky and update when used #4055

Closed
opened 2026-11-03 04:14:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2154
Author: @kacpherek
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: fix/daylight-detector


📝 Commits (2)

  • d0af843 Daylight detectors follow the sky and update when used
  • aa8a78e Merge main into fix/daylight-detector

📊 Changes

7 files changed (+95 additions, -5 deletions)

View changed files

📝 crates/horizon-client/src/containers.rs (+13 -3)
📝 crates/horizon-client/src/game.rs (+14 -0)
📝 crates/horizon-client/src/game/block_entity_ticks.rs (+13 -0)
📝 crates/horizon-client/src/save.rs (+3 -1)
📝 crates/horizon-world/src/level/interact.rs (+1 -0)
📝 crates/horizon-world/src/level/mod.rs (+22 -0)
📝 crates/horizon-world/src/level/redstone.rs (+29 -1)

📄 Description

What and why

A daylight detector under open sky always reads power 0. In game, a normal detector reads 0 at noon, and an inverted one reads 0 at midnight (vanilla gives about 15 in both cases). Nothing ever updated the detector's power, and flipping inverted by using it did not recompute it either.

This change:

  • gives the daylight detector a block entity (BlockEntity::DaylightDetector, no data, saved and loaded under minecraft:daylight_detector like vanilla) so it has a ticker;
  • updates the power every 20 game ticks (game_time % 20 == 0), not in the Nether (no sky light there), from the sky light at the block minus the sky darkening, shaped by the sun angle, or 15 - target when inverted, clamped to 0..15, and only writes the block if the power changed;
  • recomputes the power right away when the detector is used to flip inverted;
  • adds LevelAccess::sun_angle (degrees, default 0) so the behaviour library can read the dimension environment's visual/sun_angle; the game answers it from the same environment tables it already uses for the sky.

Not covered: detectors placed before this change were saved without a block entity, so they keep showing their old power until they are placed again.

Vanilla reference

  • DaylightDetectorBlock.updateSignalStrength (effective sky brightness, SUN_ANGLE formula for the normal detector, 15 - target for the inverted one, clamp, setBlockAndUpdate only on change)
  • DaylightDetectorBlock.tickEntity and getTicker (every 20 game ticks, server only, only in dimensions with sky light)
  • DaylightDetectorBlock.useWithoutItem (cycles inverted, then recomputes at once)
  • LevelReader.getEffectiveSkyBrightness (sky light minus getSkyDarken, at least 0)

Self-check

cargo check -p horizon-client passes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/2154 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/daylight-detector` --- ### 📝 Commits (2) - [`d0af843`](https://github.com/horizon-rust/horizon/commit/d0af8430948c1f277a7f3e1b574dd2c7311babb8) Daylight detectors follow the sky and update when used - [`aa8a78e`](https://github.com/horizon-rust/horizon/commit/aa8a78e1b7cc1f31102c3acdfe1f5e1f10da5ce9) Merge main into fix/daylight-detector ### 📊 Changes **7 files changed** (+95 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/containers.rs` (+13 -3) 📝 `crates/horizon-client/src/game.rs` (+14 -0) 📝 `crates/horizon-client/src/game/block_entity_ticks.rs` (+13 -0) 📝 `crates/horizon-client/src/save.rs` (+3 -1) 📝 `crates/horizon-world/src/level/interact.rs` (+1 -0) 📝 `crates/horizon-world/src/level/mod.rs` (+22 -0) 📝 `crates/horizon-world/src/level/redstone.rs` (+29 -1) </details> ### 📄 Description ## What and why A daylight detector under open sky always reads power 0. In game, a normal detector reads 0 at noon, and an inverted one reads 0 at midnight (vanilla gives about 15 in both cases). Nothing ever updated the detector's `power`, and flipping `inverted` by using it did not recompute it either. This change: - gives the daylight detector a block entity (`BlockEntity::DaylightDetector`, no data, saved and loaded under `minecraft:daylight_detector` like vanilla) so it has a ticker; - updates the power every 20 game ticks (`game_time % 20 == 0`), not in the Nether (no sky light there), from the sky light at the block minus the sky darkening, shaped by the sun angle, or `15 - target` when inverted, clamped to 0..15, and only writes the block if the power changed; - recomputes the power right away when the detector is used to flip `inverted`; - adds `LevelAccess::sun_angle` (degrees, default 0) so the behaviour library can read the dimension environment's `visual/sun_angle`; the game answers it from the same environment tables it already uses for the sky. Not covered: detectors placed before this change were saved without a block entity, so they keep showing their old power until they are placed again. ## Vanilla reference - `DaylightDetectorBlock.updateSignalStrength` (effective sky brightness, `SUN_ANGLE` formula for the normal detector, `15 - target` for the inverted one, clamp, `setBlockAndUpdate` only on change) - `DaylightDetectorBlock.tickEntity` and `getTicker` (every 20 game ticks, server only, only in dimensions with sky light) - `DaylightDetectorBlock.useWithoutItem` (cycles `inverted`, then recomputes at once) - `LevelReader.getEffectiveSkyBrightness` (sky light minus `getSkyDarken`, at least 0) ## Self-check `cargo check -p horizon-client` passes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:14:22 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#4055
No description provided.