From 9f9a176bb787ae88ea73004b9a4c7d093d13086d Mon Sep 17 00:00:00 2001 From: dima_dencep Date: Wed, 1 Jan 2025 23:45:09 +0700 Subject: [PATCH] Interpolation when reaching the end --- .../dima_dencep/mods/rrls/RrlsConfig.java | 8 +++- .../mods/rrls/mixins/LoadingOverlayMixin.java | 37 +++++++++++++++++++ ...ConfigurationSectionScreenWithOverlay.java | 2 +- .../resources/assets/rrls/lang/en_us.json | 2 + .../resources/assets/rrls/lang/ru_ru.json | 2 + 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/redlance/dima_dencep/mods/rrls/RrlsConfig.java b/common/src/main/java/org/redlance/dima_dencep/mods/rrls/RrlsConfig.java index 9f314e9..ecc6e71 100644 --- a/common/src/main/java/org/redlance/dima_dencep/mods/rrls/RrlsConfig.java +++ b/common/src/main/java/org/redlance/dima_dencep/mods/rrls/RrlsConfig.java @@ -35,6 +35,7 @@ public class RrlsConfig { // Interpolation public final ModConfigSpec.BooleanValue interpolateProgress; + public final ModConfigSpec.BooleanValue interpolateAtEnd; public final ModConfigSpec.EnumValue ease; public final ModConfigSpec.ConfigValue easingArg; @@ -64,7 +65,8 @@ protected RrlsConfig(ModConfigSpec.Builder builder) { builder.push("interpolation"); this.interpolateProgress = builder.define("interpolateProgress", false); - this.ease = builder.defineEnum("ease", Ease.OUTCIRC); + this.interpolateAtEnd = builder.define("interpolateAtEnd", true); + this.ease = builder.defineEnum("ease", Ease.INOUTQUINT); this.easingArg = builder.define("easingArg", Double.NaN, RrlsConfig::isFloatLike); builder.pop(); @@ -112,6 +114,10 @@ public static boolean interpolateProgress() { return CONFIG_SPEC_PAIR.getKey().interpolateProgress.get(); } + public static boolean interpolateAtEnd() { + return CONFIG_SPEC_PAIR.getKey().interpolateAtEnd.get(); + } + public static Ease easing() { return CONFIG_SPEC_PAIR.getKey().ease.get(); } diff --git a/common/src/main/java/org/redlance/dima_dencep/mods/rrls/mixins/LoadingOverlayMixin.java b/common/src/main/java/org/redlance/dima_dencep/mods/rrls/mixins/LoadingOverlayMixin.java index 222f586..d7ee7b6 100644 --- a/common/src/main/java/org/redlance/dima_dencep/mods/rrls/mixins/LoadingOverlayMixin.java +++ b/common/src/main/java/org/redlance/dima_dencep/mods/rrls/mixins/LoadingOverlayMixin.java @@ -16,6 +16,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.util.ARGB; import net.minecraft.util.Mth; +import org.objectweb.asm.Opcodes; import org.redlance.dima_dencep.mods.rrls.RrlsConfig; import org.redlance.dima_dencep.mods.rrls.config.Type; import org.redlance.dima_dencep.mods.rrls.utils.DummyGuiGraphics; @@ -56,8 +57,11 @@ public abstract class LoadingOverlayMixin extends Overlay { private long fadeInStart; @Shadow public abstract void drawProgressBar(GuiGraphics guiGraphics, int minX, int minY, int maxX, int maxY, float partialTick); + @Unique private FocusableTextWidget rrls$textWidget; + @Unique + private boolean rrls$isFinished; @Inject( method = "", @@ -225,6 +229,39 @@ public abstract class LoadingOverlayMixin extends Overlay { return original.call(alpha, red, green, blue); } + @WrapOperation( + method = "render", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/client/gui/screens/LoadingOverlay;fadeOutStart:J", + ordinal = 2 + ) + ) + public long rrls$(LoadingOverlay instance, Operation original) { + if (this.fadeOutStart == -1L && this.currentProgress >= 0.999F) { + this.fadeOutStart = Util.getMillis(); + } + if (RrlsConfig.interpolateAtEnd()) { + return this.rrls$isFinished ? 1L : -1L; + } + return original.call(instance); + } + + @WrapOperation( + method = "render", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/client/gui/screens/LoadingOverlay;fadeOutStart:J", + opcode = Opcodes.PUTFIELD + ) + ) + public void rrls$(LoadingOverlay instance, long value, Operation original) { + this.rrls$isFinished = true; + if (!RrlsConfig.interpolateAtEnd()) { + original.call(instance, value); + } + } + @ModifyConstant( method = "render", constant = { diff --git a/common/src/main/java/org/redlance/dima_dencep/mods/rrls/screens/ConfigurationSectionScreenWithOverlay.java b/common/src/main/java/org/redlance/dima_dencep/mods/rrls/screens/ConfigurationSectionScreenWithOverlay.java index b197804..a91ecaf 100644 --- a/common/src/main/java/org/redlance/dima_dencep/mods/rrls/screens/ConfigurationSectionScreenWithOverlay.java +++ b/common/src/main/java/org/redlance/dima_dencep/mods/rrls/screens/ConfigurationSectionScreenWithOverlay.java @@ -77,6 +77,6 @@ public float getActualProgress() { @Override public boolean isDone() { - return this.minecraft != null && this.minecraft.overlay == this.overlay && this.currentProgress > 5.0F; + return this.minecraft != null && this.minecraft.overlay == this.overlay && this.currentProgress > 1.5F; } } diff --git a/common/src/main/resources/assets/rrls/lang/en_us.json b/common/src/main/resources/assets/rrls/lang/en_us.json index 1a2a600..2ca2b46 100644 --- a/common/src/main/resources/assets/rrls/lang/en_us.json +++ b/common/src/main/resources/assets/rrls/lang/en_us.json @@ -15,6 +15,8 @@ "rrls.configuration.reloadText": "The text that will be displayed if TEXT is selected above", "rrls.configuration.interpolateProgress": "Interpolate progress", "rrls.configuration.interpolateProgress.tooltip": "In vanilla minecraft interpolation starts at ~75%, turn it on if you want to do progress based interpolation.\nThis can lead to early fading, but is necessary for some easings.", + "rrls.configuration.interpolateAtEnd": "Interpolate at the end", + "rrls.configuration.interpolateAtEnd.tooltip": "Start interpolation only when the progress bar is completely filled.", "rrls.configuration.ease": "Easing", "rrls.configuration.ease.tooltip": "See https://easings.net/", "rrls.configuration.easingArg": "Easing argument", diff --git a/common/src/main/resources/assets/rrls/lang/ru_ru.json b/common/src/main/resources/assets/rrls/lang/ru_ru.json index b1784b4..6882898 100644 --- a/common/src/main/resources/assets/rrls/lang/ru_ru.json +++ b/common/src/main/resources/assets/rrls/lang/ru_ru.json @@ -15,6 +15,8 @@ "rrls.configuration.reloadText": "Текст, который будет отображаться, если выше выбран пункт TEXT", "rrls.configuration.interpolateProgress": "Интерполировать прогресс", "rrls.configuration.interpolateProgress.tooltip": "В ванильном minecraft интерполяция начинается с ~75%, включите ее, если хотите делать интерполяцию на основе прогресса.\nЭто может привести к раннему затуханию, но необходимо для некоторых изингов.", + "rrls.configuration.interpolateAtEnd": "Интерполировать в конце", + "rrls.configuration.interpolateAtEnd.tooltip": "Начинать интерполяцию только тогда, когда индикатор выполнения полностью заполнится.", "rrls.configuration.ease": "Изинг", "rrls.configuration.ease.tooltip": "См. https://easings.net/", "rrls.configuration.easingArg": "Аргумент изинга",