Skip to content

Commit

Permalink
Minecraft 1.21.0 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Sep 20, 2024
1 parent 6b574ba commit e834674
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 161 deletions.
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-alpha.24w33a
minecraft_version = 1.21.0
# Version for publishing
minecraft_version_min = 24w33a
minecraft_version_max = 24w34a
minecraft_version_min = 1.21
minecraft_version_max = 1.21

enabled_platforms=fabric,quilt
enabled_platforms=fabric,forge,neoforge,quilt
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
minecraft = "24w33a"
minecraft = "1.21"

# Platform libraries

fabric_loader = "0.15.10"
fabric_api = "0.102.2+1.21.2"
fabric_api = "0.100.1+1.21"

forge = "1.21-51.0.33"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,6 @@ public static Component IdleConditionMessage(Enum<IdleCondition> state) {
return localized("config", "idle_condition_" + state.toString().toLowerCase(Locale.ROOT));
}

private static Optional<Component[]> idleConditionTooltip(IdleCondition condition) {
return Optional.of(new Component[]{ localized("config", "idle_condition_" + condition.toString().toLowerCase(Locale.ROOT) + "_tooltip") });
}

private static Component graphicsStateMessage(Enum<GraphicsState> graphicsState) {
return localized("config", "graphics_state_" + graphicsState.toString().toLowerCase(Locale.ROOT));
}
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 @@ -2,11 +2,9 @@

import dynamic_fps.impl.util.ResourceLocations;
import net.minecraft.client.Minecraft;
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.renderer.RenderType;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -19,7 +17,6 @@ public class BatteryToast implements Toast {
private Component title;
private Component description;
private ResourceLocation icon;
private Visibility visibility;

private static BatteryToast queuedToast;

Expand All @@ -29,7 +26,6 @@ public class BatteryToast implements Toast {
private BatteryToast(Component title, ResourceLocation icon) {
this.title = title;
this.icon = icon;
this.visibility = Visibility.SHOW;
}

/**
Expand All @@ -42,28 +38,12 @@ 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);
}
}

@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) {
if (this == queuedToast) {
queuedToast = null;
Expand All @@ -75,12 +55,14 @@ public void render(GuiGraphics graphics, Font font, long currentTime) {
}

// resource, x, y, z, ?, ?, width, height, width, height
graphics.blit(RenderType::guiTextured, BACKGROUND_IMAGE, 0, 0, 0, 0.0f, 0, this.width(), this.height(), this.width(), this.height());
graphics.blit(BACKGROUND_IMAGE, 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);

graphics.blit(RenderType::guiTextured, MOD_ICON, 2, 2, 0, 0.0f, 0, 8, 8, 8, 8);
graphics.blit(RenderType::guiTextured, this.icon, 8, 8, 0, 0.0f, 0, 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);

graphics.drawString(Minecraft.getInstance().font, this.title, 30, 7, 0x5f3315, false);
graphics.drawString(Minecraft.getInstance().font, this.description, 30, 18, -16777216, false);
return currentTime - this.firstRender >= 5000.0 * toastComponent.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
}
}
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.

Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,32 @@ private void setScreen(CallbackInfo callbackInfo) {
IdleHandler.onActivity();
}

/**
* Conditionally bypasses the main menu frame rate limit.
*
* This is done in two cases:
* - The window is active, and the user wants to uncap the frame rate
* - The window is inactive, and the current FPS limit should be lower
*/
@Inject(method = "getFramerateLimit", at = @At(value = "CONSTANT", args = "intValue=60"), cancellable = true)
private void getFramerateLimit(CallbackInfoReturnable<Integer> callbackInfo) {
int limit = this.window.getFramerateLimit();

if (DynamicFPSMod.powerState() != PowerState.FOCUSED) {
// Vanilla returns 60 here
// Only overwrite if our current limit is lower
if (limit < 60) {
callbackInfo.setReturnValue(limit);
}
} else if (DynamicFPSConfig.INSTANCE.uncapMenuFrameRate()) {
if (this.options.enableVsync().get()) {
// VSync will regulate to a non-infinite value
callbackInfo.setReturnValue(Constants.NO_FRAME_RATE_LIMIT);
} else {
// Even though the option "uncaps" the frame rate the limit is 250 FPS.
// Since otherwise this will just cause coil whine with no real benefit
callbackInfo.setReturnValue(Math.min(limit, Constants.NO_FRAME_RATE_LIMIT - 10));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package dynamic_fps.impl.mixin;

import net.minecraft.client.gui.components.toasts.ToastManager;
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 dynamic_fps.impl.DynamicFPSMod;
import net.minecraft.client.gui.components.toasts.ToastComponent;

@Mixin(ToastManager.class)
public class ToastManagerMixin {
@Inject(method = "freeSlotCount", at = @At("HEAD"), cancellable = true)
private void freeSlotCount(CallbackInfoReturnable<Integer> callbackInfo) {
@Mixin(ToastComponent.class)
public class ToastComponentMixin {
@Inject(method = "freeSlots", at = @At("HEAD"), cancellable = true)
private void hasFreeSlots(CallbackInfoReturnable<Integer> callbackInfo) {
if (!DynamicFPSMod.shouldShowToasts()) {
callbackInfo.setReturnValue(0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dynamic_fps.impl.mixin;

import dynamic_fps.impl.PowerState;
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 com.mojang.blaze3d.platform.Window;

import dynamic_fps.impl.DynamicFPSMod;

@Mixin(Window.class)
public class WindowMixin {
/**
* Sets a frame rate limit while we're cancelling some or all rendering.
*/
@Inject(method = "getFramerateLimit", at = @At("RETURN"), cancellable = true)
private void onGetFramerateLimit(CallbackInfoReturnable<Integer> callbackInfo) {
PowerState state = DynamicFPSMod.powerState();

if (state != PowerState.FOCUSED) {
// Instruct Minecraft to render a minimum of 15 FPS
// Going lower here makes resuming again feel sluggish
callbackInfo.setReturnValue(Math.max(DynamicFPSMod.targetFrameRate(), 15));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dynamic_fps.impl.feature.battery.BatteryTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;

import static dynamic_fps.impl.util.Localization.localized;
Expand Down Expand Up @@ -58,7 +57,7 @@ private static void drawBatteryOverlay(GuiGraphics graphics) {
int[] position = config.placement().get(graphics);

// resource, x, y, z, ?, ?, width, height, width, height
graphics.blit(RenderType::guiTextured, icon, position[0], position[1], 0, 0.0f, 0, 16, 16, 16, 16);
graphics.blit(icon, 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"uncap_menu_frame_rate": false,
"idle": {
"timeout": 300,
"condition": "vanilla"
"condition": "on_battery"
},
"battery_tracker": {
"enabled": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
"config.dynamic_fps.idle_time_tooltip": "Minutes without input until Dynamic FPS activates the Idle state while the game is focused.",

"config.dynamic_fps.idle_condition": "Idle Condition",

"config.dynamic_fps.idle_condition_none": "None",
"config.dynamic_fps.idle_condition_vanilla": "Vanilla",
"config.dynamic_fps.idle_condition_on_battery": "While on battery",

"config.dynamic_fps.idle_condition_none_tooltip": "Always activate Idle state when inactive for too long.",
"config.dynamic_fps.idle_condition_vanilla_tooltip": "Disable Dynamic FPS idling. Uses the vanilla setting instead.",
"config.dynamic_fps.idle_condition_on_battery_tooltip": "Enable the Idle state when inactive for too long and on battery.",

"config.dynamic_fps.uncap_menu_frame_rate": "Uncap Menu FPS",
"config.dynamic_fps.uncap_menu_frame_rate_tooltip": "Remove the 60 FPS limit in the main menu.",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"minVersion": "0.8",
"client": [
"DebugScreenOverlayMixin",
"FramerateLimitTrackerMixin",
"GameRendererMixin",
"GuiMixin",
"LoadingOverlayMixin",
"MinecraftMixin",
"OptionsMixin",
"SoundEngineMixin",
"ToastManagerMixin",
"ToastComponentMixin",
"WindowMixin",
"bugfix.BlockableEventLoopMixin"
],
"mixins": [],
Expand Down
2 changes: 1 addition & 1 deletion platforms/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"depends": {
"fabricloader": ">=0.15.10",
"minecraft": ">=1.21.2-alpha.24.33.a",
"minecraft": ["1.21.0", "1.21.1"],
"mixinextras": ">=0.3.2",
"fabric-resource-loader-v0": "*",
"fabric-lifecycle-events-v1": "*"
Expand Down
2 changes: 1 addition & 1 deletion platforms/forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ file="META-INF/accesstransformer.cfg"
[[dependencies.dynamic_fps]]
modId = "minecraft"
mandatory = true
versionRange = "[1.21.0,)"
versionRange = "[1.21.0,1.21.1]"
ordering = "NONE"
side = "CLIENT"
Loading

0 comments on commit e834674

Please sign in to comment.