Skip to content

Commit

Permalink
Minecraft 1.20.0 backport
Browse files Browse the repository at this point in the history
Signed-off-by: Lilly Rose Berner <[email protected]>
  • Loading branch information
LostLuma committed Dec 3, 2024
1 parent c59f71e commit d7933dd
Show file tree
Hide file tree
Showing 38 changed files with 453 additions and 189 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.2
minecraft_version = 1.20.0
# Version for publishing
minecraft_version_min = 1.21.2
minecraft_version_max = 1.21.4
minecraft_version_min = 1.20
minecraft_version_max = 1.20.1

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,14 +1,14 @@
[versions]
minecraft = "1.21.3"
minecraft = "1.20"

# Platform libraries

fabric_loader = "0.15.10"
fabric_api = "0.102.2+1.21.2"
fabric_api = "0.83.0+1.20"

forge = "1.21.3-53.0.7"
forge = "1.20-46.0.14"

neoforge = "21.3.0-beta"
neoforge = "20.4.237"

quilt_loader = "0.25.0"

Expand All @@ -18,8 +18,8 @@ battery = "1.3.0"

# Modding libraries

modmenu = "11.0.0-beta.1"
cloth_config = "15.0.127"
modmenu = "7.0.0"
cloth_config = "11.0.99"

mixinextras = "0.3.5"

Expand Down
17 changes: 10 additions & 7 deletions platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import dynamic_fps.impl.feature.battery.BatteryToast;
import dynamic_fps.impl.feature.battery.BatteryTracker;
import dynamic_fps.impl.feature.state.IdleHandler;
import dynamic_fps.impl.util.BatteryUtil;
import dynamic_fps.impl.util.FallbackConfigScreen;
import dynamic_fps.impl.util.Logging;
import dynamic_fps.impl.util.*;
import dynamic_fps.impl.feature.state.OptionHolder;
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 @@ -178,7 +175,7 @@ public static GraphicsState graphicsState() {
}

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

public static void onBatteryChargeChanged(int before, int after) {
Expand All @@ -200,11 +197,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 Expand Up @@ -263,7 +266,7 @@ private static void checkForStateChanges() {
checkForStateChanges0();
} else {
// Schedule check for the beginning of the next frame
minecraft.schedule(DynamicFPSMod::checkForStateChanges0);
minecraft.tell(DynamicFPSMod::checkForStateChanges0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void applyWorkaround() {
// Agrees that the window is focused. The mod is
// A little too fast for this, so we schedule it
// For the next client tick (before next frame).
minecraft.schedule(minecraft.mouseHandler::grabMouse);
minecraft.tell(minecraft.mouseHandler::grabMouse);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

public enum IdleCondition {
NONE,
VANILLA,
ON_BATTERY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastManager;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -14,7 +14,6 @@

public class BaseToast implements Toast {
private long firstRender;
private Visibility visibility;

protected Component title;
protected Component description;
Expand All @@ -28,47 +27,31 @@ protected BaseToast(Component title, Component description, @Nullable ResourceLo
this.description = description;

this.icon = icon;

this.visibility = Visibility.SHOW;
}

@Override
public @NotNull Visibility getWantedVisibility() {
return this.visibility;
}

@Override
public void update(ToastManager toastManager, long currentTime) {
if (this.firstRender == 0) {
return;
}

if (currentTime - this.firstRender >= 5000.0 * toastManager.getNotificationDisplayTimeMultiplier()) {
this.visibility = Visibility.HIDE;
}
}

@Override
public void render(GuiGraphics graphics, Font font, long currentTime) {
public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) {
if (this.firstRender == 0) {
this.onFirstRender();
this.firstRender = currentTime;
}

// type, resource, x, y, ?, ?, width, height, width, height
graphics.blit(RenderType::guiTextured, BACKGROUND_IMAGE, 0, 0, 0.0f, 0, this.width(), this.height(), this.width(), this.height());
// resource, x, y, z, ?, ?, width, height, width, height
graphics.blit(BACKGROUND_IMAGE, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());

int x = 8;

if (this.icon != null) {
x += 22;

graphics.blit(RenderType::guiTextured, MOD_ICON, 2, 2, 0.0f, 0, 8, 8, 8, 8);
graphics.blit(RenderType::guiTextured, this.icon, 8, 8, 0.0f, 0, 16, 16, 16, 16);
graphics.blit(MOD_ICON, 2, 2, 0.0f, 0.0f, 8, 8, 8, 8);
graphics.blit(this.icon, 8, 8, 0.0f, 0.0f, 16, 16, 16, 16);
}

graphics.drawString(Minecraft.getInstance().font, this.title, x, 7, 0x5f3315, false);
graphics.drawString(Minecraft.getInstance().font, this.description, x, 18, -16777216, false);
graphics.drawString(toastComponent.getMinecraft().font, this.title, x, 7, 0x5f3315, false);
graphics.drawString(toastComponent.getMinecraft().font, this.description, x, 18, -16777216, false);

return currentTime - this.firstRender >= 5000.0 * toastComponent.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
}

public void onFirstRender() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void queueToast(Component title, ResourceLocation icon) {
queuedToast.icon = icon;
} else {
queuedToast = new BatteryToast(title, icon);
Minecraft.getInstance().getToastManager().addToast(queuedToast);
Minecraft.getInstance().getToasts().addToast(queuedToast);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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 @@ -105,15 +105,15 @@ private static void updateState() {
changed = true;

int current = charge;
minecraft.schedule(() -> DynamicFPSMod.onBatteryChargeChanged(current, newCharge));
minecraft.tell(() -> DynamicFPSMod.onBatteryChargeChanged(current, newCharge));
}

if (readInitialData && status != newStatus) {
changed = true;

State current = status;
State updated = newStatus;
minecraft.schedule(() -> DynamicFPSMod.onBatteryStatusChanged(current, updated));
minecraft.tell(() -> DynamicFPSMod.onBatteryStatusChanged(current, updated));
}

charge = newCharge;
Expand Down Expand Up @@ -141,7 +141,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
Expand Up @@ -17,6 +17,6 @@ private ErrorToast(Component description) {
*/
public static void queueToast(Component description) {
ErrorToast toast = new ErrorToast(description);
Minecraft.getInstance().getToastManager().addToast(toast);
Minecraft.getInstance().getToasts().addToast(toast);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.client.CloudStatus;
import net.minecraft.client.GraphicsStatus;
import net.minecraft.client.Options;
import net.minecraft.server.level.ParticleStatus;
import net.minecraft.client.ParticleStatus;

/*
* Helper for saving, overriding, and re-applying vanilla options.
Expand Down

This file was deleted.

Loading

0 comments on commit d7933dd

Please sign in to comment.