Skip to content

Commit 46050a6

Browse files
committed
Minecraft 1.19.3 backport
Signed-off-by: Lilly Rose Berner <lilly@lostluma.net>
1 parent c59f71e commit 46050a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+500
-251
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
13+
minecraft_version = 1.19.3
1414
# Version for publishing
15-
minecraft_version_min = 1.21.2
16-
minecraft_version_max = 1.21.4
15+
minecraft_version_min = 1.19.3
16+
minecraft_version_max = 1.19.3
1717

18-
enabled_platforms=fabric,forge,neoforge,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 = "1.21.3"
2+
minecraft = "1.19.3"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.102.2+1.21.2"
7+
fabric_api = "0.76.1+1.19.3"
88

9-
forge = "1.21.3-53.0.7"
9+
forge = "1.19.3-44.1.23"
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 = "5.1.0"
22+
cloth_config = "9.1.104"
2323

2424
mixinextras = "0.3.5"
2525

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

+10-7
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;
@@ -263,7 +266,7 @@ private static void checkForStateChanges() {
263266
checkForStateChanges0();
264267
} else {
265268
// Schedule check for the beginning of the next frame
266-
minecraft.schedule(DynamicFPSMod::checkForStateChanges0);
269+
minecraft.tell(DynamicFPSMod::checkForStateChanges0);
267270
}
268271
}
269272

platforms/common/src/main/java/dynamic_fps/impl/compat/ClothConfig.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder;
1818
import net.minecraft.ChatFormatting;
1919
import net.minecraft.client.gui.screens.Screen;
20-
import net.minecraft.network.chat.CommonComponents;
2120
import net.minecraft.network.chat.Component;
2221
import net.minecraft.sounds.SoundSource;
2322

@@ -64,7 +63,7 @@ public static Screen genConfigScreen(Screen parent) {
6463
);
6564

6665
general.addEntry(
67-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
66+
entryBuilder.startTextDescription(Component.literal(" ")).build()
6867
);
6968

7069
general.addEntry(
@@ -94,7 +93,7 @@ public static Screen genConfigScreen(Screen parent) {
9493
);
9594

9695
general.addEntry(
97-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
96+
entryBuilder.startTextDescription(Component.literal(" ")).build()
9897
);
9998

10099
VariableStepTransformer volumeTransformer = getVolumeStepTransformer();
@@ -126,7 +125,7 @@ public static Screen genConfigScreen(Screen parent) {
126125
);
127126

128127
general.addEntry(
129-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
128+
entryBuilder.startTextDescription(Component.literal(" ")).build()
130129
);
131130

132131
BatteryTrackerConfig batteryTracker = config.batteryTracker();

platforms/common/src/main/java/dynamic_fps/impl/compat/GLFW.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void applyWorkaround() {
3131
// Agrees that the window is focused. The mod is
3232
// A little too fast for this, so we schedule it
3333
// For the next client tick (before next frame).
34-
minecraft.schedule(minecraft.mouseHandler::grabMouse);
34+
minecraft.tell(minecraft.mouseHandler::grabMouse);
3535
}
3636
}
3737

Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
package dynamic_fps.impl.config.option;
22

3-
import net.minecraft.client.gui.GuiGraphics;
3+
import com.mojang.blaze3d.platform.Window;
44

55
/**
66
* Screen corner to render the battery indicator in.
77
*/
88
public enum BatteryIndicatorPlacement {
9-
TOP_LEFT(graphics -> new int[] {4, 4}),
10-
TOP_RIGHT(graphics -> new int[] {graphics.guiWidth() - 47, 4}),
11-
BOTTOM_LEFT(graphics -> new int[] {4, graphics.guiHeight() - 20}),
12-
BOTTOM_RIGHT(graphics -> new int[] {graphics.guiWidth() - 47, graphics.guiHeight() - 20});
9+
TOP_LEFT(window -> new int[] {4, 4}),
10+
TOP_RIGHT(window -> new int[] {window.getGuiScaledWidth() - 47, 4}),
11+
BOTTOM_LEFT(window -> new int[] {4, window.getGuiScaledHeight() - 20}),
12+
BOTTOM_RIGHT(window -> new int[] {window.getGuiScaledWidth() - 47, window.getGuiScaledHeight() - 20});
1313

1414
private final DynamicPlacement placement;
1515

1616
BatteryIndicatorPlacement(DynamicPlacement placement) {
1717
this.placement = placement;
1818
}
1919

20-
public int[] get(GuiGraphics graphics) {
21-
return this.placement.get(graphics);
20+
public int[] get(Window window) {
21+
return this.placement.get(window);
2222
}
2323

2424
@FunctionalInterface
2525
private interface DynamicPlacement {
26-
int[] get(GuiGraphics graphics);
26+
int[] get(Window window);
2727
}
2828
}

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

+18-30
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
package dynamic_fps.impl.feature.battery;
22

3+
import com.mojang.blaze3d.systems.RenderSystem;
4+
import com.mojang.blaze3d.vertex.PoseStack;
35
import dynamic_fps.impl.util.ResourceLocations;
46
import net.minecraft.client.Minecraft;
5-
import net.minecraft.client.gui.Font;
6-
import net.minecraft.client.gui.GuiGraphics;
7+
import net.minecraft.client.gui.GuiComponent;
78
import net.minecraft.client.gui.components.toasts.Toast;
8-
import net.minecraft.client.gui.components.toasts.ToastManager;
9-
import net.minecraft.client.renderer.RenderType;
9+
import net.minecraft.client.gui.components.toasts.ToastComponent;
1010
import net.minecraft.network.chat.Component;
1111
import net.minecraft.resources.ResourceLocation;
1212
import org.jetbrains.annotations.NotNull;
1313
import org.jetbrains.annotations.Nullable;
1414

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

1918
protected Component title;
2019
protected Component description;
2120
protected @Nullable ResourceLocation icon;
2221

22+
private static final Minecraft MINECRAFT = Minecraft.getInstance();
23+
2324
private static final ResourceLocation MOD_ICON = ResourceLocations.of("dynamic_fps", "textures/battery/toast/background_icon.png");
2425
private static final ResourceLocation BACKGROUND_IMAGE = ResourceLocations.of("dynamic_fps", "textures/battery/toast/background.png");
2526

@@ -28,47 +29,34 @@ protected BaseToast(Component title, Component description, @Nullable ResourceLo
2829
this.description = description;
2930

3031
this.icon = icon;
31-
32-
this.visibility = Visibility.SHOW;
3332
}
3433

3534
@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-
}
49-
}
50-
51-
@Override
52-
public void render(GuiGraphics graphics, Font font, long currentTime) {
35+
public @NotNull Visibility render(PoseStack poseStack, ToastComponent toastComponent, long currentTime) {
5336
if (this.firstRender == 0) {
5437
this.onFirstRender();
5538
this.firstRender = currentTime;
5639
}
5740

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());
41+
RenderSystem.setShaderTexture(0, BACKGROUND_IMAGE);
42+
// resource, x, y, z, ?, ?, width, height, width, height
43+
GuiComponent.blit(poseStack, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
6044

6145
int x = 8;
6246

6347
if (this.icon != null) {
6448
x += 22;
6549

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);
50+
RenderSystem.setShaderTexture(0, MOD_ICON);
51+
GuiComponent.blit(poseStack, 2, 2, 0.0f, 0.0f, 8, 8, 8, 8);
52+
RenderSystem.setShaderTexture(0, this.icon);
53+
GuiComponent.blit(poseStack, 8, 8, 0.0f, 0.0f, 16, 16, 16, 16);
6854
}
6955

70-
graphics.drawString(Minecraft.getInstance().font, this.title, x, 7, 0x5f3315, false);
71-
graphics.drawString(Minecraft.getInstance().font, this.description, x, 18, -16777216, false);
56+
MINECRAFT.font.draw(poseStack, this.title, x, 7, 0x5f3315);
57+
MINECRAFT.font.draw(poseStack, this.description, x, 17, -16777216);
58+
59+
return currentTime - this.firstRender >= 5000.0 ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
7260
}
7361

7462
public void onFirstRender() {}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dynamic_fps.impl.feature.battery;
22

33
import net.minecraft.client.Minecraft;
4+
import net.minecraft.network.chat.CommonComponents;
45
import net.minecraft.network.chat.Component;
56
import net.minecraft.resources.ResourceLocation;
67

@@ -10,7 +11,7 @@ public class BatteryToast extends BaseToast {
1011
private static BatteryToast queuedToast;
1112

1213
private BatteryToast(Component title, ResourceLocation icon) {
13-
super(title, Component.empty(), icon);
14+
super(title, CommonComponents.EMPTY, icon);
1415
}
1516

1617
/**
@@ -23,7 +24,7 @@ public static void queueToast(Component title, ResourceLocation icon) {
2324
queuedToast.icon = icon;
2425
} else {
2526
queuedToast = new BatteryToast(title, icon);
26-
Minecraft.getInstance().getToastManager().addToast(queuedToast);
27+
Minecraft.getInstance().getToasts().addToast(queuedToast);
2728
}
2829
}
2930

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static void init() {
7272
}
7373
} else {
7474
manager = temp; // Keep around to allow updating batteries
75-
Thread.ofVirtual().name("refresh-battery").start(BatteryTracker::updateBatteries);
75+
new Thread(BatteryTracker::updateBatteries, "refresh-battery").start();
7676
}
7777
}
7878

@@ -105,15 +105,15 @@ private static void updateState() {
105105
changed = true;
106106

107107
int current = charge;
108-
minecraft.schedule(() -> DynamicFPSMod.onBatteryChargeChanged(current, newCharge));
108+
minecraft.tell(() -> DynamicFPSMod.onBatteryChargeChanged(current, newCharge));
109109
}
110110

111111
if (readInitialData && status != newStatus) {
112112
changed = true;
113113

114114
State current = status;
115115
State updated = newStatus;
116-
minecraft.schedule(() -> DynamicFPSMod.onBatteryStatusChanged(current, updated));
116+
minecraft.tell(() -> DynamicFPSMod.onBatteryStatusChanged(current, updated));
117117
}
118118

119119
charge = newCharge;
@@ -141,7 +141,7 @@ private static void updateBatteries() {
141141
updateState();
142142

143143
try {
144-
Thread.sleep(updateInterval);
144+
Thread.sleep(updateInterval.toMillis());
145145
} catch (InterruptedException e) {
146146
active = false;
147147
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
@@ -17,6 +17,6 @@ private ErrorToast(Component description) {
1717
*/
1818
public static void queueToast(Component description) {
1919
ErrorToast toast = new ErrorToast(description);
20-
Minecraft.getInstance().getToastManager().addToast(toast);
20+
Minecraft.getInstance().getToasts().addToast(toast);
2121
}
2222
}

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.

0 commit comments

Comments
 (0)