Skip to content

Commit f23fd25

Browse files
committed
Minecraft 1.17.0 backport
1 parent 403ef0a commit f23fd25

Some content is hidden

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

47 files changed

+650
-312
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(16)
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(16)
1818
}
1919
}

gradle.properties

+3-3
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.17.0
1414
# Version for publishing
15-
minecraft_version_min = 24w33a
16-
minecraft_version_max = 24w34a
15+
minecraft_version_min = 1.17
16+
minecraft_version_max = 1.17.1
1717

1818
enabled_platforms=fabric,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.17.1"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.102.2+1.21.2"
7+
fabric_api = "0.46.1+1.17"
88

9-
forge = "1.21-51.0.33"
9+
forge = "1.18.2-40.2.17"
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 = "2.0.17"
22+
cloth_config = "5.3.63"
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;
@@ -247,7 +250,7 @@ public static void handleStateChange(PowerState previous, PowerState current) {
247250
}
248251

249252
// The FOCUSED config doesn't have the user's actual vsync preference sadly ...
250-
boolean enableVsync = current != PowerState.FOCUSED ? config.enableVsync() : minecraft.options.enableVsync().get();
253+
boolean enableVsync = current != PowerState.FOCUSED ? config.enableVsync() : minecraft.options.enableVsync;
251254

252255
if (enableVsync != before.enableVsync()) {
253256
minecraft.getWindow().updateVsync(enableVsync);

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
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;
21+
import net.minecraft.network.chat.TextComponent;
22+
import net.minecraft.network.chat.TranslatableComponent;
2223
import net.minecraft.sounds.SoundSource;
2324

2425
import java.util.Locale;
@@ -64,7 +65,7 @@ public static Screen genConfigScreen(Screen parent) {
6465
);
6566

6667
general.addEntry(
67-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
68+
entryBuilder.startTextDescription(new TextComponent(" ")).build()
6869
);
6970

7071
general.addEntry(
@@ -94,7 +95,7 @@ public static Screen genConfigScreen(Screen parent) {
9495
);
9596

9697
general.addEntry(
97-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
98+
entryBuilder.startTextDescription(new TextComponent(" ")).build()
9899
);
99100

100101
VariableStepTransformer volumeTransformer = getVolumeStepTransformer();
@@ -126,7 +127,7 @@ public static Screen genConfigScreen(Screen parent) {
126127
);
127128

128129
general.addEntry(
129-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
130+
entryBuilder.startTextDescription(new TextComponent(" ")).build()
130131
);
131132

132133
BatteryTrackerConfig batteryTracker = config.batteryTracker();
@@ -220,7 +221,7 @@ public static Screen genConfigScreen(Screen parent) {
220221

221222
category.addEntry(
222223
entryBuilder.startBooleanToggle(
223-
Component.translatable("options.vsync"),
224+
new TranslatableComponent("options.vsync"),
224225
instance.enableVsync()
225226
)
226227
.setDefaultValue(standard.enableVsync())
@@ -240,7 +241,7 @@ public static Screen genConfigScreen(Screen parent) {
240241

241242
volumes.add(
242243
entryBuilder.startIntSlider(
243-
Component.translatable("soundCategory." + name),
244+
new TranslatableComponent("soundCategory." + name),
244245
(int) (instance.rawVolumeMultiplier(source) * 100),
245246
0, 100
246247
)
@@ -346,7 +347,7 @@ private static Component volumeTransitionMessage(int step) {
346347
int value = getVolumeStepTransformer().toValue(step);
347348

348349
if (value <= 300) {
349-
return Component.literal(value + "%");
350+
return new TextComponent(value + "%");
350351
} else {
351352
return localized("config", "volume_transition_speed_instant");
352353
}
@@ -368,14 +369,14 @@ private static Component fpsTargetMessage(int step) {
368369
int fps = getFpsTransformer().toValue(step);
369370

370371
if (fps != Constants.NO_FRAME_RATE_LIMIT) {
371-
return Component.translatable("options.framerate", fps);
372+
return new TranslatableComponent("options.framerate", fps);
372373
} else {
373-
return Component.translatable("options.framerateLimit.max");
374+
return new TranslatableComponent("options.framerateLimit.max");
374375
}
375376
}
376377

377378
private static Component volumeMultiplierMessage(int value) {
378-
return Component.literal(Integer.toString(value) + "%");
379+
return new TextComponent(Integer.toString(value) + "%");
379380
}
380381

381382
public static Component IdleConditionMessage(Enum<IdleCondition> state) {
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
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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;
@@ -19,7 +19,6 @@ public class BatteryToast implements Toast {
1919
private Component title;
2020
private Component description;
2121
private ResourceLocation icon;
22-
private Visibility visibility;
2322

2423
private static BatteryToast queuedToast;
2524

@@ -29,7 +28,6 @@ public class BatteryToast implements Toast {
2928
private BatteryToast(Component title, ResourceLocation icon) {
3029
this.title = title;
3130
this.icon = icon;
32-
this.visibility = Visibility.SHOW;
3331
}
3432

3533
/**
@@ -42,28 +40,12 @@ public static void queueToast(Component title, ResourceLocation icon) {
4240
queuedToast.icon = icon;
4341
} else {
4442
queuedToast = new BatteryToast(title, icon);
45-
Minecraft.getInstance().getToastManager().addToast(queuedToast);
43+
Minecraft.getInstance().getToasts().addToast(queuedToast);
4644
}
4745
}
4846

4947
@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) {
48+
public @NotNull Visibility render(PoseStack poseStack, ToastComponent toastComponent, long currentTime) {
6749
if (this.firstRender == 0) {
6850
if (this == queuedToast) {
6951
queuedToast = null;
@@ -74,13 +56,18 @@ public void render(GuiGraphics graphics, Font font, long currentTime) {
7456
this.description = localized("toast", "battery_charge", BatteryTracker.charge());
7557
}
7658

59+
RenderSystem.setShaderTexture(0, BACKGROUND_IMAGE);
7760
// 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());
61+
GuiComponent.blit(poseStack, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
62+
63+
RenderSystem.setShaderTexture(0, MOD_ICON);
64+
GuiComponent.blit(poseStack, 2, 2, 0, 0.0f, 0.0f, 8, 8, 8, 8);
65+
RenderSystem.setShaderTexture(0, this.icon);
66+
GuiComponent.blit(poseStack, 8, 8, 0, 0.0f, 0.0f, 16, 16, 16, 16);
7967

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);
68+
GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315);
69+
GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.description, 30, 18, -16777216);
8270

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

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();

0 commit comments

Comments
 (0)