Skip to content

Commit 05d0aaa

Browse files
committed
Minecraft 1.20.0 backport
1 parent 4849c0d commit 05d0aaa

File tree

35 files changed

+443
-180
lines changed

35 files changed

+443
-180
lines changed

build-logic/src/main/kotlin/dynamic_fps.java.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ java {
66
withSourcesJar()
77

88
toolchain {
9-
languageVersion = JavaLanguageVersion.of(21)
9+
languageVersion = JavaLanguageVersion.of(17)
1010
}
1111
}
1212

1313
tasks.withType<JavaCompile> {
1414
options.encoding = "UTF-8"
1515

1616
javaCompiler = javaToolchains.compilerFor {
17-
languageVersion = JavaLanguageVersion.of(21)
17+
languageVersion = JavaLanguageVersion.of(17)
1818
}
1919
}

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ maven_group = juliand665
1010
archives_name = dynamic-fps
1111

1212
# File naming version
13-
minecraft_version = 1.21.2-alpha.24w33a
13+
minecraft_version = 1.20.0
1414
# Version for publishing
15-
minecraft_version_min = 24w33a
16-
minecraft_version_max = 24w34a
15+
minecraft_version_min = 1.20.0
16+
minecraft_version_max = 1.20.1
1717

18-
enabled_platforms=fabric,quilt
18+
enabled_platforms=fabric,forge,quilt

gradle/libs.versions.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[versions]
2-
minecraft = "24w33a"
2+
minecraft = "1.20"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.102.2+1.21.2"
7+
fabric_api = "0.83.0+1.20"
88

9-
forge = "1.21-51.0.33"
9+
forge = "1.20-46.0.14"
1010

11-
neoforge = "21.0.143"
11+
neoforge = "20.4.237"
1212

1313
quilt_loader = "0.25.0"
1414

@@ -18,8 +18,8 @@ battery = "1.1.0"
1818

1919
# Modding libraries
2020

21-
modmenu = "11.0.0-beta.1"
22-
cloth_config = "15.0.127"
21+
modmenu = "7.0.0"
22+
cloth_config = "11.0.99"
2323

2424
mixinextras = "0.3.5"
2525

platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
import dynamic_fps.impl.feature.battery.BatteryToast;
1111
import dynamic_fps.impl.feature.battery.BatteryTracker;
1212
import dynamic_fps.impl.feature.state.IdleHandler;
13-
import dynamic_fps.impl.util.BatteryUtil;
14-
import dynamic_fps.impl.util.FallbackConfigScreen;
15-
import dynamic_fps.impl.util.Logging;
13+
import dynamic_fps.impl.util.*;
1614
import dynamic_fps.impl.feature.state.OptionHolder;
17-
import dynamic_fps.impl.util.ResourceLocations;
18-
import dynamic_fps.impl.util.Version;
1915
import dynamic_fps.impl.feature.volume.SmoothVolumeHandler;
2016
import dynamic_fps.impl.util.duck.DuckLoadingOverlay;
2117
import dynamic_fps.impl.feature.state.WindowObserver;
2218
import dynamic_fps.impl.service.Platform;
19+
import dynamic_fps.impl.util.duck.DuckScreen;
2320
import net.lostluma.battery.api.State;
2421
import net.minecraft.Util;
2522
import net.minecraft.client.Minecraft;
@@ -178,7 +175,7 @@ public static GraphicsState graphicsState() {
178175
}
179176

180177
public static boolean shouldShowLevels() {
181-
return isDisabled() || !isLevelCoveredByOverlay();
178+
return isDisabled() || !(isLevelCoveredByScreen() || isLevelCoveredByOverlay());
182179
}
183180

184181
public static void onBatteryChargeChanged(int before, int after) {
@@ -200,11 +197,17 @@ public static void onBatteryStatusChanged(State before, State after) {
200197
private static void doInit() {
201198
// NOTE: Init battery tracker first here
202199
// Since the idle handler queries it for info
200+
ModCompatHelper.init();
201+
203202
BatteryTracker.init();
204203
IdleHandler.init();
205204
SmoothVolumeHandler.init();
206205
}
207206

207+
private static boolean isLevelCoveredByScreen() {
208+
return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground();
209+
}
210+
208211
private static void showNotification(String titleTranslationKey, String iconPath) {
209212
if (!DynamicFPSConfig.INSTANCE.batteryTracker().notifications()) {
210213
return;

platforms/common/src/main/java/dynamic_fps/impl/config/option/IdleCondition.java

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
public enum IdleCondition {
44
NONE,
5-
VANILLA,
65
ON_BATTERY;
76
}

platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryToast.java

+10-28
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import dynamic_fps.impl.util.ResourceLocations;
44
import net.minecraft.client.Minecraft;
5-
import net.minecraft.client.gui.Font;
65
import net.minecraft.client.gui.GuiGraphics;
76
import net.minecraft.client.gui.components.toasts.Toast;
8-
import net.minecraft.client.gui.components.toasts.ToastManager;
9-
import net.minecraft.client.renderer.RenderType;
7+
import net.minecraft.client.gui.components.toasts.ToastComponent;
108
import net.minecraft.network.chat.Component;
119
import net.minecraft.resources.ResourceLocation;
1210
import org.jetbrains.annotations.NotNull;
@@ -19,7 +17,6 @@ public class BatteryToast implements Toast {
1917
private Component title;
2018
private Component description;
2119
private ResourceLocation icon;
22-
private Visibility visibility;
2320

2421
private static BatteryToast queuedToast;
2522

@@ -29,7 +26,6 @@ public class BatteryToast implements Toast {
2926
private BatteryToast(Component title, ResourceLocation icon) {
3027
this.title = title;
3128
this.icon = icon;
32-
this.visibility = Visibility.SHOW;
3329
}
3430

3531
/**
@@ -42,28 +38,12 @@ public static void queueToast(Component title, ResourceLocation icon) {
4238
queuedToast.icon = icon;
4339
} else {
4440
queuedToast = new BatteryToast(title, icon);
45-
Minecraft.getInstance().getToastManager().addToast(queuedToast);
41+
Minecraft.getInstance().getToasts().addToast(queuedToast);
4642
}
4743
}
4844

4945
@Override
50-
public @NotNull Visibility getWantedVisibility() {
51-
return this.visibility;
52-
}
53-
54-
@Override
55-
public void update(ToastManager toastManager, long currentTime) {
56-
if (this.firstRender == 0) {
57-
return;
58-
}
59-
60-
if (currentTime - this.firstRender >= 5000.0 * toastManager.getNotificationDisplayTimeMultiplier()) {
61-
this.visibility = Visibility.HIDE;
62-
}
63-
}
64-
65-
@Override
66-
public void render(GuiGraphics graphics, Font font, long currentTime) {
46+
public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) {
6747
if (this.firstRender == 0) {
6848
if (this == queuedToast) {
6949
queuedToast = null;
@@ -75,12 +55,14 @@ public void render(GuiGraphics graphics, Font font, long currentTime) {
7555
}
7656

7757
// resource, x, y, z, ?, ?, width, height, width, height
78-
graphics.blit(RenderType::guiTextured, BACKGROUND_IMAGE, 0, 0, 0, 0.0f, 0, this.width(), this.height(), this.width(), this.height());
58+
graphics.blit(BACKGROUND_IMAGE, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
59+
60+
graphics.blit(MOD_ICON, 2, 2, 0, 0.0f, 0.0f, 8, 8, 8, 8);
61+
graphics.blit(this.icon, 8, 8, 0, 0.0f, 0.0f, 16, 16, 16, 16);
7962

80-
graphics.blit(RenderType::guiTextured, MOD_ICON, 2, 2, 0, 0.0f, 0, 8, 8, 8, 8);
81-
graphics.blit(RenderType::guiTextured, this.icon, 8, 8, 0, 0.0f, 0, 16, 16, 16, 16);
63+
graphics.drawString(toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315, false);
64+
graphics.drawString(toastComponent.getMinecraft().font, this.description, 30, 18, -16777216, false);
8265

83-
graphics.drawString(Minecraft.getInstance().font, this.title, 30, 7, 0x5f3315, false);
84-
graphics.drawString(Minecraft.getInstance().font, this.description, 30, 18, -16777216, false);
66+
return currentTime - this.firstRender >= 5000.0 * toastComponent.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
8567
}
8668
}

platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryTracker.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void init() {
7070
}
7171
} else {
7272
manager = temp; // Keep around to allow updating batteries
73-
Thread.ofVirtual().name("refresh-battery").start(BatteryTracker::updateBatteries);
73+
new Thread(BatteryTracker::updateBatteries, "refresh-battery").start();
7474
}
7575
}
7676

@@ -139,7 +139,7 @@ private static void updateBatteries() {
139139
updateState();
140140

141141
try {
142-
Thread.sleep(updateInterval);
142+
Thread.sleep(updateInterval.toMillis());
143143
} catch (InterruptedException e) {
144144
active = false;
145145
Thread.currentThread().interrupt();

platforms/common/src/main/java/dynamic_fps/impl/feature/state/OptionHolder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import net.minecraft.client.CloudStatus;
55
import net.minecraft.client.GraphicsStatus;
66
import net.minecraft.client.Options;
7-
import net.minecraft.server.level.ParticleStatus;
7+
import net.minecraft.client.ParticleStatus;
88

99
/*
1010
* Helper for saving, overriding, and re-applying vanilla options.

platforms/common/src/main/java/dynamic_fps/impl/mixin/FramerateLimitTrackerMixin.java

-99
This file was deleted.

platforms/common/src/main/java/dynamic_fps/impl/mixin/MinecraftMixin.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class MinecraftMixin {
2121
@Shadow
2222
@Final
23-
private Window window;
23+
private Window window;
2424

2525
@Shadow
2626
@Final
@@ -36,4 +36,32 @@ private void setScreen(CallbackInfo callbackInfo) {
3636
IdleHandler.onActivity();
3737
}
3838

39+
/**
40+
* Conditionally bypasses the main menu frame rate limit.
41+
*
42+
* This is done in two cases:
43+
* - The window is active, and the user wants to uncap the frame rate
44+
* - The window is inactive, and the current FPS limit should be lower
45+
*/
46+
@Inject(method = "getFramerateLimit", at = @At(value = "CONSTANT", args = "intValue=60"), cancellable = true)
47+
private void getFramerateLimit(CallbackInfoReturnable<Integer> callbackInfo) {
48+
int limit = this.window.getFramerateLimit();
49+
50+
if (DynamicFPSMod.powerState() != PowerState.FOCUSED) {
51+
// Vanilla returns 60 here
52+
// Only overwrite if our current limit is lower
53+
if (limit < 60) {
54+
callbackInfo.setReturnValue(limit);
55+
}
56+
} else if (DynamicFPSConfig.INSTANCE.uncapMenuFrameRate()) {
57+
if (this.options.enableVsync().get()) {
58+
// VSync will regulate to a non-infinite value
59+
callbackInfo.setReturnValue(Constants.NO_FRAME_RATE_LIMIT);
60+
} else {
61+
// Even though the option "uncaps" the frame rate the limit is 250 FPS.
62+
// Since otherwise this will just cause coil whine with no real benefit
63+
callbackInfo.setReturnValue(Math.min(limit, Constants.NO_FRAME_RATE_LIMIT - 10));
64+
}
65+
}
66+
}
3967
}

0 commit comments

Comments
 (0)