Skip to content

Commit 2bf5fbc

Browse files
committed
Minecraft 1.20.0 backport
Signed-off-by: Lilly Rose Berner <lilly@lostluma.net>
1 parent a617f25 commit 2bf5fbc

39 files changed

+454
-196
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
@@ -13,9 +13,9 @@ maven_group = juliand665
1313
archives_name = dynamic-fps
1414

1515
# File naming version
16-
minecraft_version = 1.21.5
16+
minecraft_version = 1.20.0
1717
# Version for publishing
18-
minecraft_version_min = 1.21.5
19-
minecraft_version_max = 1.21.5
18+
minecraft_version_min = 1.20
19+
minecraft_version_max = 1.20.1
2020

21-
enabled_platforms=fabric,quilt
21+
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 = "1.21.5"
2+
minecraft = "1.20"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.118.2+1.21.5"
7+
fabric_api = "0.83.0+1.20"
88

9-
forge = "1.21.3-53.0.7"
9+
forge = "1.20-46.0.14"
1010

11-
neoforge = "21.3.0-beta"
11+
neoforge = "20.4.237"
1212

1313
quilt_loader = "0.25.0"
1414

@@ -18,8 +18,8 @@ battery = "1.3.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.4.1"
2525

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import dynamic_fps.impl.util.FallbackConfigScreen;
1717
import dynamic_fps.impl.util.Logging;
1818
import dynamic_fps.impl.feature.state.OptionHolder;
19+
import dynamic_fps.impl.util.ModCompatHelper;
1920
import dynamic_fps.impl.util.ResourceLocations;
2021
import dynamic_fps.impl.util.Threads;
2122
import dynamic_fps.impl.util.Version;
2223
import dynamic_fps.impl.feature.volume.SmoothVolumeHandler;
2324
import dynamic_fps.impl.util.duck.DuckLoadingOverlay;
2425
import dynamic_fps.impl.feature.state.WindowObserver;
2526
import dynamic_fps.impl.service.Platform;
27+
import dynamic_fps.impl.util.duck.DuckScreen;
2628
import net.lostluma.battery.api.State;
2729
import net.minecraft.Util;
2830
import net.minecraft.client.Minecraft;
@@ -190,7 +192,7 @@ public static GraphicsState graphicsState() {
190192
}
191193

192194
public static boolean shouldShowLevels() {
193-
return isDisabled() || !isLevelCoveredByOverlay();
195+
return isDisabled() || !(isLevelCoveredByScreen() || isLevelCoveredByOverlay());
194196
}
195197

196198
public static void onBatteryChargeChanged(int before, int after) {
@@ -214,6 +216,8 @@ public static void onBatteryStatusChanged(State before, State after) {
214216
private static void doInit() {
215217
initClickHandler();
216218
SmoothVolumeHandler.init();
219+
// NOTE: Init battery tracker first here
220+
// Since the idle handler queries it for info
217221

218222
if (!BatteryTracker.isFeatureEnabled()) {
219223
IdleHandler.init();
@@ -227,6 +231,8 @@ private static void doInit() {
227231
Threads.runOnMainThread(IdleHandler::init);
228232
});
229233
}
234+
235+
ModCompatHelper.init();
230236
}
231237

232238
private static void initClickHandler() {
@@ -239,6 +245,11 @@ private static void initClickHandler() {
239245
clickHandler = new ClickIgnoreHandler(window.address());
240246
}
241247
}
248+
249+
private static boolean isLevelCoveredByScreen() {
250+
return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground();
251+
}
252+
242253
private static void showNotification(String titleTranslationKey, String iconPath) {
243254
if (!DynamicFPSConfig.INSTANCE.batteryTracker().notifications()) {
244255
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/BaseToast.java

+10-27
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import net.minecraft.client.gui.Font;
66
import net.minecraft.client.gui.GuiGraphics;
77
import net.minecraft.client.gui.components.toasts.Toast;
8-
import net.minecraft.client.gui.components.toasts.ToastManager;
8+
import net.minecraft.client.gui.components.toasts.ToastComponent;
99
import net.minecraft.client.renderer.RenderType;
1010
import net.minecraft.network.chat.Component;
1111
import net.minecraft.resources.ResourceLocation;
@@ -14,7 +14,6 @@
1414

1515
public class BaseToast implements Toast {
1616
private long firstRender;
17-
private Visibility visibility;
1817

1918
protected Component title;
2019
protected Component description;
@@ -28,47 +27,31 @@ protected BaseToast(Component title, Component description, @Nullable ResourceLo
2827
this.description = description;
2928

3029
this.icon = icon;
31-
32-
this.visibility = Visibility.SHOW;
33-
}
34-
35-
@Override
36-
public @NotNull Visibility getWantedVisibility() {
37-
return this.visibility;
38-
}
39-
40-
@Override
41-
public void update(ToastManager toastManager, long currentTime) {
42-
if (this.firstRender == 0) {
43-
return;
44-
}
45-
46-
if (currentTime - this.firstRender >= 5000.0 * toastManager.getNotificationDisplayTimeMultiplier()) {
47-
this.visibility = Visibility.HIDE;
48-
}
4930
}
5031

5132
@Override
52-
public void render(GuiGraphics graphics, Font font, long currentTime) {
33+
public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) {
5334
if (this.firstRender == 0) {
5435
this.onFirstRender();
5536
this.firstRender = currentTime;
5637
}
5738

58-
// type, resource, x, y, ?, ?, width, height, width, height
59-
graphics.blit(RenderType::guiTextured, BACKGROUND_IMAGE, 0, 0, 0.0f, 0, this.width(), this.height(), this.width(), this.height());
39+
// resource, x, y, z, ?, ?, width, height, width, height
40+
graphics.blit(BACKGROUND_IMAGE, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
6041

6142
int x = 8;
6243

6344
if (this.icon != null) {
6445
x += 22;
6546

66-
graphics.blit(RenderType::guiTextured, MOD_ICON, 2, 2, 0.0f, 0, 8, 8, 8, 8);
67-
graphics.blit(RenderType::guiTextured, this.icon, 8, 8, 0.0f, 0, 16, 16, 16, 16);
47+
graphics.blit(MOD_ICON, 2, 2, 0.0f, 0.0f, 8, 8, 8, 8);
48+
graphics.blit(this.icon, 8, 8, 0.0f, 0.0f, 16, 16, 16, 16);
6849
}
6950

70-
graphics.drawString(Minecraft.getInstance().font, this.title, x, 7, 0x5f3315, false);
71-
graphics.drawString(Minecraft.getInstance().font, this.description, x, 18, -16777216, false);
51+
graphics.drawString(toastComponent.getMinecraft().font, this.title, x, 7, 0x5f3315, false);
52+
graphics.drawString(toastComponent.getMinecraft().font, this.description, x, 18, -16777216, false);
53+
54+
return currentTime - this.firstRender >= 5000.0 * toastComponent.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
7255
}
7356

7457
public void onFirstRender() {}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void queueToast(Component title, ResourceLocation icon) {
2222
queuedToast.icon = icon;
2323
} else {
2424
queuedToast = new BatteryToast(title, icon);
25-
Minecraft.getInstance().getToastManager().addToast(queuedToast);
25+
Minecraft.getInstance().getToasts().addToast(queuedToast);
2626
}
2727
}
2828

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private static void updateBatteries() {
143143
updateState();
144144

145145
try {
146-
Thread.sleep(updateInterval);
146+
Thread.sleep(updateInterval.toMillis());
147147
} catch (InterruptedException e) {
148148
active = false;
149149
Thread.currentThread().interrupt();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ private ErrorToast(Component description) {
1616
*/
1717
public static void queueToast(Component description) {
1818
ErrorToast toast = new ErrorToast(description);
19-
Minecraft.getInstance().getToastManager().addToast(toast);
19+
Minecraft.getInstance().getToasts().addToast(toast);
2020
}
2121
}

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

-101
This file was deleted.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class GameRendererMixin {
2828
)
2929
)
3030
private boolean skipRendering(boolean original) {
31-
return original || !DynamicFPSMod.renderedCurrentFrame();
31+
return original || !DynamicFPSMod.checkForRender();
3232
}
3333

3434
/**

0 commit comments

Comments
 (0)