Skip to content

Commit

Permalink
DONE!
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jul 11, 2024
1 parent 0c2f243 commit 15d3127
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 84 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

withSourcesJar()
}
Expand Down Expand Up @@ -84,7 +84,7 @@ publisher {

versionType.set("release")
projectVersion.set(project.version.toString())
gameVersions.set(listOf("1.20.3", "1.20.4"))
gameVersions.set(listOf("1.20.5", "1.20.6"))
loaders.set(listOf("fabric", "quilt"))
curseEnvironment.set("client")

Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ archives-name = "bounced"
mod = "4.1.0"
loader = "fabric"

minecraft = "1.20.3"
yarn = "1.20.3+build.1"
fabric-loader = "0.15.9"
fabric-api = "0.91.1+1.20.3"
minecraft = "1.20.5"
yarn = "1.20.5+build.1"
fabric-loader = "0.15.11"
fabric-api = "0.97.8+1.20.5"
fabric-loom = "1.6-SNAPSHOT"
modpublisher = "2.1.0"

Expand All @@ -20,7 +20,7 @@ id-curseforge = "844458"
# display
display-name = "Bounced"
display-loader = "Fabric"
display-version = "1.20.3+"
display-version = "1.20.5+"

[libraries]
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }
Expand Down
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jdk:
- openjdk17
- openjdk21
25 changes: 16 additions & 9 deletions src/main/java/band/kessokuteatime/bounced/Bounced.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onInitializeClient() {
if (screen instanceof TitleScreen || screen instanceof AccessibilityOnboardingScreen) {
ScreenMouseEvents.beforeMouseClick(screen)
.register((currentScreen, mouseX, mouseY, button) -> {
double centerX = scaledWidth / 2.0, y = 30, width = 310, height = 44;
double centerX = scaledWidth / 2.0, y = 30 + primaryPos(), width = 310, height = 44;
if (!isIntro()
&& mouseX >= centerX - width / 2 && mouseX <= centerX + width / 2
&& mouseY >= y && mouseY <= y + height
Expand All @@ -47,15 +47,16 @@ public void onInitializeClient() {
});
}

public static double offset(boolean isIntro) {
return MinecraftClient.getInstance().getWindow().getScaledHeight() / (isIntro ? 4.1 : 7.0);
}

public static void update() {
double offset = offset(isIntro());
if (isIntro()) {
double offset = MinecraftClient.getInstance().getWindow().getScaledHeight() / 4.1;
primaryPos = (shouldAnimate.get() ? 0 : easeOutBounce(primaryAnimationTime) * offset) - offset;
secondaryPos = (shouldAnimate.get() ? 0 : easeOutBounce(secondaryAnimationTime) * offset) - offset;
}
else {
double offset = MinecraftClient.getInstance().getWindow().getScaledHeight() / 7.0;

} else {
if (shouldAnimate.get()) {
primaryPos = 0;
secondaryPos = 0;
Expand Down Expand Up @@ -93,9 +94,15 @@ public static boolean isIntro() {
}

public static void init() {
initializationTime = System.currentTimeMillis();
thresholdOffset = -1;
shouldJump.set(false);
init(false);
}

public static void init(boolean force) {
if (force || !isIntro()) {
initializationTime = System.currentTimeMillis();
thresholdOffset = -1;
shouldJump.set(false);
}
}

public static void push() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,15 @@
package band.kessokuteatime.bounced.mixin;

import band.kessokuteatime.bounced.Bounced;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* This class is responsible for triggering the title animation before the title screen is rendered.
*/
@Mixin(MinecraftClient.class)
class Trigger {
@Inject(method = "setScreen", at = @At("TAIL"))
private void trigger(Screen screen, CallbackInfo ci) {
if (!(screen instanceof TitleScreen)) Bounced.push();
}
}

/**
* This class is responsible for triggering the title animation when the game starts for the first time.
*/
@Mixin(AccessibilityOnboardingScreen.class)
class AccessibilityOnboardingTrigger {
@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init();
}

/**
* Triggers and restarts the animation.
*/
@ModifyArg(
method = "renderBackground",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V"
), index = 1
)
private float trigger(float progress) {
Bounced.resetWhen(progress > 0.9);
Bounced.update();
return progress;
}
}

/**
* This class is responsible for triggering the animation and animating the splash text.
*/
@Mixin(TitleScreen.class)
public class SplashTextAnimator {
@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init();
}

/**
* Triggers and restarts the animation.
*/
@ModifyArg(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V"
), index = 1
)
private float trigger(float progress) {
Bounced.resetWhen(progress > 0.9);
Bounced.update();
return progress;
}
}

@Mixin(SplashTextRenderer.class)
class SplashTextTranslator {
class SplashTextAnimator {
/**
* Applies the animation transformation to the splash text.
*/
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/band/kessokuteatime/bounced/mixin/Trigger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package band.kessokuteatime.bounced.mixin;


import band.kessokuteatime.bounced.Bounced;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.AccessibilityOnboardingScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* This class is responsible for triggering the title animation before the title screen is rendered.
*/
@Mixin(MinecraftClient.class)
public class Trigger {
@Inject(method = "setScreen", at = @At("TAIL"))
private void trigger(Screen screen, CallbackInfo ci) {
if (!(screen instanceof TitleScreen || screen instanceof AccessibilityOnboardingScreen)) {
Bounced.push();
}
}
}

/**
* This class is responsible for triggering the title animation when the game starts for the first time.
*/
@Mixin(AccessibilityOnboardingScreen.class)
class AccessibilityOnboardingTrigger {
@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init(true);
}

/**
* Triggers and restarts the animation.
*/
@ModifyArg(
method = "renderPanoramaBackground",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(Lnet/minecraft/client/gui/DrawContext;IIFF)V"
), index = 3
)
private float trigger(float progress) {
Bounced.resetWhen(progress > 0.9);
Bounced.update();
return progress;
}
}

/**
* This class is responsible for triggering the animation every time the title screen is shown.
*/
@Mixin(TitleScreen.class)
class TitleScreenTrigger {
@Shadow
private boolean doBackgroundFade;

@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init(true);
}

/**
* Triggers the animation when background is fading.
*/
@Redirect(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/util/math/MathHelper;clampedMap(FFFFF)F"
)
)
private float trigger(float value, float oldStart, float oldEnd, float newStart, float newEnd) {
float clamped = MathHelper.clampedMap(value, oldStart, oldEnd, newStart, newEnd);
Bounced.resetWhen(clamped > 0.9);
return clamped;
}

/**
* Triggers and restarts the animation at normal render phases.
*/
@Inject(
method = "render",
at = @At("HEAD")
)
private void trigger(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
Bounced.resetWhen(!doBackgroundFade);
Bounced.update();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/bounced.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"AccessibilityOnboardingTrigger",
"LogoDrawerAnimator",
"SplashTextAnimator",
"SplashTextTranslator",
"TitleScreenTrigger",
"Trigger"
],
"injectors": {
Expand Down

0 comments on commit 15d3127

Please sign in to comment.