Skip to content

Commit ffb459a

Browse files
committed
Minecraft 1.19.3 backport
1 parent d3de26b commit ffb459a

File tree

37 files changed

+494
-87
lines changed

37 files changed

+494
-87
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.0
13+
minecraft_version = 1.19.3
1414
# Version for publishing
15-
minecraft_version_min = 1.21
16-
minecraft_version_max = 1.21
15+
minecraft_version_min = 1.19.3
16+
minecraft_version_max = 1.19.3
1717

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

gradle/libs.versions.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
[versions]
2-
minecraft = "1.21"
2+
minecraft = "1.19.3"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.100.1+1.21"
7+
fabric_api = "0.76.1+1.19.3"
88

9-
forge = "1.20.4-49.0.30"
9+
forge = "1.19.3-44.1.23"
1010

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

1313
quilt_loader = "0.25.0"
14-
quilt_standard_libraries = "8.0.0-alpha.12+1.20.4"
14+
quilt_standard_libraries = "4.0.0-beta.13+1.19.3"
1515

1616
# Regular libraries
1717

1818
battery = "1.1.0"
1919

2020
# Modding libraries
2121

22-
modmenu = "11.0.0-beta.1"
23-
cloth_config = "15.0.127"
22+
modmenu = "5.1.0"
23+
cloth_config = "9.1.104"
2424

2525
mixinextras = "0.3.5"
2626

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

+9-1
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;
@@ -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;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static Screen genConfigScreen(Screen parent) {
6464
);
6565

6666
general.addEntry(
67-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
67+
entryBuilder.startTextDescription(Component.literal(" ")).build()
6868
);
6969

7070
general.addEntry(
@@ -93,7 +93,7 @@ public static Screen genConfigScreen(Screen parent) {
9393
);
9494

9595
general.addEntry(
96-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
96+
entryBuilder.startTextDescription(Component.literal(" ")).build()
9797
);
9898

9999
VariableStepTransformer volumeTransformer = getVolumeStepTransformer();
@@ -125,7 +125,7 @@ public static Screen genConfigScreen(Screen parent) {
125125
);
126126

127127
general.addEntry(
128-
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
128+
entryBuilder.startTextDescription(Component.literal(" ")).build()
129129
);
130130

131131
BatteryTrackerConfig batteryTracker = config.batteryTracker();
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

+13-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;
@@ -43,7 +45,7 @@ public static void queueToast(Component title, ResourceLocation icon) {
4345
}
4446

4547
@Override
46-
public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) {
48+
public @NotNull Visibility render(PoseStack poseStack, ToastComponent toastComponent, long currentTime) {
4749
if (this.firstRender == 0) {
4850
if (this == queuedToast) {
4951
queuedToast = null;
@@ -54,15 +56,18 @@ public static void queueToast(Component title, ResourceLocation icon) {
5456
this.description = localized("toast", "battery_charge", BatteryTracker.charge());
5557
}
5658

59+
RenderSystem.setShaderTexture(0, BACKGROUND_IMAGE);
5760
// 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());
61+
GuiComponent.blit(poseStack, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
5962

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

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

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

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();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package dynamic_fps.impl.mixin;
2+
3+
import dynamic_fps.impl.service.ModCompat;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.Unique;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
import dynamic_fps.impl.util.duck.DuckScreen;
11+
import net.minecraft.client.gui.screens.Screen;
12+
13+
@Mixin(Screen.class)
14+
public class ScreenMixin implements DuckScreen {
15+
@Unique
16+
private boolean dynamic_fps$canOptimize = false;
17+
18+
@Unique
19+
private boolean dynamic_fps$hasOptedOut = false;
20+
21+
@Override
22+
public boolean dynamic_fps$rendersBackground() {
23+
return dynamic_fps$canOptimize;
24+
}
25+
26+
@Override
27+
public void dynamic_fps$setRendersBackground() {
28+
this.dynamic_fps$canOptimize = true;
29+
}
30+
31+
@Inject(method = "init", at = @At("HEAD"))
32+
private void onInit(CallbackInfo callbackInfo) {
33+
String name = this.getClass().getName();
34+
35+
this.dynamic_fps$hasOptedOut = ModCompat.getInstance().isScreenOptedOut(name);
36+
37+
// Allow other mods to opt out on behalf of vanilla screens
38+
// That Dynamic FPS forced to opt in via its own mod metadata.
39+
if (!this.dynamic_fps$hasOptedOut) {
40+
this.dynamic_fps$canOptimize = ModCompat.getInstance().isScreenOptedIn(name);
41+
}
42+
}
43+
44+
@Inject(method = "renderDirtBackground", at = @At("HEAD"))
45+
private void onRenderDirtBackground(CallbackInfo callbackInfo) {
46+
if (!this.dynamic_fps$hasOptedOut) {
47+
this.dynamic_fps$canOptimize = true; // Signal to apply optimizations on next frame
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dynamic_fps.impl.mixin;
2+
3+
import dynamic_fps.impl.util.duck.DuckScreen;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.injection.At;
6+
import org.spongepowered.asm.mixin.injection.Inject;
7+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
8+
9+
import net.minecraft.client.gui.screens.achievement.StatsScreen;
10+
11+
@Mixin(StatsScreen.class)
12+
public class StatsScreenMixin {
13+
@Inject(method = "onStatsUpdated", at = @At("HEAD"))
14+
private void onStatsUpdated(CallbackInfo callbackInfo) {
15+
((DuckScreen) this).dynamic_fps$setRendersBackground();
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package dynamic_fps.impl.mixin;
22

3+
import java.util.Deque;
4+
35
import org.spongepowered.asm.mixin.Mixin;
46
import org.spongepowered.asm.mixin.injection.At;
5-
import org.spongepowered.asm.mixin.injection.Inject;
6-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
7+
import org.spongepowered.asm.mixin.injection.Redirect;
78

89
import dynamic_fps.impl.DynamicFPSMod;
10+
import net.minecraft.client.gui.components.toasts.Toast;
911
import net.minecraft.client.gui.components.toasts.ToastComponent;
1012

1113
@Mixin(ToastComponent.class)
1214
public class ToastComponentMixin {
13-
@Inject(method = "freeSlots", at = @At("HEAD"), cancellable = true)
14-
private void hasFreeSlots(CallbackInfoReturnable<Integer> callbackInfo) {
15+
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Ljava/util/Deque;isEmpty()Z"))
16+
private boolean onQueueIsEmpty(Deque<Toast> queued) {
1517
if (!DynamicFPSMod.shouldShowToasts()) {
16-
callbackInfo.setReturnValue(0);
18+
return true;
19+
} else {
20+
return queued.isEmpty();
1721
}
1822
}
1923
}

platforms/common/src/main/java/dynamic_fps/impl/service/ModCompat.java

+13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
package dynamic_fps.impl.service;
22

3+
import java.util.Set;
4+
35
public interface ModCompat {
46
boolean isDisabled();
57

68
boolean disableOverlayOptimization();
79

10+
Set<String> getOptedInScreens();
11+
Set<String> getOptedOutScreens();
12+
13+
default boolean isScreenOptedIn(String className) {
14+
return getOptedInScreens().contains(className);
15+
}
16+
17+
default boolean isScreenOptedOut(String className) {
18+
return getOptedOutScreens().contains(className);
19+
}
20+
821
static ModCompat getInstance() {
922
return Services.MOD_COMPAT;
1023
}

platforms/common/src/main/java/dynamic_fps/impl/util/FallbackConfigScreen.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dynamic_fps.impl.util;
22

3+
import com.mojang.blaze3d.vertex.PoseStack;
34
import net.minecraft.client.Minecraft;
4-
import net.minecraft.client.gui.GuiGraphics;
55
import net.minecraft.client.gui.components.Button;
66
import net.minecraft.client.gui.screens.Screen;
77
import net.minecraft.network.chat.CommonComponents;
@@ -32,14 +32,15 @@ protected void init() {
3232
}
3333

3434
@Override
35-
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
36-
super.render(guiGraphics, mouseX, mouseY, partialTicks);
35+
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {
36+
this.renderDirtBackground(0);
37+
super.render(poseStack, mouseX, mouseY, partialTicks);
3738

38-
int width = guiGraphics.guiWidth() / 2;
39-
int height = guiGraphics.guiHeight() / 3;
39+
int width = this.width / 2;
40+
int height = this.height / 3;
4041

41-
guiGraphics.drawCenteredString(this.font, WARNING_0.getVisualOrderText(), width, height, 0xFFFFFF);
42-
guiGraphics.drawCenteredString(this.font, WARNING_1.getVisualOrderText(), width, height + 10, 0xFFFFFF);
42+
drawCenteredString(poseStack, this.font, WARNING_0.getVisualOrderText(), width, height, 0xFFFFFF);
43+
drawCenteredString(poseStack, this.font, WARNING_1.getVisualOrderText(), width, height + 10, 0xFFFFFF);
4344
}
4445

4546
@Override

0 commit comments

Comments
 (0)