Skip to content

Commit 57817fe

Browse files
committed
Minecraft 1.21.0 backport
1 parent 4849c0d commit 57817fe

File tree

17 files changed

+89
-152
lines changed

17 files changed

+89
-152
lines changed

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-alpha.24w33a
13+
minecraft_version = 1.21.0
1414
# Version for publishing
15-
minecraft_version_min = 24w33a
16-
minecraft_version_max = 24w34a
15+
minecraft_version_min = 1.21
16+
minecraft_version_max = 1.21.1
1717

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

gradle/libs.versions.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[versions]
2-
minecraft = "24w33a"
2+
minecraft = "1.21"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.102.2+1.21.2"
7+
fabric_api = "0.100.1+1.21"
88

99
forge = "1.21-51.0.33"
1010

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/BatteryToast.java

+10-28
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import dynamic_fps.impl.util.ResourceLocations;
44
import net.minecraft.client.Minecraft;
5-
import net.minecraft.client.gui.Font;
65
import net.minecraft.client.gui.GuiGraphics;
76
import net.minecraft.client.gui.components.toasts.Toast;
8-
import net.minecraft.client.gui.components.toasts.ToastManager;
9-
import net.minecraft.client.renderer.RenderType;
7+
import net.minecraft.client.gui.components.toasts.ToastComponent;
108
import net.minecraft.network.chat.Component;
119
import net.minecraft.resources.ResourceLocation;
1210
import org.jetbrains.annotations.NotNull;
@@ -19,7 +17,6 @@ public class BatteryToast implements Toast {
1917
private Component title;
2018
private Component description;
2119
private ResourceLocation icon;
22-
private Visibility visibility;
2320

2421
private static BatteryToast queuedToast;
2522

@@ -29,7 +26,6 @@ public class BatteryToast implements Toast {
2926
private BatteryToast(Component title, ResourceLocation icon) {
3027
this.title = title;
3128
this.icon = icon;
32-
this.visibility = Visibility.SHOW;
3329
}
3430

3531
/**
@@ -42,28 +38,12 @@ public static void queueToast(Component title, ResourceLocation icon) {
4238
queuedToast.icon = icon;
4339
} else {
4440
queuedToast = new BatteryToast(title, icon);
45-
Minecraft.getInstance().getToastManager().addToast(queuedToast);
41+
Minecraft.getInstance().getToasts().addToast(queuedToast);
4642
}
4743
}
4844

4945
@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) {
46+
public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) {
6747
if (this.firstRender == 0) {
6848
if (this == queuedToast) {
6949
queuedToast = null;
@@ -75,12 +55,14 @@ public void render(GuiGraphics graphics, Font font, long currentTime) {
7555
}
7656

7757
// 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());
58+
graphics.blit(BACKGROUND_IMAGE, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
59+
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);
7962

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);
63+
graphics.drawString(toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315, false);
64+
graphics.drawString(toastComponent.getMinecraft().font, this.description, 30, 18, -16777216, false);
8265

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

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.

platforms/common/src/main/java/dynamic_fps/impl/mixin/FramerateLimitTrackerMixin.java

-99
This file was deleted.

platforms/common/src/main/java/dynamic_fps/impl/mixin/MinecraftMixin.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class MinecraftMixin {
2121
@Shadow
2222
@Final
23-
private Window window;
23+
private Window window;
2424

2525
@Shadow
2626
@Final
@@ -36,4 +36,32 @@ private void setScreen(CallbackInfo callbackInfo) {
3636
IdleHandler.onActivity();
3737
}
3838

39+
/**
40+
* Conditionally bypasses the main menu frame rate limit.
41+
*
42+
* This is done in two cases:
43+
* - The window is active, and the user wants to uncap the frame rate
44+
* - The window is inactive, and the current FPS limit should be lower
45+
*/
46+
@Inject(method = "getFramerateLimit", at = @At(value = "CONSTANT", args = "intValue=60"), cancellable = true)
47+
private void getFramerateLimit(CallbackInfoReturnable<Integer> callbackInfo) {
48+
int limit = this.window.getFramerateLimit();
49+
50+
if (DynamicFPSMod.powerState() != PowerState.FOCUSED) {
51+
// Vanilla returns 60 here
52+
// Only overwrite if our current limit is lower
53+
if (limit < 60) {
54+
callbackInfo.setReturnValue(limit);
55+
}
56+
} else if (DynamicFPSConfig.INSTANCE.uncapMenuFrameRate()) {
57+
if (this.options.enableVsync().get()) {
58+
// VSync will regulate to a non-infinite value
59+
callbackInfo.setReturnValue(Constants.NO_FRAME_RATE_LIMIT);
60+
} else {
61+
// Even though the option "uncaps" the frame rate the limit is 250 FPS.
62+
// Since otherwise this will just cause coil whine with no real benefit
63+
callbackInfo.setReturnValue(Math.min(limit, Constants.NO_FRAME_RATE_LIMIT - 10));
64+
}
65+
}
66+
}
3967
}

platforms/common/src/main/java/dynamic_fps/impl/mixin/ToastManagerMixin.java platforms/common/src/main/java/dynamic_fps/impl/mixin/ToastComponentMixin.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package dynamic_fps.impl.mixin;
22

3-
import net.minecraft.client.gui.components.toasts.ToastManager;
43
import org.spongepowered.asm.mixin.Mixin;
54
import org.spongepowered.asm.mixin.injection.At;
65
import org.spongepowered.asm.mixin.injection.Inject;
76
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
87

98
import dynamic_fps.impl.DynamicFPSMod;
9+
import net.minecraft.client.gui.components.toasts.ToastComponent;
1010

11-
@Mixin(ToastManager.class)
12-
public class ToastManagerMixin {
13-
@Inject(method = "freeSlotCount", at = @At("HEAD"), cancellable = true)
14-
private void freeSlotCount(CallbackInfoReturnable<Integer> callbackInfo) {
11+
@Mixin(ToastComponent.class)
12+
public class ToastComponentMixin {
13+
@Inject(method = "freeSlots", at = @At("HEAD"), cancellable = true)
14+
private void hasFreeSlots(CallbackInfoReturnable<Integer> callbackInfo) {
1515
if (!DynamicFPSMod.shouldShowToasts()) {
1616
callbackInfo.setReturnValue(0);
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package dynamic_fps.impl.mixin;
2+
3+
import dynamic_fps.impl.PowerState;
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.CallbackInfoReturnable;
8+
9+
import com.mojang.blaze3d.platform.Window;
10+
11+
import dynamic_fps.impl.DynamicFPSMod;
12+
13+
@Mixin(Window.class)
14+
public class WindowMixin {
15+
/**
16+
* Sets a frame rate limit while we're cancelling some or all rendering.
17+
*/
18+
@Inject(method = "getFramerateLimit", at = @At("RETURN"), cancellable = true)
19+
private void onGetFramerateLimit(CallbackInfoReturnable<Integer> callbackInfo) {
20+
PowerState state = DynamicFPSMod.powerState();
21+
22+
if (state != PowerState.FOCUSED) {
23+
// Instruct Minecraft to render a minimum of 15 FPS
24+
// Going lower here makes resuming again feel sluggish
25+
callbackInfo.setReturnValue(Math.max(DynamicFPSMod.targetFrameRate(), 15));
26+
}
27+
}
28+
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import dynamic_fps.impl.feature.battery.BatteryTracker;
66
import net.minecraft.client.Minecraft;
77
import net.minecraft.client.gui.GuiGraphics;
8-
import net.minecraft.client.renderer.RenderType;
98
import net.minecraft.network.chat.Component;
109

1110
import static dynamic_fps.impl.util.Localization.localized;
@@ -58,7 +57,7 @@ private static void drawBatteryOverlay(GuiGraphics graphics) {
5857
int[] position = config.placement().get(graphics);
5958

6059
// resource, x, y, z, ?, ?, width, height, width, height
61-
graphics.blit(RenderType::guiTextured, icon, position[0], position[1], 0, 0.0f, 0, 16, 16, 16, 16);
60+
graphics.blit(icon, position[0], position[1], 0, 0.0f, 0.0f, 16, 16, 16, 16);
6261
// font, text, x, y, text color
6362
graphics.drawString(minecraft.font, BatteryTracker.charge() + "%", position[0] + 20, position[1] + 4, 0xFFFFFF);
6463
}

platforms/common/src/main/resources/assets/dynamic_fps/data/default_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"uncap_menu_frame_rate": false,
44
"idle": {
55
"timeout": 300,
6-
"condition": "vanilla"
6+
"condition": "on_battery"
77
},
88
"battery_tracker": {
99
"enabled": false,

platforms/common/src/main/resources/dynamic_fps-common.mixins.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"minVersion": "0.8",
55
"client": [
66
"DebugScreenOverlayMixin",
7-
"FramerateLimitTrackerMixin",
87
"GameRendererMixin",
98
"GuiMixin",
109
"LoadingOverlayMixin",
1110
"MinecraftMixin",
1211
"OptionsMixin",
1312
"SoundEngineMixin",
14-
"ToastManagerMixin",
13+
"ToastComponentMixin",
14+
"WindowMixin",
1515
"bugfix.BlockableEventLoopMixin"
1616
],
1717
"mixins": [],

platforms/fabric/src/main/resources/fabric.mod.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
"depends": {
7272
"fabricloader": ">=0.15.10",
73-
"minecraft": ">=1.21.2-alpha.24.33.a",
73+
"minecraft": ["1.21.0", "1.21.1"],
7474
"mixinextras": ">=0.3.2",
7575
"fabric-resource-loader-v0": "*",
7676
"fabric-lifecycle-events-v1": "*"

platforms/forge/src/main/resources/META-INF/mods.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ file="META-INF/accesstransformer.cfg"
8585
[[dependencies.dynamic_fps]]
8686
modId = "minecraft"
8787
mandatory = true
88-
versionRange = "[1.21.0,)"
88+
versionRange = "[1.21.0,1.21.1]"
8989
ordering = "NONE"
9090
side = "CLIENT"

platforms/neoforge/src/main/resources/META-INF/neoforge.mods.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ file="META-INF/accesstransformer.cfg"
8585
[[dependencies.dynamic_fps]]
8686
modId = "minecraft"
8787
mandatory = true
88-
versionRange = "[1.21.0,)"
88+
versionRange = "[1.21.0,1.21.1]"
8989
ordering = "NONE"
9090
side = "CLIENT"

platforms/quilt/src/main/resources/quilt.mod.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
},
8282
{
8383
"id": "minecraft",
84-
"versions": ">=1.21.2-alpha.24.33.a"
84+
"versions": { "all": [">=1.21.0", "<=1.21.1"]}
8585
},
8686
{
8787
"id": "mixinextras",

0 commit comments

Comments
 (0)