Skip to content

Commit

Permalink
Interpolation when reaching the end
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Jan 1, 2025
1 parent ec17dee commit 9f9a176
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class RrlsConfig {

// Interpolation
public final ModConfigSpec.BooleanValue interpolateProgress;
public final ModConfigSpec.BooleanValue interpolateAtEnd;
public final ModConfigSpec.EnumValue<Ease> ease;
public final ModConfigSpec.ConfigValue<Double> easingArg;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "<init>",
Expand Down Expand Up @@ -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<Long> 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<Void> original) {
this.rrls$isFinished = true;
if (!RrlsConfig.interpolateAtEnd()) {
original.call(instance, value);
}
}

@ModifyConstant(
method = "render",
constant = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/rrls/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/rrls/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Аргумент изинга",
Expand Down

0 comments on commit 9f9a176

Please sign in to comment.