Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
Add native_framerate_limit hook so native mods can lower the frame rate
Ratmirfc111a8fc08e
diff --git a/crates/horizon-client/src/game/native_hooks.rs b/crates/horizon-client/src/game/native_hooks.rsindex 663f50403..7269ee525 100644--- a/crates/horizon-client/src/game/native_hooks.rs+++ b/crates/horizon-client/src/game/native_hooks.rs@@ -1359,6 +1359,21 @@ impl Game<'_> {pub(super) fn native_frame(&mut self, elapsed: Duration) {let _ = elapsed;}+ /// The frame rate this window is about to be held to: Max Framerate after the+ /// inactivity throttle and Battery Mode (260 is unlimited). `focused` is whether the+ /// window has focus, `minimized` whether it is minimised and `in_world` whether a world+ /// is open. A mod may lower `limit`, as Dynamic FPS does for a window in the background:+ /// Horizon keeps the lower of its own limit and the mod's, and ignores values below 1.+ /// API @API:framerate_limit@.+ pub(super) fn native_framerate_limit(+ &self,+ focused: bool,+ minimized: bool,+ in_world: bool,+ limit: &mut i32,+ ) {+ let _ = (focused, minimized, in_world, limit);+ }/// Render-thread notification after a resource-pack reload has applied successfully./// Atlas, models, renderer and client caches already refer to the new resources./// Selection/F3+T and server-pack reloads share this point; initial startup does not.diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rsindex 70b943f6c..6d20d85ba 100644--- a/crates/horizon-client/src/game/options.rs+++ b/crates/horizon-client/src/game/options.rs@@ -574,9 +574,19 @@ impl Game<'_> {has_overlay: false,};let limit = framerate_limit(self.settings.max_fps as i32, context);- self.settings+ let limit = self+ .settings.horizon- .battery_limit(limit, self.title.is_none(), self.focused)+ .battery_limit(limit, self.title.is_none(), self.focused);+ // A native mod may only lower it (`native_framerate_limit`).+ let mut hooked = limit;+ self.native_framerate_limit(+ self.focused,+ context.iconified,+ self.title.is_none(),+ &mut hooked,+ );+ if hooked >= 1 { hooked.min(limit) } else { limit }}/// `Minecraft.runTick`'s frame limiter: `FramerateLimiter.limitDisplayFPS`/// below 260 frames per second, sleeping then spin-waiting until thediff --git a/tools/native-hook-fragments/framerate_limit.json b/tools/native-hook-fragments/framerate_limit.jsonnew file mode 100644index 000000000..31bd8891b--- /dev/null+++ b/tools/native-hook-fragments/framerate_limit.json@@ -0,0 +1,13 @@+{+ "hooks": [+ {+ "name": "framerate_limit",+ "target": "horizon_client::game::native_hooks::Game<'_>::native_framerate_limit",+ "neoforge": "none (vanilla FramerateLimitTracker.getFramerateLimit fires no event)",+ "side": "client",+ "cancellable": false+ }+ ],+ "rust_summary": "lowering the frame rate limit, as Dynamic FPS does (`native_framerate_limit`).",+ "doc_summary": "lowering the frame rate limit: `native_framerate_limit(focused, minimized, in_world, limit)` is asked each frame with the limit Horizon is about to use (Max Framerate after the inactivity throttle and Battery Mode, 260 for unlimited), whether the window has focus, whether it is minimised and whether a world is open. A mod may lower `limit`, for example to throttle a window in the background as Dynamic FPS does; Horizon keeps the lower of its own limit and the mod's and ignores values below 1. Bundles that use it need `\"hooks\": @API:framerate_limit@`."+}