Skip to content

Commit a4c1fdf

Browse files
committed
Minecraft 1.16.5 backport
1 parent ecd7fd0 commit a4c1fdf

Some content is hidden

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

51 files changed

+611
-166
lines changed

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

Lines changed: 2 additions & 2 deletions
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(8)
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(8)
1818
}
1919
}

gradle.properties

Lines changed: 4 additions & 4 deletions
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.0
13+
minecraft_version = 1.16.4
1414
# Version for publishing
15-
minecraft_version_min = 1.21
16-
minecraft_version_max = 1.21
15+
minecraft_version_min = 1.16.4
16+
minecraft_version_max = 1.16.5
1717

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

gradle/libs.versions.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[versions]
2-
minecraft = "1.21"
2+
minecraft = "1.16.5"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.100.1+1.21"
7+
fabric_api = "0.29.4+1.16"
88

9-
forge = "1.20.4-49.0.30"
9+
forge = "1.16.5-36.2.41"
1010

11-
neoforge = "21.0.0-beta"
11+
neoforge = "20.4.160-beta"
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 = "1.16.23"
22+
cloth_config = "4.17.101"
2323

2424
mixinextras = "0.3.5"
2525

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import dynamic_fps.impl.util.FallbackConfigScreen;
1515
import dynamic_fps.impl.util.Logging;
1616
import dynamic_fps.impl.feature.state.OptionHolder;
17+
import dynamic_fps.impl.util.ModCompatHelper;
1718
import dynamic_fps.impl.util.ResourceLocations;
1819
import dynamic_fps.impl.util.Version;
1920
import dynamic_fps.impl.feature.volume.SmoothVolumeHandler;
2021
import dynamic_fps.impl.util.duck.DuckLoadingOverlay;
2122
import dynamic_fps.impl.feature.state.WindowObserver;
2223
import dynamic_fps.impl.service.Platform;
24+
import dynamic_fps.impl.util.duck.DuckScreen;
2325
import net.lostluma.battery.api.State;
2426
import net.minecraft.Util;
2527
import net.minecraft.client.Minecraft;
@@ -63,7 +65,7 @@ public static void init() {
6365
doInit();
6466

6567
Platform platform = Platform.getInstance();
66-
Version version = platform.getModVersion(Constants.MOD_ID).orElseThrow();
68+
Version version = platform.getModVersion(Constants.MOD_ID).orElseThrow(RuntimeException::new);
6769

6870
Logging.getLogger().info("Dynamic FPS {} active on {}!", version, platform.getName());
6971
}
@@ -174,7 +176,7 @@ public static boolean shouldShowToasts() {
174176
}
175177

176178
public static boolean shouldShowLevels() {
177-
return isDisabled() || !isLevelCoveredByOverlay();
179+
return isDisabled() || !(isLevelCoveredByScreen() || isLevelCoveredByOverlay());
178180
}
179181

180182
public static void onBatteryChargeChanged(int before, int after) {
@@ -196,11 +198,17 @@ public static void onBatteryStatusChanged(State before, State after) {
196198
private static void doInit() {
197199
// NOTE: Init battery tracker first here
198200
// Since the idle handler queries it for info
201+
ModCompatHelper.init();
202+
199203
BatteryTracker.init();
200204
IdleHandler.init();
201205
SmoothVolumeHandler.init();
202206
}
203207

208+
private static boolean isLevelCoveredByScreen() {
209+
return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground();
210+
}
211+
204212
private static void showNotification(String titleTranslationKey, String iconPath) {
205213
if (!DynamicFPSConfig.INSTANCE.batteryTracker().notifications()) {
206214
return;
@@ -243,7 +251,7 @@ public static void handleStateChange(PowerState previous, PowerState current) {
243251
}
244252

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

248256
if (enableVsync != before.enableVsync()) {
249257
minecraft.getWindow().updateVsync(enableVsync);

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import net.minecraft.client.gui.screens.Screen;
2020
import net.minecraft.network.chat.CommonComponents;
2121
import net.minecraft.network.chat.Component;
22+
import net.minecraft.network.chat.TextComponent;
23+
import net.minecraft.network.chat.TranslatableComponent;
2224
import net.minecraft.sounds.SoundSource;
2325

2426
import java.util.Locale;
@@ -64,7 +66,7 @@ public static Screen genConfigScreen(Screen parent) {
6466
);
6567

6668
general.addEntry(
67-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
69+
entryBuilder.startTextDescription(new TextComponent(" ")).build()
6870
);
6971

7072
general.addEntry(
@@ -93,7 +95,7 @@ public static Screen genConfigScreen(Screen parent) {
9395
);
9496

9597
general.addEntry(
96-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
98+
entryBuilder.startTextDescription(new TextComponent(" ")).build()
9799
);
98100

99101
VariableStepTransformer volumeTransformer = getVolumeStepTransformer();
@@ -125,7 +127,7 @@ public static Screen genConfigScreen(Screen parent) {
125127
);
126128

127129
general.addEntry(
128-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
130+
entryBuilder.startTextDescription(new TextComponent(" ")).build()
129131
);
130132

131133
BatteryTrackerConfig batteryTracker = config.batteryTracker();
@@ -219,7 +221,7 @@ public static Screen genConfigScreen(Screen parent) {
219221

220222
category.addEntry(
221223
entryBuilder.startBooleanToggle(
222-
Component.translatable("options.vsync"),
224+
new TranslatableComponent("options.vsync"),
223225
instance.enableVsync()
224226
)
225227
.setDefaultValue(standard.enableVsync())
@@ -239,7 +241,7 @@ public static Screen genConfigScreen(Screen parent) {
239241

240242
volumes.add(
241243
entryBuilder.startIntSlider(
242-
Component.translatable("soundCategory." + name),
244+
new TranslatableComponent("soundCategory." + name),
243245
(int) (instance.rawVolumeMultiplier(source) * 100),
244246
0, 100
245247
)
@@ -261,7 +263,7 @@ public static Screen genConfigScreen(Screen parent) {
261263
.setDefaultValue(standard.graphicsState())
262264
.setSaveConsumer(instance::setGraphicsState)
263265
.setEnumNameProvider(ClothConfig::graphicsStateMessage)
264-
.setTooltipSupplier(ClothConfig::graphicsStateTooltip)
266+
.setTooltipSupplier(value -> graphicsStateTooltip((GraphicsState) value))
265267
.build()
266268
);
267269

@@ -335,7 +337,7 @@ private static Component volumeTransitionMessage(int step) {
335337
int value = getVolumeStepTransformer().toValue(step);
336338

337339
if (value <= 300) {
338-
return Component.literal(value + "%");
340+
return new TranslatableComponent(value + "%");
339341
} else {
340342
return localized("config", "volume_transition_speed_instant");
341343
}
@@ -357,14 +359,14 @@ private static Component fpsTargetMessage(int step) {
357359
int fps = getFpsTransformer().toValue(step);
358360

359361
if (fps != Constants.NO_FRAME_RATE_LIMIT) {
360-
return Component.translatable("options.framerate", fps);
362+
return new TranslatableComponent("options.framerate", fps);
361363
} else {
362-
return Component.translatable("options.framerateLimit.max");
364+
return new TranslatableComponent("options.framerateLimit.max");
363365
}
364366
}
365367

366368
private static Component volumeMultiplierMessage(int value) {
367-
return Component.literal(Integer.toString(value) + "%");
369+
return new TranslatableComponent(Integer.toString(value) + "%");
368370
}
369371

370372
public static Component IdleConditionMessage(Enum<IdleCondition> state) {

platforms/common/src/main/java/dynamic_fps/impl/config/Serialization.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public static DynamicFPSConfig loadDefault() {
142142
throw new IOException("Stream is null.");
143143
}
144144

145-
data = stream.readAllBytes();
145+
data = new byte[stream.available()];
146+
stream.read(data, 0, stream.available());
146147
} catch (IOException e) {
147148
throw new RuntimeException("Failed to load Dynamic FPS config.", e);
148149
}
Lines changed: 8 additions & 8 deletions
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/feature/battery/BatteryToast.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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.GuiGraphics;
7+
import net.minecraft.client.gui.GuiComponent;
68
import net.minecraft.client.gui.components.toasts.Toast;
79
import net.minecraft.client.gui.components.toasts.ToastComponent;
810
import net.minecraft.network.chat.Component;
@@ -20,6 +22,8 @@ public class BatteryToast implements Toast {
2022

2123
private static BatteryToast queuedToast;
2224

25+
private static final Minecraft MINECRAFT = Minecraft.getInstance();
26+
2327
private static final ResourceLocation MOD_ICON = ResourceLocations.of("dynamic_fps", "textures/battery/toast/background_icon.png");
2428
private static final ResourceLocation BACKGROUND_IMAGE = ResourceLocations.of("dynamic_fps", "textures/battery/toast/background.png");
2529

@@ -43,7 +47,7 @@ public static void queueToast(Component title, ResourceLocation icon) {
4347
}
4448

4549
@Override
46-
public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) {
50+
public @NotNull Visibility render(PoseStack poseStack, ToastComponent toastComponent, long currentTime) {
4751
if (this.firstRender == 0) {
4852
if (this == queuedToast) {
4953
queuedToast = null;
@@ -54,15 +58,18 @@ public static void queueToast(Component title, ResourceLocation icon) {
5458
this.description = localized("toast", "battery_charge", BatteryTracker.charge());
5559
}
5660

61+
MINECRAFT.getTextureManager().bind(BACKGROUND_IMAGE);
5762
// resource, x, y, z, ?, ?, width, height, width, height
58-
graphics.blit(BACKGROUND_IMAGE, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
63+
GuiComponent.blit(poseStack, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
5964

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);
65+
MINECRAFT.getTextureManager().bind(MOD_ICON);
66+
GuiComponent.blit(poseStack, 2, 2, 0, 0.0f, 0.0f, 8, 8, 8, 8);
67+
MINECRAFT.getTextureManager().bind(this.icon);
68+
GuiComponent.blit(poseStack, 8, 8, 0, 0.0f, 0.0f, 16, 16, 16, 16);
6269

63-
graphics.drawString(toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315, false);
64-
graphics.drawString(toastComponent.getMinecraft().font, this.description, 30, 18, -16777216, false);
70+
GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315);
71+
GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.description, 30, 18, -16777216);
6572

66-
return currentTime - this.firstRender >= 5000.0 * toastComponent.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
73+
return currentTime - this.firstRender >= 5000.0 ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
6774
}
6875
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static void init() {
5858
}
5959
} else {
6060
manager = temp; // Keep around to allow updating batteries
61-
Thread.ofVirtual().name("refresh-battery").start(BatteryTracker::updateBatteries);
61+
new Thread(BatteryTracker::updateBatteries, "refresh-battery").start();
6262
}
6363
}
6464

@@ -127,7 +127,7 @@ private static void updateBatteries() {
127127
updateState();
128128

129129
try {
130-
Thread.sleep(updateInterval);
130+
Thread.sleep(updateInterval.toMillis());
131131
} catch (InterruptedException e) {
132132
active = false;
133133
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)