diff --git a/build.gradle b/build.gradle index 79e6a41c..a6523cb9 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ subprojects { withSourcesJar() toolchain { - languageVersion = JavaLanguageVersion.of(21) + languageVersion = JavaLanguageVersion.of(17) } } @@ -62,7 +62,7 @@ subprojects { it.options.encoding = "UTF-8" javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(21) + languageVersion = JavaLanguageVersion.of(17) } } } diff --git a/gradle.properties b/gradle.properties index d18ff1a2..3ee414cf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,10 +4,10 @@ org.gradle.jvmargs = -Xmx3G # Mod Properties mod_version = 3.5.0 -minecraft_version_min = 1.21.0 +minecraft_version_min = 1.19.4 maven_group = juliand665 archives_base_name = dynamic-fps -enabled_platforms=fabric,neoforge +enabled_platforms=fabric,forge,quilt # enabled_platforms=fabric,forge,neoforge,quilt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0e8b24d0..2e793f63 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,17 +1,17 @@ [versions] -minecraft = "1.21" +minecraft = "1.19.4" # Platform libraries fabric_loader = "0.15.10" -fabric_api = "0.100.1+1.21" +fabric_api = "0.75.3+1.19.4" -forge = "1.20.4-49.0.30" +forge = "1.19.4-45.2.8" -neoforge = "21.0.0-beta" +neoforge = "20.4.237" quilt_loader = "0.25.0" -quilt_standard_libraries = "8.0.0-alpha.12+1.20.4" +quilt_standard_libraries = "5.0.0-beta.11+1.19.4" # Regular libraries @@ -19,8 +19,8 @@ battery = "1.0.0" # Modding libraries -modmenu = "11.0.0-beta.1" -cloth_config = "15.0.127" +modmenu = "6.1.0" +cloth_config = "10.1.117" mixinextras = "0.3.5" diff --git a/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java b/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java index ef4e890b..e59089f6 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java @@ -14,12 +14,14 @@ import dynamic_fps.impl.util.FallbackConfigScreen; import dynamic_fps.impl.util.Logging; import dynamic_fps.impl.feature.state.OptionHolder; +import dynamic_fps.impl.util.ModCompatHelper; import dynamic_fps.impl.util.ResourceLocations; import dynamic_fps.impl.util.Version; import dynamic_fps.impl.feature.volume.SmoothVolumeHandler; import dynamic_fps.impl.util.duck.DuckLoadingOverlay; import dynamic_fps.impl.feature.state.WindowObserver; import dynamic_fps.impl.service.Platform; +import dynamic_fps.impl.util.duck.DuckScreen; import net.lostluma.battery.api.State; import net.minecraft.Util; import net.minecraft.client.Minecraft; @@ -170,7 +172,7 @@ public static boolean shouldShowToasts() { } public static boolean shouldShowLevels() { - return isDisabled() || !isLevelCoveredByOverlay(); + return isDisabled() || !(isLevelCoveredByScreen() || isLevelCoveredByOverlay()); } public static void onBatteryChargeChanged(int before, int after) { @@ -192,11 +194,17 @@ public static void onBatteryStatusChanged(State before, State after) { private static void doInit() { // NOTE: Init battery tracker first here // Since the idle handler queries it for info + ModCompatHelper.init(); + BatteryTracker.init(); IdleHandler.init(); SmoothVolumeHandler.init(); } + private static boolean isLevelCoveredByScreen() { + return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground(); + } + private static void showNotification(String titleTranslationKey, String iconPath) { if (!DynamicFPSConfig.INSTANCE.batteryTracker().notifications()) { return; diff --git a/platforms/common/src/main/java/dynamic_fps/impl/config/Serialization.java b/platforms/common/src/main/java/dynamic_fps/impl/config/Serialization.java index c7e74efb..20fe9b25 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/config/Serialization.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/config/Serialization.java @@ -85,7 +85,7 @@ private static JsonObject removeUnchangedFields(JsonObject config, JsonObject pa removeUnchangedFields((JsonObject) value, (JsonObject) other); } - if (value.equals(other) || (value.isJsonObject() && value.getAsJsonObject().isEmpty())) { + if (value.equals(other) || (value.isJsonObject() && value.getAsJsonObject().size() == 0)) { config.remove(name); } }); diff --git a/platforms/common/src/main/java/dynamic_fps/impl/config/option/BatteryIndicatorPlacement.java b/platforms/common/src/main/java/dynamic_fps/impl/config/option/BatteryIndicatorPlacement.java index be6234a5..3158092a 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/config/option/BatteryIndicatorPlacement.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/config/option/BatteryIndicatorPlacement.java @@ -1,15 +1,15 @@ package dynamic_fps.impl.config.option; -import net.minecraft.client.gui.GuiGraphics; +import com.mojang.blaze3d.platform.Window; /** * Screen corner to render the battery indicator in. */ public enum BatteryIndicatorPlacement { - TOP_LEFT(graphics -> new int[] {4, 4}), - TOP_RIGHT(graphics -> new int[] {graphics.guiWidth() - 47, 4}), - BOTTOM_LEFT(graphics -> new int[] {4, graphics.guiHeight() - 20}), - BOTTOM_RIGHT(graphics -> new int[] {graphics.guiWidth() - 47, graphics.guiHeight() - 20}); + TOP_LEFT(window -> new int[] {4, 4}), + TOP_RIGHT(window -> new int[] {window.getGuiScaledWidth() - 47, 4}), + BOTTOM_LEFT(window -> new int[] {4, window.getGuiScaledHeight() - 20}), + BOTTOM_RIGHT(window -> new int[] {window.getGuiScaledWidth() - 47, window.getGuiScaledHeight() - 20}); private final DynamicPlacement placement; @@ -17,12 +17,12 @@ public enum BatteryIndicatorPlacement { this.placement = placement; } - public int[] get(GuiGraphics graphics) { - return this.placement.get(graphics); + public int[] get(Window window) { + return this.placement.get(window); } @FunctionalInterface private interface DynamicPlacement { - int[] get(GuiGraphics graphics); + int[] get(Window window); } } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryToast.java b/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryToast.java index 93ee1c16..e77d5b6c 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryToast.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryToast.java @@ -1,8 +1,10 @@ package dynamic_fps.impl.feature.battery; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import dynamic_fps.impl.util.ResourceLocations; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.toasts.Toast; import net.minecraft.client.gui.components.toasts.ToastComponent; import net.minecraft.network.chat.Component; @@ -43,7 +45,7 @@ public static void queueToast(Component title, ResourceLocation icon) { } @Override - public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) { + public @NotNull Visibility render(PoseStack poseStack, ToastComponent toastComponent, long currentTime) { if (this.firstRender == 0) { if (this == queuedToast) { queuedToast = null; @@ -54,14 +56,17 @@ public static void queueToast(Component title, ResourceLocation icon) { this.description = localized("toast", "battery_charge", BatteryTracker.charge()); } + RenderSystem.setShaderTexture(0, BACKGROUND_IMAGE); // resource, x, y, z, ?, ?, width, height, width, height - graphics.blit(BACKGROUND_IMAGE, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height()); + GuiComponent.blit(poseStack, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height()); - graphics.blit(MOD_ICON, 2, 2, 0, 0.0f, 0.0f, 8, 8, 8, 8); - graphics.blit(this.icon, 8, 8, 0, 0.0f, 0.0f, 16, 16, 16, 16); + RenderSystem.setShaderTexture(0, MOD_ICON); + GuiComponent.blit(poseStack, 2, 2, 0, 0.0f, 0.0f, 8, 8, 8, 8); + RenderSystem.setShaderTexture(0, this.icon); + GuiComponent.blit(poseStack, 8, 8, 0, 0.0f, 0.0f, 16, 16, 16, 16); - graphics.drawString(toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315, false); - graphics.drawString(toastComponent.getMinecraft().font, this.description, 30, 18, -16777216, false); + GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315); + GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.description, 30, 18, -16777216); return currentTime - this.firstRender >= 5000.0 * toastComponent.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW; } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryTracker.java b/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryTracker.java index 483a6d5a..62b15d27 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryTracker.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/feature/battery/BatteryTracker.java @@ -58,7 +58,7 @@ public static void init() { } } else { manager = temp; // Keep around to allow updating batteries - Thread.ofVirtual().name("refresh-battery").start(BatteryTracker::updateBatteries); + new Thread(BatteryTracker::updateBatteries, "refresh-battery").start(); } } @@ -127,7 +127,7 @@ private static void updateBatteries() { updateState(); try { - Thread.sleep(updateInterval); + Thread.sleep(updateInterval.toMillis()); } catch (InterruptedException e) { active = false; Thread.currentThread().interrupt(); diff --git a/platforms/common/src/main/java/dynamic_fps/impl/mixin/ScreenMixin.java b/platforms/common/src/main/java/dynamic_fps/impl/mixin/ScreenMixin.java new file mode 100644 index 00000000..7f39e351 --- /dev/null +++ b/platforms/common/src/main/java/dynamic_fps/impl/mixin/ScreenMixin.java @@ -0,0 +1,50 @@ +package dynamic_fps.impl.mixin; + +import dynamic_fps.impl.service.ModCompat; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import dynamic_fps.impl.util.duck.DuckScreen; +import net.minecraft.client.gui.screens.Screen; + +@Mixin(Screen.class) +public class ScreenMixin implements DuckScreen { + @Unique + private boolean dynamic_fps$canOptimize = false; + + @Unique + private boolean dynamic_fps$hasOptedOut = false; + + @Override + public boolean dynamic_fps$rendersBackground() { + return dynamic_fps$canOptimize; + } + + @Override + public void dynamic_fps$setRendersBackground() { + this.dynamic_fps$canOptimize = true; + } + + @Inject(method = "init", at = @At("HEAD")) + private void onInit(CallbackInfo callbackInfo) { + String name = this.getClass().getName(); + + this.dynamic_fps$hasOptedOut = ModCompat.getInstance().isScreenOptedOut(name); + + // Allow other mods to opt out on behalf of vanilla screens + // That Dynamic FPS forced to opt in via its own mod metadata. + if (!this.dynamic_fps$hasOptedOut) { + this.dynamic_fps$canOptimize = ModCompat.getInstance().isScreenOptedIn(name); + } + } + + @Inject(method = "renderDirtBackground", at = @At("HEAD")) + private void onRenderDirtBackground(CallbackInfo callbackInfo) { + if (!this.dynamic_fps$hasOptedOut) { + this.dynamic_fps$canOptimize = true; // Signal to apply optimizations on next frame + } + } +} diff --git a/platforms/common/src/main/java/dynamic_fps/impl/mixin/StatsScreenMixin.java b/platforms/common/src/main/java/dynamic_fps/impl/mixin/StatsScreenMixin.java new file mode 100644 index 00000000..92b1b5ac --- /dev/null +++ b/platforms/common/src/main/java/dynamic_fps/impl/mixin/StatsScreenMixin.java @@ -0,0 +1,17 @@ +package dynamic_fps.impl.mixin; + +import dynamic_fps.impl.util.duck.DuckScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.gui.screens.achievement.StatsScreen; + +@Mixin(StatsScreen.class) +public class StatsScreenMixin { + @Inject(method = "onStatsUpdated", at = @At("HEAD")) + private void onStatsUpdated(CallbackInfo callbackInfo) { + ((DuckScreen) this).dynamic_fps$setRendersBackground(); + } +} diff --git a/platforms/common/src/main/java/dynamic_fps/impl/service/ModCompat.java b/platforms/common/src/main/java/dynamic_fps/impl/service/ModCompat.java index dea57fdf..bbfdbc53 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/service/ModCompat.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/service/ModCompat.java @@ -1,10 +1,23 @@ package dynamic_fps.impl.service; +import java.util.Set; + public interface ModCompat { boolean isDisabled(); boolean disableOverlayOptimization(); + Set getOptedInScreens(); + Set getOptedOutScreens(); + + default boolean isScreenOptedIn(String className) { + return getOptedInScreens().contains(className); + } + + default boolean isScreenOptedOut(String className) { + return getOptedOutScreens().contains(className); + } + static ModCompat getInstance() { return Services.MOD_COMPAT; } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/util/FallbackConfigScreen.java b/platforms/common/src/main/java/dynamic_fps/impl/util/FallbackConfigScreen.java index 99f5532b..41107338 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/util/FallbackConfigScreen.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/util/FallbackConfigScreen.java @@ -1,7 +1,7 @@ package dynamic_fps.impl.util; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; @@ -32,14 +32,15 @@ protected void init() { } @Override - public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { - super.render(guiGraphics, mouseX, mouseY, partialTicks); + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) { + this.renderDirtBackground(poseStack); + super.render(poseStack, mouseX, mouseY, partialTicks); - int width = guiGraphics.guiWidth() / 2; - int height = guiGraphics.guiHeight() / 3; + int width = this.width / 2; + int height = this.height / 3; - guiGraphics.drawCenteredString(this.font, WARNING_0.getVisualOrderText(), width, height, 0xFFFFFF); - guiGraphics.drawCenteredString(this.font, WARNING_1.getVisualOrderText(), width, height + 10, 0xFFFFFF); + drawCenteredString(poseStack, this.font, WARNING_0.getVisualOrderText(), width, height, 0xFFFFFF); + drawCenteredString(poseStack, this.font, WARNING_1.getVisualOrderText(), width, height + 10, 0xFFFFFF); } @Override diff --git a/platforms/common/src/main/java/dynamic_fps/impl/util/HudInfoRenderer.java b/platforms/common/src/main/java/dynamic_fps/impl/util/HudInfoRenderer.java index 35e472db..470d5737 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/util/HudInfoRenderer.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/util/HudInfoRenderer.java @@ -1,10 +1,12 @@ package dynamic_fps.impl.util; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import dynamic_fps.impl.config.BatteryTrackerConfig; import dynamic_fps.impl.config.DynamicFPSConfig; import dynamic_fps.impl.feature.battery.BatteryTracker; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.network.chat.Component; import static dynamic_fps.impl.util.Localization.localized; @@ -16,30 +18,30 @@ public final class HudInfoRenderer { private static final Minecraft minecraft = Minecraft.getInstance(); - public static void renderInfo(GuiGraphics guiGraphics) { + public static void renderInfo(PoseStack poseStack) { if (minecraft.options.hideGui || minecraft.screen != null) { return; } if (DynamicFPSConfig.INSTANCE.batteryTracker().enabled()) { - drawBatteryOverlay(guiGraphics); + drawBatteryOverlay(poseStack); } if (DynamicFPSMod.disabledByUser()) { - drawCenteredText(guiGraphics, localized("gui", "hud.disabled")); + drawCenteredText(poseStack, localized("gui", "hud.disabled")); } else if (DynamicFPSMod.isForcingLowFPS()) { - drawCenteredText(guiGraphics, localized("gui", "hud.reducing")); + drawCenteredText(poseStack, localized("gui", "hud.reducing")); } } - private static void drawCenteredText(GuiGraphics guiGraphics, Component component) { - int width = guiGraphics.guiWidth() / 2; + private static void drawCenteredText(PoseStack poseStack, Component component) { + int width = minecraft.getWindow().getGuiScaledWidth() / 2; - guiGraphics.drawCenteredString(minecraft.font, component, width, 32, 0xFFFFFF); + GuiComponent.drawCenteredString(poseStack, minecraft.font, component, width, 32, 0xFFFFFF); } - private static void drawBatteryOverlay(GuiGraphics graphics) { - if (minecraft.getDebugOverlay().showDebugScreen() || !BatteryTracker.hasBatteries()) { + private static void drawBatteryOverlay(PoseStack poseStack) { + if (minecraft.options.renderDebug || !BatteryTracker.hasBatteries()) { return; } @@ -54,11 +56,12 @@ private static void drawBatteryOverlay(GuiGraphics graphics) { ResourceLocation icon = ResourceLocations.of("dynamic_fps", "textures/battery/icon/" + type + "_" + index + ".png"); // pair of coordinates - int[] position = config.placement().get(graphics); + int[] position = config.placement().get(minecraft.getWindow()); + RenderSystem.setShaderTexture(0, icon); // resource, x, y, z, ?, ?, width, height, width, height - graphics.blit(icon, position[0], position[1], 0, 0.0f, 0.0f, 16, 16, 16, 16); + GuiComponent.blit(poseStack, position[0], position[1], 0, 0.0f, 0.0f, 16, 16, 16, 16); // font, text, x, y, text color - graphics.drawString(minecraft.font, BatteryTracker.charge() + "%", position[0] + 20, position[1] + 4, 0xFFFFFF); + GuiComponent.drawString(poseStack, minecraft.font, BatteryTracker.charge() + "%", position[0] + 20, position[1] + 4, 0xFFFFFF); } } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/util/ModCompatHelper.java b/platforms/common/src/main/java/dynamic_fps/impl/util/ModCompatHelper.java new file mode 100644 index 00000000..7e629913 --- /dev/null +++ b/platforms/common/src/main/java/dynamic_fps/impl/util/ModCompatHelper.java @@ -0,0 +1,40 @@ +package dynamic_fps.impl.util; + +import dynamic_fps.impl.service.ModCompat; +import dynamic_fps.impl.service.Platform; + +import java.util.Optional; + +public class ModCompatHelper { + public static void init() { + fixFastloadSoftLock(); + } + + /** + * Fix softlock in combination with Fastload <=3.4.0 due to our screen / loading overlay optimization. + * + * See the issue report for more info. + */ + private static void fixFastloadSoftLock() { + Optional optional = Platform.getInstance().getModVersion("fastload"); + + if (optional.isEmpty()) { + return; + } + + Version other; + + try { + other = Version.of("3.4.0"); + } catch (Version.VersionParseException e) { + throw new RuntimeException(e); + } + + // If a version below 3.4.0 is present opt their custom world loading screen out of our optimization + if (optional.get().compareTo(other) <= 0) { + ModCompat.getInstance().getOptedOutScreens().add( + "io.github.bumblesoftware.fastload.client.BuildingTerrainScreen" + ); + } + } +} diff --git a/platforms/common/src/main/java/dynamic_fps/impl/util/ResourceLocations.java b/platforms/common/src/main/java/dynamic_fps/impl/util/ResourceLocations.java index 45e40b8d..c9f0ab50 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/util/ResourceLocations.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/util/ResourceLocations.java @@ -4,6 +4,6 @@ public class ResourceLocations { public static ResourceLocation of(String namespace, String path) { - return ResourceLocation.fromNamespaceAndPath(namespace, path); + return new ResourceLocation(namespace, path); } } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/util/VariableStepTransformer.java b/platforms/common/src/main/java/dynamic_fps/impl/util/VariableStepTransformer.java index 93bef45f..dc94e8bc 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/util/VariableStepTransformer.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/util/VariableStepTransformer.java @@ -1,6 +1,7 @@ package dynamic_fps.impl.util; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -13,9 +14,11 @@ public class VariableStepTransformer { private boolean unsorted; private final List steps; + private final List reversedSteps; public VariableStepTransformer() { this.steps = new ArrayList<>(); + this.reversedSteps = new ArrayList<>(); } /** @@ -27,6 +30,7 @@ public VariableStepTransformer() { public void addStep(int change, int max) { this.unsorted = true; this.steps.add(new Step(change, max)); + this.reversedSteps.add(new Step(change, max)); } /** @@ -42,7 +46,7 @@ public int toStep(int value) { int currentChange = 0; int currentValue = value; - for (Step pair : this.steps.reversed()) { + for (Step pair : this.reversedSteps) { if (currentValue > pair.max && currentChange != 0) { step += Math.floorDiv(currentValue - pair.max, currentChange); currentValue = pair.max; @@ -86,6 +90,14 @@ public int compare(Step self, Step other) { return Integer.compare(self.max, other.max); } }); + + this.reversedSteps.sort(new Comparator() { + @Override + public int compare(Step self, Step other) { + return Integer.compare(self.max, other.max); + } + }); + Collections.reverse(this.reversedSteps); } private record Step(int change, int max) {} diff --git a/platforms/common/src/main/java/dynamic_fps/impl/util/duck/DuckScreen.java b/platforms/common/src/main/java/dynamic_fps/impl/util/duck/DuckScreen.java new file mode 100644 index 00000000..fe72fe3d --- /dev/null +++ b/platforms/common/src/main/java/dynamic_fps/impl/util/duck/DuckScreen.java @@ -0,0 +1,11 @@ +package dynamic_fps.impl.util.duck; + +public interface DuckScreen { + default boolean dynamic_fps$rendersBackground() { + throw new RuntimeException("No implementation for dynamic_fps$rendersBackground was found."); + } + + default void dynamic_fps$setRendersBackground() { + throw new RuntimeException("No implementation for dynamic_fps$rendersBackground was found."); + } +} diff --git a/platforms/common/src/main/resources/dynamic_fps-common.mixins.json b/platforms/common/src/main/resources/dynamic_fps-common.mixins.json index a8037d96..33486bf4 100644 --- a/platforms/common/src/main/resources/dynamic_fps-common.mixins.json +++ b/platforms/common/src/main/resources/dynamic_fps-common.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "dynamic_fps.impl.mixin", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "client": [ "DebugScreenOverlayMixin", @@ -9,7 +9,9 @@ "GuiMixin", "LoadingOverlayMixin", "MinecraftMixin", + "ScreenMixin", "SoundEngineMixin", + "StatsScreenMixin", "ToastComponentMixin", "WindowMixin", "bugfix.BlockableEventLoopMixin" diff --git a/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/mixin/GuiMixin.java b/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/mixin/GuiMixin.java index ecfae3d4..09e89480 100644 --- a/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/mixin/GuiMixin.java +++ b/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/mixin/GuiMixin.java @@ -1,9 +1,9 @@ package net.lostluma.dynamic_fps.impl.fabric.mixin; import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.vertex.PoseStack; import dynamic_fps.impl.util.HudInfoRenderer; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiGraphics; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,8 +14,14 @@ public class GuiMixin { /** * Render info on whether Dynamic FPS is disabled or always reducing the user's FPS. */ - @Inject(method = "renderSavingIndicator", at = @At("HEAD")) - private void renderSavingIndicator(CallbackInfo callbackInfo, @Local(argsOnly = true) GuiGraphics guiGraphics) { - HudInfoRenderer.renderInfo(guiGraphics); + @Inject( + method = "render", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/Gui;renderSavingIndicator(Lcom/mojang/blaze3d/vertex/PoseStack;)V" + ) + ) + private void renderSavingIndicator(CallbackInfo callbackInfo, @Local(argsOnly = true) PoseStack poseStack) { + HudInfoRenderer.renderInfo(poseStack); } } diff --git a/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/service/FabricModCompat.java b/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/service/FabricModCompat.java index 473389b2..d00cd7a6 100644 --- a/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/service/FabricModCompat.java +++ b/platforms/fabric/src/main/java/net/lostluma/dynamic_fps/impl/fabric/service/FabricModCompat.java @@ -2,15 +2,22 @@ import dynamic_fps.impl.service.ModCompat; import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.MappingResolver; import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.metadata.CustomValue; import net.fabricmc.loader.api.metadata.ModMetadata; import net.lostluma.dynamic_fps.impl.fabric.compat.FREX; import org.jetbrains.annotations.Nullable; +import java.util.HashSet; +import java.util.Set; + public class FabricModCompat implements ModCompat { private static boolean disableOverlayOptimization = false; + private static final Set optedInScreens = new HashSet<>(); + private static final Set optedOutScreens = new HashSet<>(); + static { FabricLoader.getInstance().getAllMods().forEach(FabricModCompat::parseModMetadata); } @@ -25,6 +32,16 @@ public boolean disableOverlayOptimization() { return disableOverlayOptimization; } + @Override + public Set getOptedInScreens() { + return optedInScreens; + } + + @Override + public Set getOptedOutScreens() { + return optedOutScreens; + } + private static void parseModMetadata(ModContainer mod) { CustomValue.CvObject root; ModMetadata data = mod.getMetadata(); @@ -36,6 +53,9 @@ private static void parseModMetadata(ModContainer mod) { } parseOverlayOverride(root.get("optimized_overlay")); + + parseScreenOverrides(root.get("optimized_screens"), "enabled", optedInScreens); + parseScreenOverrides(root.get("optimized_screens"), "disabled", optedOutScreens); } private static void parseOverlayOverride(@Nullable CustomValue value) { @@ -43,4 +63,25 @@ private static void parseOverlayOverride(@Nullable CustomValue value) { disableOverlayOptimization = true; } } + + private static void parseScreenOverrides(@Nullable CustomValue parent, String type, Set set) { + if (parent == null || parent.getType() != CustomValue.CvType.OBJECT) { + return; + } + + CustomValue values = parent.getAsObject().get(type); + + if (values == null || values.getType() != CustomValue.CvType.ARRAY) { + return; + } + + MappingResolver resolver = FabricLoader.getInstance().getMappingResolver(); + + values.getAsArray().forEach(value -> { + if (value.getType() == CustomValue.CvType.STRING) { + // Translate from intermediary to runtime names for vanilla screens + set.add(resolver.mapClassName("intermediary", value.getAsString())); + } + }); + } } diff --git a/platforms/fabric/src/main/resources/dynamic_fps.mixins.json b/platforms/fabric/src/main/resources/dynamic_fps.mixins.json index ad91e785..f9a16703 100644 --- a/platforms/fabric/src/main/resources/dynamic_fps.mixins.json +++ b/platforms/fabric/src/main/resources/dynamic_fps.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "net.lostluma.dynamic_fps.impl.fabric.mixin", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "client": [ "GuiMixin", diff --git a/platforms/fabric/src/main/resources/fabric.mod.json b/platforms/fabric/src/main/resources/fabric.mod.json index 0b60d317..8f28a154 100644 --- a/platforms/fabric/src/main/resources/fabric.mod.json +++ b/platforms/fabric/src/main/resources/fabric.mod.json @@ -69,7 +69,9 @@ }, "depends": { "fabricloader": ">=0.15.10", - "minecraft": ">=1.21.0-alpha.24.20.a", + "minecraft": [ + "1.19.4" + ], "mixinextras": ">=0.3.2", "fabric-resource-loader-v0": "*", "fabric-lifecycle-events-v1": "*" @@ -86,5 +88,43 @@ "dynamic_fps.mixins.json", "dynamic_fps-common.mixins.json" ], - "accessWidener": "dynamic_fps.accesswidener" + "accessWidener": "dynamic_fps.accesswidener", + "custom": { + "dynamic_fps": { + "optimized_screens": { + "enabled": [ + "net.minecraft.class_4189", + "net.minecraft.class_404", + "net.minecraft.class_426", + "net.minecraft.class_4288", + "net.minecraft.class_6777", + "net.minecraft.class_443", + "net.minecraft.class_446", + "net.minecraft.class_445", + "net.minecraft.class_6599" + ], + "disabled": [ + "net.minecraft.class_434" + ], + "_comment": { + "_0": "Mojang mapping names of the enabled / disabled screens.", + "_1": "Sorted by fully qualified name. Translation not needed for mod screens.", + "enabled": { + "net.minecraft.class_4189": "net.minecraft.client.gui.screens.AccessibilityOptionsScreen", + "net.minecraft.class_404": "net.minecraft.client.gui.screens.ChatOptionsScreen", + "net.minecraft.class_426": "net.minecraft.client.gui.screens.LanguageSelectScreen", + "net.minecraft.class_4288": "net.minecraft.client.gui.screens.MouseSettingsScreen", + "net.minecraft.class_6777": "net.minecraft.client.gui.screens.OnlineOptionsScreen", + "net.minecraft.class_443": "net.minecraft.client.gui.screens.SoundOptionsScreen", + "net.minecraft.class_446": "net.minecraft.client.gui.screens.VideoSettingsScreen", + "net.minecraft.class_445": "net.minecraft.client.gui.screens.WinScreen", + "net.minecraft.class_6599": "net.minecraft.client.gui.screens.controls.KeyBindsScreen" + }, + "disabled": { + "net.minecraft.class_434": "net.minecraft.client.gui.screens.ReceivingLevelScreen" + } + } + } + } + } } diff --git a/platforms/forge/build.gradle b/platforms/forge/build.gradle index c7381cd6..0e3e02ef 100644 --- a/platforms/forge/build.gradle +++ b/platforms/forge/build.gradle @@ -36,6 +36,8 @@ dependencies { include(libs.mixinextras.forge) implementation(libs.mixinextras.forge) + include(libs.battery) + common(project(path: ":platforms:common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":platforms:common", configuration: "transformProductionForge")) { transitive = false } } diff --git a/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/DynamicFPSForgeMod.java b/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/DynamicFPSForgeMod.java index f6f3e938..38aa94e4 100644 --- a/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/DynamicFPSForgeMod.java +++ b/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/DynamicFPSForgeMod.java @@ -43,7 +43,7 @@ public DynamicFPSForgeMod() { } public void renderGuiOverlay(RenderGuiOverlayEvent event) { - HudInfoRenderer.renderInfo(event.getGuiGraphics()); + HudInfoRenderer.renderInfo(event.getPoseStack()); } public void registerKeyMappings(RegisterKeyMappingsEvent event) { diff --git a/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgeModCompat.java b/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgeModCompat.java index 4f47fadb..814c28eb 100644 --- a/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgeModCompat.java +++ b/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgeModCompat.java @@ -1,9 +1,23 @@ package net.lostluma.dynamic_fps.impl.forge.service; +import com.electronwill.nightconfig.core.CommentedConfig; import dynamic_fps.impl.service.ModCompat; +import net.minecraft.client.gui.screens.ReceivingLevelScreen; import net.minecraftforge.fml.ModList; +import net.minecraftforge.forgespi.language.IModInfo; + +import java.util.HashSet; +import java.util.Set; public class ForgeModCompat implements ModCompat { + private static boolean disableOverlayOptimization = false; + private static final Set optedOutScreens = new HashSet<>(); + + static { + optedOutScreens.add(ReceivingLevelScreen.class.getCanonicalName()); + ModList.get().getMods().forEach(ForgeModCompat::parseModMetadata); + } + @Override public boolean isDisabled() { return false; @@ -11,6 +25,30 @@ public boolean isDisabled() { @Override public boolean disableOverlayOptimization() { - return ModList.get().isLoaded("rrls"); + return disableOverlayOptimization || ModList.get().isLoaded("rrls"); + } + + @Override + public Set getOptedInScreens() { + return Set.of(); + } + + @Override + public Set getOptedOutScreens() { + return optedOutScreens; + } + + private static void parseModMetadata(IModInfo modInfo) { + Object config = modInfo.getModProperties().get("dynamic_fps"); + + if (config == null) { + return; + } + + Boolean value = ((CommentedConfig) config).get("optimized_overlay"); + + if (value != null && !value) { + disableOverlayOptimization = true; + } } } diff --git a/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgePlatform.java b/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgePlatform.java index 74a7af9e..13be8a2b 100644 --- a/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgePlatform.java +++ b/platforms/forge/src/main/java/net/lostluma/dynamic_fps/impl/forge/service/ForgePlatform.java @@ -2,6 +2,7 @@ import dynamic_fps.impl.Constants; import dynamic_fps.impl.service.Platform; +import dynamic_fps.impl.util.Version; import net.lostluma.dynamic_fps.impl.forge.DynamicFPSForgeMod; import net.minecraftforge.fml.ModContainer; import net.minecraftforge.fml.ModList; @@ -41,9 +42,20 @@ public boolean isModLoaded(String modId) { } @Override - public Optional getModVersion(String modId) { + public Optional getModVersion(String modId) { Optional optional = ModList.get().getModContainerById(modId); - return optional.map(modContainer -> modContainer.getModInfo().getVersion().toString()); + + if (optional.isEmpty()) { + return Optional.empty(); + } + + String raw = optional.get().getModInfo().getVersion().toString(); + + try { + return Optional.of(Version.of(raw)); + } catch (Version.VersionParseException e) { + throw new RuntimeException(e); + } } @Override diff --git a/platforms/forge/src/main/resources/META-INF/mods.toml b/platforms/forge/src/main/resources/META-INF/mods.toml index 5871b43e..ef5f0ab7 100644 --- a/platforms/forge/src/main/resources/META-INF/mods.toml +++ b/platforms/forge/src/main/resources/META-INF/mods.toml @@ -84,7 +84,7 @@ file="META-INF/accesstransformer.cfg" [[dependencies.dynamic_fps]] modId = "minecraft" mandatory = true -versionRange = "[1.20.0,1.20.4]" +versionRange = "[1.19.4]" ordering = "NONE" side = "CLIENT" diff --git a/platforms/forge/src/main/resources/dynamic_fps.mixins.json b/platforms/forge/src/main/resources/dynamic_fps.mixins.json index 7a6610bd..36a7f8d0 100644 --- a/platforms/forge/src/main/resources/dynamic_fps.mixins.json +++ b/platforms/forge/src/main/resources/dynamic_fps.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "net.lostluma.dynamic_fps.impl.forge.mixin", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "client": [], "mixins": [], diff --git a/platforms/neoforge/build.gradle b/platforms/neoforge/build.gradle index cc2873bb..2eed6e79 100644 --- a/platforms/neoforge/build.gradle +++ b/platforms/neoforge/build.gradle @@ -38,7 +38,7 @@ dependencies { processResources { inputs.property "version", rootProject.mod_version - filesMatching("META-INF/neoforge.mods.toml") { + filesMatching("META-INF/mods.toml") { expand "version": rootProject.mod_version } } diff --git a/platforms/neoforge/gradle.properties b/platforms/neoforge/gradle.properties index 7da18ea6..cc003479 100644 --- a/platforms/neoforge/gradle.properties +++ b/platforms/neoforge/gradle.properties @@ -1 +1,2 @@ loom.platform=neoforge +minecraft_version_min = 1.20.2 diff --git a/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/DynamicFPSNeoForgeMod.java b/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/DynamicFPSNeoForgeMod.java index 3f1cb0d5..024f28ca 100644 --- a/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/DynamicFPSNeoForgeMod.java +++ b/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/DynamicFPSNeoForgeMod.java @@ -2,15 +2,16 @@ import dynamic_fps.impl.Constants; import dynamic_fps.impl.DynamicFPSMod; +import dynamic_fps.impl.compat.ClothConfig; import dynamic_fps.impl.util.HudInfoRenderer; import dynamic_fps.impl.util.KeyMappingHandler; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.common.Mod; import net.neoforged.fml.loading.FMLLoader; +import net.neoforged.neoforge.client.ConfigScreenHandler; import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; import net.neoforged.neoforge.client.event.RenderGuiEvent; -import net.neoforged.neoforge.client.gui.IConfigScreenFactory; import net.neoforged.neoforge.common.NeoForge; @Mod(Constants.MOD_ID) @@ -23,8 +24,10 @@ public DynamicFPSNeoForgeMod(IEventBus modEventBus) { DynamicFPSMod.init(); ModLoadingContext.get().registerExtensionPoint( - IConfigScreenFactory.class, - () -> (minecraft, screen) -> DynamicFPSMod.getConfigScreen(screen) + ConfigScreenHandler.ConfigScreenFactory.class, + () -> new ConfigScreenHandler.ConfigScreenFactory( + (minecraft, screen) -> ClothConfig.genConfigScreen(screen) + ) ); modEventBus.addListener(this::registerKeyMappings); diff --git a/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgeModCompat.java b/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgeModCompat.java index 7496aa3a..62735115 100644 --- a/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgeModCompat.java +++ b/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgeModCompat.java @@ -2,13 +2,19 @@ import com.electronwill.nightconfig.core.CommentedConfig; import dynamic_fps.impl.service.ModCompat; +import net.minecraft.client.gui.screens.ReceivingLevelScreen; import net.neoforged.fml.ModList; import net.neoforged.neoforgespi.language.IModInfo; +import java.util.HashSet; +import java.util.Set; + public class NeoForgeModCompat implements ModCompat { private static boolean disableOverlayOptimization = false; + private static final Set optedOutScreens = new HashSet<>(); static { + optedOutScreens.add(ReceivingLevelScreen.class.getCanonicalName()); ModList.get().getMods().forEach(NeoForgeModCompat::parseModMetadata); } @@ -22,6 +28,16 @@ public boolean disableOverlayOptimization() { return disableOverlayOptimization || ModList.get().isLoaded("rrls"); } + @Override + public Set getOptedInScreens() { + return Set.of(); + } + + @Override + public Set getOptedOutScreens() { + return optedOutScreens; + } + private static void parseModMetadata(IModInfo modInfo) { Object config = modInfo.getModProperties().get("dynamic_fps"); diff --git a/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgePlatform.java b/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgePlatform.java index b90d6ea2..06251e6a 100644 --- a/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgePlatform.java +++ b/platforms/neoforge/src/main/java/net/lostluma/dynamic_fps/impl/neoforge/service/NeoForgePlatform.java @@ -7,8 +7,8 @@ import net.neoforged.fml.ModList; import net.neoforged.fml.loading.FMLLoader; import net.neoforged.fml.loading.FMLPaths; -import net.neoforged.neoforge.client.event.ClientTickEvent; import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.TickEvent; import java.io.IOException; import java.nio.file.Files; @@ -61,7 +61,7 @@ public Optional getModVersion(String modId) { @Override public void registerStartTickEvent(StartTickEvent event) { - NeoForge.EVENT_BUS.addListener(ClientTickEvent.Pre.class, (unused) -> event.onStartTick()); + NeoForge.EVENT_BUS.addListener(TickEvent.ClientTickEvent.class, (unused) -> event.onStartTick()); } private Path ensureDir(Path path) { diff --git a/platforms/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/platforms/neoforge/src/main/resources/META-INF/mods.toml similarity index 98% rename from platforms/neoforge/src/main/resources/META-INF/neoforge.mods.toml rename to platforms/neoforge/src/main/resources/META-INF/mods.toml index 61b1a97e..3eeb541c 100644 --- a/platforms/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/platforms/neoforge/src/main/resources/META-INF/mods.toml @@ -84,7 +84,7 @@ file="META-INF/accesstransformer.cfg" [[dependencies.dynamic_fps]] modId = "minecraft" mandatory = true -versionRange = "[1.21.0,)" +versionRange = "[1.20.2,1.20.4]" ordering = "NONE" side = "CLIENT" diff --git a/platforms/neoforge/src/main/resources/dynamic_fps.mixins.json b/platforms/neoforge/src/main/resources/dynamic_fps.mixins.json index 0f8948a6..a1e30c92 100644 --- a/platforms/neoforge/src/main/resources/dynamic_fps.mixins.json +++ b/platforms/neoforge/src/main/resources/dynamic_fps.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "net.lostluma.dynamic_fps.impl.neoforge.mixin", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "client": [], "mixins": [], diff --git a/platforms/quilt/build.gradle b/platforms/quilt/build.gradle index 894d5779..0d965598 100644 --- a/platforms/quilt/build.gradle +++ b/platforms/quilt/build.gradle @@ -8,10 +8,7 @@ repositories { filter { includeGroup("com.terraformersmc") } forRepository { maven { url = "https://maven.terraformersmc.com/releases" } } } - exclusiveContent { - filter { includeGroup("org.quiltmc") } - forRepository { maven { url = "https://maven.quiltmc.org/repository/release" } } - } + maven { url = "https://maven.quiltmc.org/repository/release" } } architectury { @@ -37,6 +34,8 @@ dependencies { modApi(libs.modmenu) + include(libs.battery) + common(project(path: ":platforms:common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":platforms:common", configuration: "transformProductionQuilt")) { transitive false } } diff --git a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/compat/ModMenu.java b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/compat/ModMenu.java index e0ceca9a..dffa2f13 100644 --- a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/compat/ModMenu.java +++ b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/compat/ModMenu.java @@ -2,18 +2,12 @@ import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; -import dynamic_fps.impl.compat.ClothConfig; -import org.quiltmc.loader.api.QuiltLoader; -public class ModMenu implements ModMenuApi { - private static final boolean CLOTH_CONFIG = QuiltLoader.isModLoaded("cloth-config2"); +import dynamic_fps.impl.DynamicFPSMod; +public class ModMenu implements ModMenuApi { @Override public ConfigScreenFactory getModConfigScreenFactory() { - if (!CLOTH_CONFIG) { - return parent -> null; - } else { - return ClothConfig::genConfigScreen; - } + return DynamicFPSMod::getConfigScreen; } } diff --git a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/mixin/GuiMixin.java b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/mixin/GuiMixin.java index ecfae3d4..106612a0 100644 --- a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/mixin/GuiMixin.java +++ b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/mixin/GuiMixin.java @@ -1,9 +1,9 @@ -package net.lostluma.dynamic_fps.impl.fabric.mixin; +package net.lostluma.dynamic_fps.impl.quilt.mixin; import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.vertex.PoseStack; import dynamic_fps.impl.util.HudInfoRenderer; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiGraphics; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,8 +14,14 @@ public class GuiMixin { /** * Render info on whether Dynamic FPS is disabled or always reducing the user's FPS. */ - @Inject(method = "renderSavingIndicator", at = @At("HEAD")) - private void renderSavingIndicator(CallbackInfo callbackInfo, @Local(argsOnly = true) GuiGraphics guiGraphics) { - HudInfoRenderer.renderInfo(guiGraphics); + @Inject( + method = "render", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/Gui;renderSavingIndicator(Lcom/mojang/blaze3d/vertex/PoseStack;)V" + ) + ) + private void renderSavingIndicator(CallbackInfo callbackInfo, @Local(argsOnly = true) PoseStack poseStack) { + HudInfoRenderer.renderInfo(poseStack); } } diff --git a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltModCompat.java b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltModCompat.java index 3a11d11d..efc0142b 100644 --- a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltModCompat.java +++ b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltModCompat.java @@ -15,6 +15,9 @@ public class QuiltModCompat implements ModCompat { private static boolean disableOverlayOptimization = false; + private static final Set optedInScreens = new HashSet<>(); + private static final Set optedOutScreens = new HashSet<>(); + static { QuiltLoader.getAllMods().forEach(QuiltModCompat::parseModMetadata); } @@ -29,6 +32,16 @@ public boolean disableOverlayOptimization() { return disableOverlayOptimization; } + @Override + public Set getOptedInScreens() { + return optedInScreens; + } + + @Override + public Set getOptedOutScreens() { + return optedOutScreens; + } + private static void parseModMetadata(ModContainer mod) { LoaderValue.LObject root; ModMetadata data = mod.metadata(); @@ -40,6 +53,9 @@ private static void parseModMetadata(ModContainer mod) { } parseOverlayOverride(root.get("optimized_overlay")); + + parseScreenOverrides(root.get("optimized_screens"), "enabled", optedInScreens); + parseScreenOverrides(root.get("optimized_screens"), "disabled", optedOutScreens); } private static void parseOverlayOverride(@Nullable LoaderValue value) { @@ -47,4 +63,25 @@ private static void parseOverlayOverride(@Nullable LoaderValue value) { disableOverlayOptimization = true; } } + + private static void parseScreenOverrides(@Nullable LoaderValue parent, String type, Set set) { + if (parent == null || parent.type() != LoaderValue.LType.OBJECT) { + return; + } + + LoaderValue values = parent.asObject().get(type); + + if (values == null || values.type() != LoaderValue.LType.ARRAY) { + return; + } + + MappingResolver resolver = QuiltLoader.getMappingResolver(); + + values.asArray().forEach(value -> { + if (value.type() == LoaderValue.LType.STRING) { + // Translate from intermediary to runtime names for vanilla screens + set.add(resolver.mapClassName("intermediary", value.asString())); + } + }); + } } diff --git a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltPlatform.java b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltPlatform.java index f497be75..a032c954 100644 --- a/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltPlatform.java +++ b/platforms/quilt/src/main/java/net/lostluma/dynamic_fps/impl/quilt/service/QuiltPlatform.java @@ -2,6 +2,7 @@ import dynamic_fps.impl.Constants; import dynamic_fps.impl.service.Platform; +import dynamic_fps.impl.util.Version; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.QuiltLoader; import org.quiltmc.qsl.lifecycle.api.client.event.ClientTickEvents; @@ -33,9 +34,25 @@ public boolean isDevelopmentEnvironment() { } @Override - public Optional getModVersion(String modId) { + public boolean isModLoaded(String modId) { + return QuiltLoader.isModLoaded(modId); + } + + @Override + public Optional getModVersion(String modId) { Optional optional = QuiltLoader.getModContainer(modId); - return optional.map(modContainer -> modContainer.metadata().version().toString()); + + if (optional.isEmpty()) { + return Optional.empty(); + } + + String raw = optional.get().metadata().version().toString(); + + try { + return Optional.of(Version.of(raw)); + } catch (Version.VersionParseException e) { + throw new RuntimeException(e); + } } @Override diff --git a/platforms/quilt/src/main/resources/dynamic_fps.mixins.json b/platforms/quilt/src/main/resources/dynamic_fps.mixins.json index c9b784b3..603b6b5c 100644 --- a/platforms/quilt/src/main/resources/dynamic_fps.mixins.json +++ b/platforms/quilt/src/main/resources/dynamic_fps.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "net.lostluma.dynamic_fps.impl.quilt.mixin", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "client": [ "GuiMixin", diff --git a/platforms/quilt/src/main/resources/quilt.mod.json b/platforms/quilt/src/main/resources/quilt.mod.json index dd4a5312..7f907164 100644 --- a/platforms/quilt/src/main/resources/quilt.mod.json +++ b/platforms/quilt/src/main/resources/quilt.mod.json @@ -80,7 +80,7 @@ }, { "id": "minecraft", - "versions": ">=1.20.5-alpha.24.14.a" + "versions": "=1.19.4" }, { "id": "mixinextras", @@ -113,5 +113,41 @@ "dynamic_fps.mixins.json", "dynamic_fps-common.mixins.json" ], - "access_widener": "dynamic_fps.accesswidener" + "access_widener": "dynamic_fps.accesswidener", + "dynamic_fps": { + "optimized_screens": { + "enabled": [ + "net.minecraft.class_4189", + "net.minecraft.class_404", + "net.minecraft.class_426", + "net.minecraft.class_4288", + "net.minecraft.class_6777", + "net.minecraft.class_443", + "net.minecraft.class_446", + "net.minecraft.class_445", + "net.minecraft.class_6599" + ], + "disabled": [ + "net.minecraft.class_434" + ], + "_comment": { + "_0": "Mojang mapping names of the enabled / disabled screens.", + "_1": "Sorted by fully qualified name. Translation not needed for mod screens.", + "enabled": { + "net.minecraft.class_4189": "net.minecraft.client.gui.screens.AccessibilityOptionsScreen", + "net.minecraft.class_404": "net.minecraft.client.gui.screens.ChatOptionsScreen", + "net.minecraft.class_426": "net.minecraft.client.gui.screens.LanguageSelectScreen", + "net.minecraft.class_4288": "net.minecraft.client.gui.screens.MouseSettingsScreen", + "net.minecraft.class_6777": "net.minecraft.client.gui.screens.OnlineOptionsScreen", + "net.minecraft.class_443": "net.minecraft.client.gui.screens.SoundOptionsScreen", + "net.minecraft.class_446": "net.minecraft.client.gui.screens.VideoSettingsScreen", + "net.minecraft.class_445": "net.minecraft.client.gui.screens.WinScreen", + "net.minecraft.class_6599": "net.minecraft.client.gui.screens.controls.KeyBindsScreen" + }, + "disabled": { + "net.minecraft.class_434": "net.minecraft.client.gui.screens.ReceivingLevelScreen" + } + } + } + } } diff --git a/settings.gradle b/settings.gradle index 05316cfe..9fc3100a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,6 +16,6 @@ rootProject.name = "dynamic-fps" include(":platforms:common") include(":platforms:fabric") -// include(":platforms:forge") -include(":platforms:neoforge") -// include(":platforms:quilt") +include(":platforms:forge") +// include(":platforms:neoforge") +include(":platforms:quilt")