Skip to content

Commit

Permalink
Minecraft 1.19.4 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Jul 28, 2024
1 parent ecd7fd0 commit 883677e
Show file tree
Hide file tree
Showing 32 changed files with 431 additions and 73 deletions.
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/dynamic_fps.java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ java {
withSourcesJar()

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

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"

javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(17)
}
}
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ maven_group = juliand665
archives_name = dynamic-fps

# File naming version
minecraft_version = 1.21.0
minecraft_version = 1.19.4
# Version for publishing
minecraft_version_min = 1.21
minecraft_version_max = 1.21
minecraft_version_min = 1.19.4
minecraft_version_max = 1.19.4

enabled_platforms=fabric,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,14 +1,14 @@
[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"

Expand All @@ -18,8 +18,8 @@ battery = "1.1.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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,7 +176,7 @@ public static boolean shouldShowToasts() {
}

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

public static void onBatteryChargeChanged(int before, int after) {
Expand All @@ -196,11 +198,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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
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;

BatteryIndicatorPlacement(DynamicPlacement placement) {
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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
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,10 +1,23 @@
package dynamic_fps.impl.service;

import java.util.Set;

public interface ModCompat {
boolean isDisabled();

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
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

Expand All @@ -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);
}
}
Loading

0 comments on commit 883677e

Please sign in to comment.