Skip to content

Commit

Permalink
fix flash bug before bounce
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Dec 29, 2022
1 parent dcd51c2 commit 70351a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.parallel = true
loader_version = 0.14.11

# Mod Properties
mod_version = 1.0.0
mod_version = 1.0.1
maven_group = net.krlite
archives_base_name = bounced-1.19

Expand Down
15 changes: 5 additions & 10 deletions src/main/java/net/krlite/bounced/Bounced.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.krlite.bounced;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -28,27 +27,23 @@ public long queue() {
public long queueElapsed() {
return System.currentTimeMillis() - origin;
}

public double queueAsPercentage() {
return (double) queue() / (double) lasting;
}
}

public record Pusher(AtomicBoolean ready) {
public Pusher(boolean ready) {
this(new AtomicBoolean(ready));
}

public void let() {
public void push() {
ready.set(true);
}

public boolean queue() {
return ready.get();
public boolean pull() {
return ready.get() && ready.getAndSet(false);
}

public boolean access() {
return ready.getAndSet(false);
public void and(boolean and, Runnable runnable) {
if (and && pull()) runnable.run();
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/net/krlite/bounced/mixin/MinecraftAnimator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Trigger {
@Inject(method = "setScreen", at = @At("TAIL"))
private void trigger(Screen screen, CallbackInfo ci) {
if (!(screen instanceof TitleScreen)) PUSHER.let();
if (!(screen instanceof TitleScreen)) PUSHER.push();
}
}

Expand All @@ -31,7 +31,8 @@ private void trigger(Screen screen, CallbackInfo ci) {
@Mixin(TitleScreen.class)
public class MinecraftAnimator {
private Bounced.Timer timer = new Bounced.Timer(853);
private double yPos = 0;
private final double offset = MinecraftClient.getInstance().getWindow().getScaledHeight() / 3.5;
private double yPos;

/**
* Triggers the animation when the title is first rendered.
Expand All @@ -48,7 +49,7 @@ public class MinecraftAnimator {
)
private float trigger(float alpha) {
// Short-circuit manipulation
if (alpha > 0 && PUSHER.access()) timer = timer.reset();
PUSHER.and(alpha > 0, () -> timer = timer.reset());
return alpha;
}

Expand All @@ -58,12 +59,14 @@ private float trigger(float alpha) {
@Inject(
method = "render",
at = @At(
value = "FIELD", target = "Lnet/minecraft/client/gui/screen/TitleScreen;MINECRAFT_TITLE_TEXTURE:Lnet/minecraft/util/Identifier;",
value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShaderColor(FFFF)V",
shift = At.Shift.AFTER
),
slice = @Slice(
from = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/TitleScreen;MINECRAFT_TITLE_TEXTURE:Lnet/minecraft/util/Identifier;")
)
)
private void animate(MatrixStack matrixStack, int mouseX, int mouseY, float delta, CallbackInfo ci) {
double offset = MinecraftClient.getInstance().getWindow().getScaledHeight() / 3.5;
yPos = Bounced.easeOutBounce(-offset, offset, timer);
}

Expand Down

0 comments on commit 70351a1

Please sign in to comment.