Skip to content

Commit 0c16723

Browse files
committed
Minecraft 1.16.5 backport
1 parent df610e4 commit 0c16723

File tree

59 files changed

+707
-174
lines changed

Some content is hidden

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

59 files changed

+707
-174
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ subprojects {
5454
withSourcesJar()
5555

5656
toolchain {
57-
languageVersion = JavaLanguageVersion.of(21)
57+
languageVersion = JavaLanguageVersion.of(8)
5858
}
5959
}
6060

6161
tasks.withType(JavaCompile).configureEach {
6262
it.options.encoding = "UTF-8"
6363

6464
javaCompiler = javaToolchains.compilerFor {
65-
languageVersion = JavaLanguageVersion.of(21)
65+
languageVersion = JavaLanguageVersion.of(8)
6666
}
6767
}
6868
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ org.gradle.jvmargs = -Xmx3G
44

55
# Mod Properties
66
mod_version = 3.5.0
7-
minecraft_version_min = 1.21.0
7+
minecraft_version_min = 1.16.4
88

99
maven_group = juliand665
1010
archives_base_name = dynamic-fps
1111

12-
enabled_platforms=fabric,neoforge
12+
enabled_platforms=fabric
1313
# enabled_platforms=fabric,forge,neoforge,quilt

gradle/libs.versions.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
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"
14-
quilt_standard_libraries = "8.0.0-alpha.12+1.20.4"
14+
quilt_standard_libraries = "1.1.0-beta.26+1.18.2"
1515

1616
# Regular libraries
1717

18-
battery = "1.0.0"
18+
battery = "1.0.1"
1919

2020
# Modding libraries
2121

22-
modmenu = "11.0.0-beta.1"
23-
cloth_config = "15.0.127"
22+
modmenu = "1.16.23"
23+
cloth_config = "4.17.101"
2424

2525
mixinextras = "0.3.5"
2626

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

+10-2
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
}
@@ -170,7 +172,7 @@ public static boolean shouldShowToasts() {
170172
}
171173

172174
public static boolean shouldShowLevels() {
173-
return isDisabled() || !isLevelCoveredByOverlay();
175+
return isDisabled() || !(isLevelCoveredByScreen() || isLevelCoveredByOverlay());
174176
}
175177

176178
public static void onBatteryChargeChanged(int before, int after) {
@@ -192,11 +194,17 @@ public static void onBatteryStatusChanged(State before, State after) {
192194
private static void doInit() {
193195
// NOTE: Init battery tracker first here
194196
// Since the idle handler queries it for info
197+
ModCompatHelper.init();
198+
195199
BatteryTracker.init();
196200
IdleHandler.init();
197201
SmoothVolumeHandler.init();
198202
}
199203

204+
private static boolean isLevelCoveredByScreen() {
205+
return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground();
206+
}
207+
200208
private static void showNotification(String titleTranslationKey, String iconPath) {
201209
if (!DynamicFPSConfig.INSTANCE.batteryTracker().notifications()) {
202210
return;

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

+11-9
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();
@@ -229,7 +231,7 @@ public static Screen genConfigScreen(Screen parent) {
229231

230232
volumes.add(
231233
entryBuilder.startIntSlider(
232-
Component.translatable("soundCategory." + name),
234+
new TranslatableComponent("soundCategory." + name),
233235
(int) (instance.rawVolumeMultiplier(source) * 100),
234236
0, 100
235237
)
@@ -251,7 +253,7 @@ public static Screen genConfigScreen(Screen parent) {
251253
.setDefaultValue(standard.graphicsState())
252254
.setSaveConsumer(instance::setGraphicsState)
253255
.setEnumNameProvider(ClothConfig::graphicsStateMessage)
254-
.setTooltipSupplier(ClothConfig::graphicsStateTooltip)
256+
.setTooltipSupplier(value -> graphicsStateTooltip((GraphicsState) value))
255257
.build()
256258
);
257259

@@ -325,7 +327,7 @@ private static Component volumeTransitionMessage(int step) {
325327
int value = getVolumeStepTransformer().toValue(step);
326328

327329
if (value <= 300) {
328-
return Component.literal(value + "%");
330+
return new TranslatableComponent(value + "%");
329331
} else {
330332
return localized("config", "volume_transition_speed_instant");
331333
}
@@ -347,14 +349,14 @@ private static Component fpsTargetMessage(int step) {
347349
int fps = getFpsTransformer().toValue(step);
348350

349351
if (fps != Constants.NO_FRAME_RATE_LIMIT) {
350-
return Component.translatable("options.framerate", fps);
352+
return new TranslatableComponent("options.framerate", fps);
351353
} else {
352-
return Component.translatable("options.framerateLimit.max");
354+
return new TranslatableComponent("options.framerateLimit.max");
353355
}
354356
}
355357

356358
private static Component volumeMultiplierMessage(int value) {
357-
return Component.literal(Integer.toString(value) + "%");
359+
return new TranslatableComponent(Integer.toString(value) + "%");
358360
}
359361

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

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static JsonObject removeUnchangedFields(JsonObject config, JsonObject pa
8585
removeUnchangedFields((JsonObject) value, (JsonObject) other);
8686
}
8787

88-
if (value.equals(other) || (value.isJsonObject() && value.getAsJsonObject().isEmpty())) {
88+
if (value.equals(other) || (value.isJsonObject() && value.getAsJsonObject().size() == 0)) {
8989
config.remove(name);
9090
}
9191
});
@@ -129,7 +129,8 @@ public static DynamicFPSConfig loadDefault() {
129129
throw new IOException("Stream is null.");
130130
}
131131

132-
data = stream.readAllBytes();
132+
data = new byte[stream.available()];
133+
stream.read(data, 0, stream.available());
133134
} catch (IOException e) {
134135
throw new RuntimeException("Failed to load Dynamic FPS config.", e);
135136
}
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

+15-8
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

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

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.lostluma.battery.api.State;
99
import net.minecraft.Util;
1010
import net.minecraft.client.Minecraft;
11+
import net.minecraft.world.entity.player.Player;
1112
import net.minecraft.world.phys.Vec3;
1213
import org.jetbrains.annotations.Nullable;
1314
import org.lwjgl.glfw.GLFW;
@@ -93,14 +94,14 @@ private static void checkActivity() {
9394
}
9495

9596
private static void checkPlayerActivity() {
96-
var player = Minecraft.getInstance().player;
97+
Player player = Minecraft.getInstance().player;
9798

9899
if (player == null) {
99100
return;
100101
}
101102

102-
var position = player.position();
103-
var lookAngle = player.getLookAngle();
103+
Vec3 position = player.position();
104+
Vec3 lookAngle = player.getLookAngle();
104105

105106
if (!position.equals(prevPosition) || !lookAngle.equals(prevLookAngle)) {
106107
onActivity();

0 commit comments

Comments
 (0)