Skip to content

Commit 4a37b73

Browse files
committed
Minecraft 1.18.0 backport
1 parent df610e4 commit 4a37b73

Some content is hidden

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

53 files changed

+641
-157
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(17)
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(17)
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.18.0
88

99
maven_group = juliand665
1010
archives_base_name = dynamic-fps
1111

12-
enabled_platforms=fabric,neoforge
12+
enabled_platforms=fabric,forge,quilt
1313
# enabled_platforms=fabric,forge,neoforge,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.18.2"
33

44
# Platform libraries
55

66
fabric_loader = "0.15.10"
7-
fabric_api = "0.100.1+1.21"
7+
fabric_api = "0.77.0+1.18.2"
88

9-
forge = "1.20.4-49.0.30"
9+
forge = "1.18.2-40.2.17"
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 = "1.1.0-beta.26+1.18.2"
1515

1616
# Regular libraries
1717

1818
battery = "1.0.0"
1919

2020
# Modding libraries
2121

22-
modmenu = "11.0.0-beta.1"
23-
cloth_config = "15.0.127"
22+
modmenu = "3.2.5"
23+
cloth_config = "6.2.57"
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;
@@ -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

+10-8
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
)
@@ -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

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

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

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dynamic_fps.impl.feature.state;
22

33
import dynamic_fps.impl.config.option.GraphicsState;
4+
import net.minecraft.client.AmbientOcclusionStatus;
45
import net.minecraft.client.CloudStatus;
56
import net.minecraft.client.GraphicsStatus;
67
import net.minecraft.client.Options;
@@ -14,45 +15,45 @@
1415
public class OptionHolder {
1516
private static CloudStatus cloudStatus;
1617
private static GraphicsStatus graphicsStatus;
17-
private static boolean ambientOcclusion;
18+
private static AmbientOcclusionStatus ambientOcclusion;
1819
private static ParticleStatus particlesStatus;
1920
private static boolean entityShadows;
20-
private static double entityDistance;
21+
private static float entityDistance;
2122

2223
/*
2324
* Create an in-memory copy of current vanilla graphics options.
2425
*
2526
* This MUST be called while graphics options have not been changed yet.
2627
*/
2728
public static void copyOptions(Options options) {
28-
cloudStatus = options.getCloudsType();
29-
graphicsStatus = options.graphicsMode().get();
30-
ambientOcclusion = options.ambientOcclusion().get();
31-
particlesStatus = options.particles().get();
32-
entityShadows = options.entityShadows().get();
33-
entityDistance = options.entityDistanceScaling().get();
29+
cloudStatus = options.renderClouds;
30+
graphicsStatus = options.graphicsMode;
31+
ambientOcclusion = options.ambientOcclusion;
32+
particlesStatus = options.particles;
33+
entityShadows = options.entityShadows;
34+
entityDistance = options.entityDistanceScaling;
3435
}
3536

3637
/*
3738
* Apply or revert the graphics options for the specified graphics state.
3839
*/
3940
public static void applyOptions(Options options, GraphicsState state) {
4041
if (state == GraphicsState.DEFAULT) {
41-
options.cloudStatus().set(cloudStatus);
42-
options.graphicsMode().set(graphicsStatus);
43-
options.ambientOcclusion().set(ambientOcclusion);
44-
options.particles().set(particlesStatus);
45-
options.entityShadows().set(entityShadows);
46-
options.entityDistanceScaling().set(entityDistance);
42+
options.renderClouds = cloudStatus;
43+
options.graphicsMode = graphicsStatus;
44+
options.ambientOcclusion = ambientOcclusion;
45+
options.particles = particlesStatus;
46+
options.entityShadows = entityShadows;
47+
options.entityDistanceScaling = entityDistance;
4748
} else { // state == GraphicsState.REDUCED
48-
options.cloudStatus().set(CloudStatus.OFF);
49-
options.particles().set(ParticleStatus.MINIMAL);
50-
options.entityShadows().set(false);
51-
options.entityDistanceScaling().set(0.5);
49+
options.renderClouds = CloudStatus.OFF;
50+
options.particles = ParticleStatus.MINIMAL;
51+
options.entityShadows = false;
52+
options.entityDistanceScaling = 0.5f;
5253

5354
if (state == GraphicsState.MINIMAL) {
54-
options.graphicsMode().set(GraphicsStatus.FAST);
55-
options.ambientOcclusion().set(false);
55+
options.graphicsMode = GraphicsStatus.FAST;
56+
options.ambientOcclusion = AmbientOcclusionStatus.OFF;
5657
}
5758
}
5859
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private void getFramerateLimit(CallbackInfoReturnable<Integer> callbackInfo) {
5454
callbackInfo.setReturnValue(limit);
5555
}
5656
} else if (DynamicFPSConfig.INSTANCE.uncapMenuFrameRate()) {
57-
if (this.options.enableVsync().get()) {
57+
if (this.options.enableVsync) {
5858
// VSync will regulate to a non-infinite value
5959
callbackInfo.setReturnValue(Constants.NO_FRAME_RATE_LIMIT);
6060
} else {

0 commit comments

Comments
 (0)