Skip to content

Commit

Permalink
Minecraft 1.19.0 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Apr 21, 2024
1 parent 6996839 commit 3647817
Show file tree
Hide file tree
Showing 32 changed files with 409 additions and 59 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ subprojects {
withSourcesJar()

toolchain {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(17)
}
}

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

javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(17)
}
}
}
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ mod_version = 3.4.3
maven_group = juliand665
archives_base_name = dynamic-fps

enabled_platforms=fabric
# enabled_platforms=fabric,forge,neoforge,quilt
enabled_platforms=fabric,forge,quilt
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[versions]
minecraft = "1.20.5-rc2"
minecraft = "1.19"

# Platform libraries

fabric_loader = "0.15.10"
fabric_api = "0.97.4+1.20.5"
fabric_api = "0.55.3+1.19"

forge = "1.20.4-49.0.30"
forge = "1.19-41.1.0"

neoforge = "20.4.160-beta"

quilt_loader = "0.25.0"
quilt_standard_libraries = "8.0.0-alpha.12+1.20.4"
quilt_standard_libraries = "2.0.0-beta.16+1.19"

# Third-party libraries

modmenu = "10.0.0-alpha.3"
cloth_config = "14.0.125"
modmenu = "4.0.0"
cloth_config = "7.0.72"

mixinextras = "0.3.5"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import dynamic_fps.impl.config.DynamicFPSConfig;
import dynamic_fps.impl.service.ModCompat;
import dynamic_fps.impl.util.Logging;
import dynamic_fps.impl.util.ModCompatHelper;
import dynamic_fps.impl.util.OptionsHolder;
import dynamic_fps.impl.util.duck.DuckScreen;
import dynamic_fps.impl.util.duck.DuckLoadingOverlay;
import dynamic_fps.impl.util.duck.DuckSoundEngine;
import dynamic_fps.impl.util.event.InputObserver;
Expand Down Expand Up @@ -51,6 +53,8 @@ public class DynamicFPSMod {
// Internal "API" for Dynamic FPS itself

public static void init() {
ModCompatHelper.init();

Platform platform = Platform.getInstance();
String version = platform.getModVersion(Constants.MOD_ID).orElseThrow();

Expand Down Expand Up @@ -159,11 +163,15 @@ public static boolean shouldShowToasts() {
}

public static boolean shouldShowLevels() {
return isDisabled() || !isLevelCoveredByOverlay();
return isDisabled() || !(isLevelCoveredByScreen() || isLevelCoveredByOverlay());
}

// Internal logic

private static boolean isLevelCoveredByScreen() {
return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground();
}

private static boolean isIdle() {
long idleTime = modConfig.idleTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource;

Expand Down Expand Up @@ -43,7 +42,7 @@ public static Screen genConfigScreen(Screen parent) {
);

general.addEntry(
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
entryBuilder.startTextDescription(Component.literal(" ")).build()
);

general.addEntry(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package dynamic_fps.impl.mixin;

import java.util.Deque;

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.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.Redirect;

import dynamic_fps.impl.DynamicFPSMod;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;

@Mixin(ToastComponent.class)
public class ToastComponentMixin {
@Inject(method = "freeSlots", at = @At("HEAD"), cancellable = true)
private void hasFreeSlots(CallbackInfoReturnable<Integer> callbackInfo) {
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Ljava/util/Deque;isEmpty()Z"))
private boolean onQueueIsEmpty(Deque<Toast> queued) {
if (!DynamicFPSMod.shouldShowToasts()) {
callbackInfo.setReturnValue(0);
return true;
} else {
return queued.isEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ public interface ModCompat {

boolean disableOverlayOptimization();

Set<String> getOptedInScreens();
Set<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,37 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.Font.DisplayMode;
import net.minecraft.network.chat.Component;

import static dynamic_fps.impl.util.Localization.localized;

import org.joml.Matrix4f;
import com.mojang.blaze3d.vertex.PoseStack;

import dynamic_fps.impl.DynamicFPSMod;

public final class HudInfoRenderer {
private static final Minecraft minecraft = Minecraft.getInstance();

public static void renderInfo(GuiGraphics guiGraphics) {
public static void renderInfo(PoseStack poseStack) {
if (DynamicFPSMod.disabledByUser()) {
drawCenteredText(guiGraphics, localized("gui", "hud.disabled"), 32);
drawCenteredText(poseStack, localized("gui", "hud.disabled"), 32);
} else if (DynamicFPSMod.isForcingLowFPS()) {
drawCenteredText(guiGraphics, localized("gui", "hud.reducing"), 32);
drawCenteredText(poseStack, localized("gui", "hud.reducing"), 32);
}
}

private static void drawCenteredText(GuiGraphics guiGraphics, Component component, float y) {
private static void drawCenteredText(PoseStack poseStack, Component component, float y) {
Font fontRenderer = minecraft.gui.getFont();

int stringWidth = fontRenderer.width(component);
int windowWidth = minecraft.getWindow().getGuiScaledWidth();

fontRenderer.drawInBatch(
fontRenderer.drawShadow(
poseStack,
component,
(windowWidth - stringWidth) / 2f,
y,
0xFFFFFFFF,
true,
new Matrix4f(),
guiGraphics.bufferSource(),
DisplayMode.NORMAL,
0,
255
0xFFFFFFFF
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dynamic_fps.impl.util;

import dynamic_fps.impl.service.ModCompat;
import dynamic_fps.impl.service.Platform;

import java.util.Arrays;
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 <a href="https://github.com/juliand665/Dynamic-FPS/issues/129">issue report</a> for more info.
*/
private static void fixFastloadSoftLock() {
Optional<String> optional = Platform.getInstance().getModVersion("fastload");

if (optional.isEmpty()) {
return;
}

String[] parts = optional.get().split("\\.");
int[] version = Arrays.stream(parts).mapToInt(Integer::parseInt).toArray();

if (version.length < 3) {
Logging.getLogger().warn("Unable to parse Fastload version: {}!", optional.get());
return;
}

// If a version below 3.4.0 is present opt their custom world loading screen out of our optimization
if (!(version[0] > 3 || version[0] == 3 && (version[1] > 4 || version[1] == 4 && version[2] > 0))) {
ModCompat.getInstance().getOptedOutScreens().add(
"io.github.bumblesoftware.fastload.client.BuildingTerrainScreen"
);

}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dynamic_fps.impl.util;

import dynamic_fps.impl.GraphicsState;
import net.minecraft.client.AmbientOcclusionStatus;
import net.minecraft.client.CloudStatus;
import net.minecraft.client.GraphicsStatus;
import net.minecraft.client.Options;
Expand All @@ -14,7 +15,7 @@
public class OptionsHolder {
private static CloudStatus cloudStatus;
private static GraphicsStatus graphicsStatus;
private static boolean ambientOcclusion;
private static AmbientOcclusionStatus ambientOcclusion;
private static ParticleStatus particlesStatus;
private static boolean entityShadows;
private static double entityDistance;
Expand Down Expand Up @@ -52,7 +53,7 @@ public static void applyOptions(Options options, GraphicsState state) {

if (state == GraphicsState.MINIMAL) {
options.graphicsMode().set(GraphicsStatus.FAST);
options.ambientOcclusion().set(false);
options.ambientOcclusion().set(AmbientOcclusionStatus.OFF);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dynamic_fps.impl.util.duck;

public interface DuckScreen {
public default boolean dynamic_fps$rendersBackground() {
throw new RuntimeException("No implementation for dynamic_fps$rendersBackground was found.");
}

public default void dynamic_fps$setRendersBackground() {
throw new RuntimeException("No implementation for dynamic_fps$rendersBackground was found.");
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"required": true,
"package": "dynamic_fps.impl.mixin",
"compatibilityLevel": "JAVA_21",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"client": [
"DebugScreenOverlayMixin",
"GameRendererMixin",
"GuiMixin",
"LoadingOverlayMixin",
"MinecraftMixin",
"ScreenMixin",
"SoundEngineMixin",
"StatsScreenMixin",
"ToastComponentMixin",
"WindowMixin",
"bugfix.BlockableEventLoopMixin"
Expand Down
Loading

0 comments on commit 3647817

Please sign in to comment.